int num; Px[] pxs; float[] cValues = new float[3]; float[] compValues = new float[3]; float[] blendValues = new float[3]; float[] targValues = new float[3]; float[] targCompValues = new float[3]; float change = 30*10; float changeCnt = 0; float changeInc = 1; float reset = -30*20; //time to hold on a shift float angCnt = 0; //current location on the wheel float angInc = 25; //step around the color wheel int flip = 1; //transition types int fold = 1; //transition types float ax, ay, bx, by; boolean pause = false; int timeCheck = 0; float outFactor = 0.1; String inside,outside; boolean hold = false; boolean pos = true; int currState = 0; void setup() { size(640, 480); noStroke(); rectMode(CENTER); ellipseMode(CENTER); colorMode(RGB); frameRate(30); //set up objects and colors num = 10; pxs = new Px[num+1]; setColors(); foldTarget(fold); } void draw() { background(51); pushMatrix(); translate(width/2,(width*.75)*.5); //place the colorShift for(int i=num; i>0; i--) { if ( (changeCnt > 0) ) { pos = true; pxs[i].update(); } pxs[i].draw(); } popMatrix(); //trigger update changeCnt += 1; //check progress if ( (hold == true) && (pos == true) ) { hold = false; currState = 1; changeCnt = change; } if ( (changeCnt >= change) ){ if ( (hold == false) && (currState == 2) ){ hold = true; pos = false; changeCnt = reset; } else { println ("timeCheck " + timeCheck/30 + "s"); if (flip == 1){ angCnt += angInc; float rand = random(1); if (rand < outFactor){ //maybe we go to white or black rand = random(1); out(rand); //FADE TO WHITE FUNCTION println("FADE"); } else{ newTarget(); println("TRANSITION"); } } else { angCnt += angInc; foldTarget(fold); println("COLOR"); fold *= -1; } flip *= -1; println(currState); println(" coming up: " + "RGB(" + targCompValues[0] + "," + targCompValues[1] + "," + targCompValues[2] + ") " + "RGB(" + targValues[0] + "," + targValues[1] + "," + targValues[2] + ")"); println(""); }; }; timeCheck +=1; }; //PICK NEW SET COMPLIMENTARY COLORS void newTarget(){ changeCnt = 0; currState = 1; targValues = pickColor(angCnt); targCompValues = pickComp(targValues); blendColors(); } //FOLD TO ANALOGUS COLORS void foldTarget(int f){ //advance newTarget(); changeCnt = 0; currState = 2; if (f == 1){ targValues = pickComp(targValues); } targCompValues = pickAnal(targValues); blendColors(); } //FADE TO WHITE OR BLACK void out(float r){ //println("OUT"); //advance newTarget(); changeCnt = 0; currState = 0; targValues = voidIt(r); targCompValues = voidIt(r); changeInc = .5; blendColors(); } //ESTABLISH PIXELS void setColors(){ cValues = voidIt(.9); compValues=voidIt(.9); for (int i=num; i>0; i--) { float fi = i; float fNum = num; //blend for (int j=0; j<3; j++){ float inc = (compValues[j]-cValues[j])/num; blendValues[j] = cValues[j] + (inc * i); } pxs[i] = new Px(0,0,((fi/fNum))*width,(fi/fNum)*(width*.75),blendValues,i); } } //CORE COLOR PICKING FUNCTIONS float[] pickColor(float ang){ //default float[] r = new float[3]; float[] convert = new float[3]; //random value for (int i=0; i<3; i++){ if (i == 0 ){ r[i] = ang;//random(360); } else { r[i] = 100;//BRIGHTNESS AND SAT } } convert = hsv2rgb(r[0],r[1],r[2]); return convert; } float[] pickComp(float[] c){ float ang,dx,dy,cdx,cdy; float h,s,b; float[] convert = new float[3]; convert = rgb2hsv(c[0],c[1],c[2]); ang = radians(convert[0]); dx = cos(ang)*convert[1]; dy = sin(ang)*convert[1]; // println (dx + " , " + dy); cdx = -1*dx; cdy = -1*dy; //circle Track ax = dx; ay = dy; bx = cdx; by = cdy; ang = degrees(atan2(cdy, cdx)+PI); //println ("ang = " + ang); h=ang+180; s = convert[1]; b = convert[2]; convert = hsv2rgb(h,s,b); return convert; } //pick an analogous color float[] pickAnal(float[] c){ float ang,dx,dy; float h,s,b; float[] convert = new float[3]; convert = rgb2hsv(c[0],c[1],c[2]); //current hsv ang = radians(convert[0]); dx = cos(ang)*convert[1]; dy = sin(ang)*convert[1]; //anal float newAng = degrees(ang)+random(20,30); //circle Track ax = dx; ay = dy; bx = cos(radians(newAng))*convert[1]; by = sin(radians(newAng))*convert[1]; h=newAng; s = convert[1]; b = convert[2]; convert = hsv2rgb(h,s,b); return convert; } //FADE TO WHITE OR BLACK float[] voidIt(float r){ float[] convert = { 255,255,255 }; if (r > .5){ convert[0] = 0; convert[1] = 0; convert[2] = 0; } changeInc = 1; return convert; } void blendColors(){ for (int i=num; i>0; i--) { float fi = i; float fNum = num; //blend float powerOf = fi/fNum; color from = color(targCompValues[0],targCompValues[1],targCompValues[2]); color to = color(targValues[0],targValues[1],targValues[2]); color inter = lerpColor(from,to,powerOf); //differnce between currColors and target colors pxs[i]._incR = (red(inter)-pxs[i]._r)/(change); pxs[i]._incG = (green(inter)-pxs[i]._g)/(change); pxs[i]._incB = (blue(inter)-pxs[i]._b)/(change); } }