//Peter Mackey Oct 2006 //using a class array to create a screenful of independent lines //recenter on mouseclick, refresh on keypress int numOfObjs = 100; cLine[] line_array = new cLine[numOfObjs]; float prevX, prevY; int clickX, clickY; void setup() { size(700,700); background(50); framerate(15); colorMode(RGB,1.0); smooth(); for (int i=0; i < line_array.length; i++) { float maxSpeed=10.0; line_array[i] = new cLine(i,maxSpeed,numOfObjs); } } void draw() { for (int i=0; i < line_array.length; i++) { line_array[i].update(newX(), newY()); } } void mouseReleased() { clickX = mouseX; clickY = mouseY; } void keyPressed() { background(50); } //to cause interpolation from old to new location float newX() { prevX = ((constrain(clickX,0,width) - prevX)/200) + prevX; return prevX; } float newY() { prevY = ((constrain(clickY,0,height) - prevY)/200) + prevY; return prevY; } class cLine { float mySpeed; // horiz increment int myHpos=0; int myID; color myClr; float bluShift; //incrementors for color float rgShift; //constructor cLine(int index, float maxspd, int numOfObjs) { myID = index; mySpeed = ( random(1.5,maxspd) ); //vary minimum to avoid too-slow lines leaving black space rgShift = float(myID)/float(numOfObjs); } void update(float nX, float nY) { float xk = nX/width; float yk = nY/height; myClr = color(rgShift*xk, rgShift*yk, yk+bluShift, 0.6); stroke(myClr); line(myHpos, myID*7, nX, nY); //max id is related to max height, so nudging myID to fit myHpos += random(mySpeed); //now test for the location... if (myHpos > width) { myHpos=0; //wrap bluShift += 0.1; if (bluShift > 10) { bluShift=0; } } }//end of method update() }// end of class cLine