float angle = 0.0; float speed = 0.025; // Play with this!!! (Default 0.03) float direction = 1; // Play with this too. (Default = 1) float r = width/40; float x; boolean toggleLoop = true; void setup() { size(600, 400); //noStroke(); smooth(); background(0); float speed = 1; frameRate (120); } void draw() { fill(0, 2); //rect(0, 0, width, height); stroke (random(225, 255), random (175, 200), random (150), random(50, 100)); //fill(255); angle = angle + speed; float amp = height/9; //amplitude (Default = height/9) float y = (height/2) + (sin(angle + (.5*PI)) * amp); // starts at top.* r = (width/40); // allows for resized window. ellipse (x, y, r, r); // show Y axis oscillation example //point (x, y); // This really slows things down. x = x + direction; if ((x > width) || (x < width - width)) { direction = -direction; } } // Mouse toggle code by amnon.owed // http://forum.processing.org/topic/mouse-toggle-loop // Place boolean toggleLoop = true; above setup. void mousePressed() { if (mouseButton == LEFT) { if (toggleLoop) { noLoop(); toggleLoop = false; } else { loop(); toggleLoop = true; } } } //R.A.Robertson, adapted from "Processing" Chapter 32_3, Reas & Fry // see also Reas & Fry Chapter 31_2.