Advertisement
z-nexx

Sort HSL in JS

Sep 8th, 2013
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. c=[];
  2. r=[[]];
  3. l=0;
  4. elems=5;
  5. for(x=0;x<elems;x++){
  6.   c.push([Math.floor(Math.random()*360),Math.floor(Math.random()*100),Math.floor(Math.random()*100)]);
  7. }
  8. c=c.sort(function(a,b){
  9.   if(a[0] == b[0])return 0;
  10.   return(a[0]>b[0])?1:-1;
  11. });
  12. for(x=0;x<elems-1;x++){
  13.   r[l].push(c[x]);
  14.   if(c[x+1][0]-c[x][0]>=30){
  15.     l++;
  16.     r.push([]);
  17.   }
  18. }
  19. r[l].push(c[x]);
  20. if (360-r.slice(-1)[0].slice(-1)[0][0]+r[0][0][0]<30){
  21.   for(x=r.slice(-1)[0].length-1;x>=0;x--){
  22.     r[0].splice(0,0,r.slice(-1)[0][x]);
  23.   }
  24.   r.pop();
  25. }
  26. console.log(r);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement