//Dave Bunnell Lab9 arrays //Dynamic Tinkertoys // Declare two arrays with 10 elements. int[] xpos = new int[21]; int[] ypos = new int[21]; int pressedCount=0; //set a variable to count mouse presses float r; float g; float b; float a; float diam; void setup() { size(1200,700); frameRate(10); // Initialize all elements of each array to zero. for (int i = 0; i < xpos.length; i ++ ) { xpos[i] = 0; ypos[i] = 0; } }//end of setup void mousePressed() { xpos[pressedCount] = mouseX; ypos[pressedCount] = mouseY; if(pressedCount<20) pressedCount=pressedCount+1; else pressedCount=0; } void draw() { background(0,255,0); // Draw the lines for (int i = 0; i < pressedCount-1; i ++ ) { stroke(0,0,255,70); strokeWeight(pressedCount); line(xpos[i],ypos[i],xpos[i+1],ypos[i+1]); if (mouseButton==LEFT) { fill(255,0,0); // pretty red diam = pressedCount + 5; // Make it look like red tinkertoy connectors } if (mouseButton==RIGHT) { r= random(0,255); g= random(0,255); b= random(0,255); a= random(0,255); diam= random(0,60); fill(r,g,b,a); } ellipse(xpos[i],ypos[i],diam,diam); println("mouse button is " + mouseButton); } }//end of Draw