lib/toxi/color/ColorList.js
function(proxy, isReversed){
		if(arguments.length === 1){
			isReversed = arguments[0];
			proxy = new HSVDistanceProxy();
		}

		if(this.colors.length === 0){
			return this;
		}

		// Remove the darkest color from the stack,
		// put it in the sorted list as starting element.
		var root = this.getDarkest(),
			stack = this.colors.slice(0),
			sorted = [];

		stack.splice(stack.indexOf(root),1);
		sorted.push(root);

		// Now find the color in the stack closest to that color.
		// Take this color from the stack and add it to the sorted list.
		// Now find the color closest to that color, etc.
		var sortedCount = 0;
		while(stack.length > 1){
			var closest = stack[0],
				lastSorted = sorted[sortedCount],
				distance = proxy.distanceBetween(closest, lastSorted);

			for(var i = stack.length - 1; i >= 0; i--){
				var c = stack[i],
					d = proxy.distanceBetween(c, lastSorted);
				if(d < distance){
					closest = c;
					distance = d;
				}
			}
			stack.splice(stack.indexOf(closest),1);
			sorted.push(closest);
			sortedCount++;
		}
		sorted.push(stack[0]);
		if(isReversed){
			sorted.reverse();
		}
		this.colors = sorted;
		return this;
	}
function(proxy, isReversed){
		if(arguments.length === 1){
			isReversed = arguments[0];
			proxy = new HSVDistanceProxy();
		}

		if(this.colors.length === 0){
			return this;
		}

		// Remove the darkest color from the stack,
		// put it in the sorted list as starting element.
		var root = this.getDarkest(),
			stack = this.colors.slice(0),
			sorted = [];

		stack.splice(stack.indexOf(root),1);
		sorted.push(root);

		// Now find the color in the stack closest to that color.
		// Take this color from the stack and add it to the sorted list.
		// Now find the color closest to that color, etc.
		var sortedCount = 0;
		while(stack.length > 1){
			var closest = stack[0],
				lastSorted = sorted[sortedCount],
				distance = proxy.distanceBetween(closest, lastSorted);

			for(var i = stack.length - 1; i >= 0; i--){
				var c = stack[i],
					d = proxy.distanceBetween(c, lastSorted);
				if(d < distance){
					closest = c;
					distance = d;
				}
			}
			stack.splice(stack.indexOf(closest),1);
			sorted.push(closest);
			sortedCount++;
		}
		sorted.push(stack[0]);
		if(isReversed){
			sorted.reverse();
		}
		this.colors = sorted;
		return this;
	}
function ( proxy , isReversed ) { if ( arguments . length === 1 ) { isReversed = arguments [ 0 ] ; proxy = new HSVDistanceProxy ( ) ; } if ( this . colors . length === 0 ) { return this ; } // Remove the darkest color from the stack, // put it in the sorted list as starting element. var root = this . getDarkest ( ) , stack = this . colors . slice ( 0 ) , sorted = [ ] ; stack . splice ( stack . indexOf ( root ) , 1 ) ; sorted . push ( root ) ; // Now find the color in the stack closest to that color. // Take this color from the stack and add it to the sorted list. // Now find the color closest to that color, etc. var sortedCount = 0 ; while ( stack . length > 1 ) { var closest = stack [ 0 ] , lastSorted = sorted [ sortedCount ] , distance = proxy . distanceBetween ( closest , lastSorted ) ; for ( var i = stack . length - 1 ; i >= 0 ; i -- ) { var c = stack [ i ] , d = proxy . distanceBetween ( c , lastSorted ) ; if ( d < distance ) { closest = c ; distance = d ; } } stack . splice ( stack . indexOf ( closest ) , 1 ) ; sorted . push ( closest ) ; sortedCount ++ ; } sorted . push ( stack [ 0 ] ) ; if ( isReversed ) { sorted . reverse ( ) ; } this . colors = sorted ; return this ; }
Sorts the list by relative distance to each predecessor, starting with
the darkest color in the list.
@param {toxi.color.*{DistanceProxy}} proxy
@param isReversed
true, if list is to be sorted in reverse.
@return itself
Sorts the list by relative distance to each predecessor starting with the darkest color in the list .