// Banded Clock by Golan Levin // Design By Numbers version, 1999 // Processing version, February 2007 //================================================ int prevX = 0; int prevY = 0; int clickX = 0; int clickY = 0; final int NCOLORS = 256; color colorArray[]; float S, M, H; int Scolors[]; int Mcolors[]; int Hcolors[]; int ys0, ys1; int ym0, ym1; int yh0, yh1; float Soffset = 0; float Hoffset = 0; float Moffset = 0; float Svel = 0; float Hvel = 0; float Mvel = 0; float damp = 0.94f; int mil, sec, minut, hou; int milError = 0; int canvasWidth; int canvasHeight; //================================================ void setup(){ size(200,200); canvasWidth = width; canvasHeight = height; Scolors = new int[canvasWidth]; Mcolors = new int[canvasWidth]; Hcolors = new int[canvasWidth]; colorArray = new color[NCOLORS]; for (int i=0; i sec){ milError = millis()%1000; } } //------------------ float GMOD (float A, float B){ return (float)(A - (floor(A/B)*B)); } //------------------ int wave(float a){ // inexpensive ramp function, // but not as nice as true sine wave (below) int val = 0; float cscale = 2.0f*255.0f; if (a < 0.5){ val = (int) round (a *cscale); } else { val = (int) round ((1.0f-a)*cscale); } return val; } //------------------ int sinWave (float a){ // expensive trigonometric function, but nicer looking float sina = (1.0+sin(TWO_PI*a))*255.0/2.0; int val = (int)round(sina); return val; } //-------------------------------------------------------------------------- // interaction methods void mousePressed (){ prevX = mouseX; prevY = mouseY; clickX = mouseX; clickY = mouseY; } void mouseDragged() { // allow bands to be shifted around, for "fun" float accel = (prevX - mouseX)*0.004f; if ((clickY >= ys0) && (clickY < ys1)){ Svel += accel; } else if ((clickY >= ym0) && (clickY < ym1)){ Mvel += accel; } else if ((clickY >= yh0) && (clickY < yh1)){ Hvel += accel; } prevX = mouseX; prevY = mouseY; }