// Design sketch drawing a field of ovals. Some interactivity on mouse click and drag. // Nelson Minar 2007-12-23 int numCircles = 12; float circleSize = 0.76; float eccentricity = 0.65; boolean needsDraw = true; int seed = millis(); void setup() { size(350, 350); smooth(); noFill(); stroke(40); strokeWeight(1.8); } void draw() { // only redraw if the user just clicked if (!needsDraw) return; background(230); randomSeed(seed); // reseed so we don't get random jitter on every draw float w = width, h = height; for (float i = 0; i < numCircles; i++) { for (float j = 0; j < numCircles; j++) { resetMatrix(); // calculate the ellipse size float cw = eccentricity * circleSize * w / numCircles; float ch = circleSize * h / numCircles; // position the ellipse translate(w * i / numCircles, h * j / numCircles); translate(0.5 * w / numCircles, 0.5 * h / numCircles); // rotate it randomly rotate(random(TWO_PI)); // and draw ellipse(0, 0, cw, ch); } } needsDraw = false; } // Left button draws a new field, with circle density corresponding to Y position // Right button saves a snapshot void mousePressed() { if (mouseButton == LEFT) { numCircles = 3 + int(mouseY * 30.0 / width); seed = millis(); needsDraw = true; } else if (mouseButton == RIGHT) { save("snapshot.png"); println("saved"); } } // Dragging the mouse changes eccentricity depending on X position void mouseDragged() { eccentricity = float(mouseX) / width; needsDraw = true; }