void setup() { size(240,300); noSmooth(); } int gridcount=100; int grid=int(pow(gridcount,2)); int size1= 2; float temp1; float temp2; float hew; float lum; float sat; float linePosition=150; int select=1; int rectsize=20; int rect1x=50; int rect2x=120; int rect3x=190; int recty=262; int liney=230; int[] xpos = new int[grid]; int[] ypos = new int[grid]; void draw () { background(220); stroke(60); line(19,liney,219,liney); noStroke(); rectMode(RADIUS); if ( abs(mouseY-recty) < rectsize && mousePressed == true ) { if ( abs(mouseX-rect1x) < rectsize ) { select = 1; } else if ( abs(mouseX-rect2x) < rectsize ) { select = 2; } else if ( abs(mouseX-rect3x) < rectsize ) { select = 3; } } if ( select == 1 ) {fill(30);} else {fill(150);} rect(rect1x,recty,rectsize,rectsize); if ( select == 2 ) {fill(30);} else {fill(150);} rect(rect2x,recty,rectsize,rectsize); if ( select == 3 ) {fill(30);} else {fill(150);} rect(rect3x,recty,rectsize,rectsize); if ( abs(mouseX-120) < 100 && abs(mouseY-230) < 10 && mousePressed == true ) { linePosition = mouseX; } fill(60); rectMode(RADIUS); rect(linePosition,230,5,5); float mousemove1 = (linePosition-20)/(gridcount * size1); translate(20,20); for(int i=0; i < grid ; i++) { xpos[i] = i/gridcount; ypos[i] = i%gridcount; float xaxis= float(i/gridcount) / gridcount; float yaxis= float(i%gridcount) / gridcount; if ( select == 1 ) { hew=mousemove1; sat=xaxis; lum=1-yaxis; } else if ( select == 2 ) { hew=xaxis; sat=mousemove1; lum=1-yaxis; } else if ( select == 3 ) { hew=yaxis; sat=xaxis; lum=mousemove1; } if (lum < .5 ) { temp2=lum*(1+sat); } else { temp2=(lum+sat)-(lum*sat); } temp1=2*lum-temp2; float Rtemp3 = hueToRGB(hew+1.0/3.0, temp1, temp2); float Gtemp3 = hueToRGB(hew+0.0/3.0, temp1, temp2); float Btemp3 = hueToRGB(hew-1.0/3.0, temp1, temp2); fill( Rtemp3*256, Gtemp3*256, Btemp3*256); rectMode(RADIUS); rect(xpos[i]*(size1+0),ypos[i]*(size1+0),size1/2,size1/2); } } float hueToRGB (float temp3, float temp1, float temp2) { float thiscolor; if (temp3 < 0) { temp3 = temp3 + 1.0; } else if (temp3 > 1) { temp3 = temp3 - 1.0; } if ( 6.0 * temp3 < 1 ) { thiscolor = temp1 + ( temp2 - temp1 ) * 6.0 * temp3; } else if (2.0*temp3 < 1) { thiscolor=temp2; } else if (3.0*temp3 < 2) { thiscolor = temp1 + ( temp2-temp1 ) * ( (2.0/3.0) - temp3 ) * 6.0; } else { thiscolor = temp1; } return thiscolor; }