//declare variables float rColor = 0; float gColor = 0; float bColor = 0; int typeCheck = 0; float maxDistance; float diameter = 60; float mouseDist; float k = 0; int y = 0; int x = 0; //setup for the stage void setup () { size (500,500); smooth(); fill(0); frameRate(10); //the dist() finds the distance between two points, //here we find the distance to the middle of the screen from the origin maxDistance = dist(0, 0, width/4, height/4); } //start drawing - check var typeCheck for type of shape to draw based on mousePressed event void draw() { background(0); stroke(rColor, gColor, bColor); smooth(); for (x = 0; x <= width; x+= 40) { for (y = 0; y <= height; y+= 40) { mouseDist = dist(mouseX, mouseY, x, y); diameter = (mouseDist / maxDistance) * cos(k+x/300-y/200) * 30; if (typeCheck == 0){ ellipseDraw(); } else if (typeCheck == 1){ rectDraw(); } } } //increments k value up to 2PI for sin and cos wave values if (k <= 6.28){ k += .05; } else{ k=0; } } void mousePressed() { //randomize colors for rgb channels for the stroke colors rColor = random(255); gColor = random(255); bColor = random(255); //checks typeCheck value to know whether to call either the ellipseDraw or rectDraw functions if (typeCheck == 0) { typeCheck = 1; } else if (typeCheck == 1) { typeCheck = 0; } } //function for ellipses drawn void ellipseDraw() { fill(mouseY/4, mouseDist/4, sin(k)* 100, 50); ellipse(x, y, mouseX/diameter, mouseY/diameter); } //function for rectangles to be drawn void rectDraw() { fill(mouseY/4, mouseDist/4, sin(k)* 100, 50); rect(x, y, mouseX/diameter, mouseY/diameter); }