 					newCentroids[cluster] += values[i]
 			for j in [0..num-1]
 				newCentroids[j] *= 1/clusterSizes[j]
-					
+
 			# check convergence
 			repeat = false
 			for j in [0..num-1]
 				if newCentroids[j] != centroids[i]
 					repeat = true
 					break
-			
+
 			centroids = newCentroids
 			nb_iters++
-			
+
 			if nb_iters > 200
 				repeat = false
-				
+
 		# finished k-means clustering
 		# the next part is borrowed from gabrielflor.it
 		kClusters = {}

		[l,a,b] = l
	[x,y,z] = Color.lab2xyz(l,a,b)
	Color.xyz2rgb(x,y,z)
	
	
Color.hcl2lab = (c,s,l) ->
	###
	Convert from a qualitative parameter c and a quantitative parameter l to a 24-bit pixel. These formulas were invented by David Dalrymple to obtain maximum contrast without going out of gamut if the parameters are in the range 0-1.
	
	A saturation multiplier was added by Gregor Aisch
	###
	if type(c) == "array" and c.length == 3
		[c,s,l] = c
		
	c /= 360.0
	TAU = 6.283185307179586476925287
	L = l*0.61+0.09 # L of L*a*b*

class Color
	###
	data type for colors

	eg.
	new Color() // white
	new Color(120,.8,.5) // defaults to hsl color
	new Color([120,.8,.5]) // this also works
	new Color(255,100,50,'rgb') //  color using RGB
	new Color('#ff0000') // or hex value

	###
	constructor: (x,y,z,m) ->
		me = @

		if not x? and not y? and not z? and not m?
			x = [255,0,255]

		if type(x) == "array" and x.length == 3
			m ?= y
			[x,y,z] = x

		if type(x) == "string"
			m = 'hex'
		else
			m ?= 'rgb'

		if m == 'rgb'
