/* "Gill Wave" Rob Weinberg 3/14/2008 spindrift.org */ int numSpinBoxes = 30; SpinBox mySpin[] = new SpinBox[numSpinBoxes]; void setup (){ size(480,290); frameRate(125); background(0); //create SpinBox instances but do not draw them yet for (int i=0; i < mySpin.length; i++){ //try variations on the spinFactor //determines rotation displacement of each fan with respect to its neighbors int spinFactor = 5*i; //(x location, y location, width, height, displacement) mySpin[i] = new SpinBox ( 120+8*i, 140, 2, 170, spinFactor ); } } void draw(){ //If noStroke is placed in "setup" it doesn't always work noStroke(); //The second number in "fill" determines amount of ghosting fill (0,6); rect(0,0,480,270); //Draw all of the instances for (int i=0; i < mySpin.length; i++){ mySpin[i].spinMe(); } } class SpinBox { int x; int y; int xwid; int ywid; int spinAngle; //constructor - does not draw anything yet SpinBox (int x, int y, int xwid, int ywid, int spinAngle) { //x and y will only be used in "translate" this.x = x; this.y = y; this.xwid = xwid; this.ywid = ywid; //initial angle of rotation - will increment this later this.spinAngle = spinAngle; } //translate, rotate, and draw the instance void spinMe (){ fill(255); //Increase the angle of rotation this.spinAngle++; //keep spinAngle from growing forever //PI, when spinAngle=300, is the same as 3PI, when spinAngle = 900 if (this.spinAngle == 900){ this.spinAngle = 300; } //bring back standard matrix pushMatrix(); //draw this instance always to the same place translate(this.x, this.y); //draw this instance with incremented angle of rotation rotate(PI/(300)*this.spinAngle); //draw the instance with some center of rotation rect (70-this.xwid/2, 0-this.ywid/2, this.xwid, this.ywid); //return matrix as you found it popMatrix(); } }