/* * Author: Laurie Waxman * Date: 18.03.2013 * Class: PUDT 1203 Creative Computing * * Draws randomized (and often freaky) bunnies on a field of grass. * Demonstrates knowledge of loops, conditional statements and functions. */ PImage grass1; PImage grass2; PImage grass3; float scene; float xPos; float yPos; float eyeWidth; float headWidth; float bodyWidth; void setup(){ size(800, 800); noStroke(); background(84, random(100, 200), 72); grass1 = loadImage("grass1.jpg"); grass2 = loadImage("grass2.jpg"); grass3 = loadImage("grass3.jpg"); } void draw(){ //picks 1 of 3 grass backgrounds scene = random(0, 10); if(scene >= 0 && scene <= 3){ image(grass1, 0, 0); }else if(scene > 3 && scene <= 6){ image(grass2, 0, 0); }else if(scene > 6 && scene < 10){ image(grass3, 0, 0); } //repeats and randomizes bunnies for(int b=0; b<20; b++){ for(int i=0; i<20; i++){ xPos = b*(random(150, 200)); //randomize bunny position yPos = i*(random(150, 200)); eyeWidth = random(25, 35); //eye width headWidth = random (60, 70); //body width bodyWidth = random (80, 100); bunny(xPos, yPos); //calls on bunny function } } noLoop(); //stops you going blind from hundreds of bunnies blinking across the page } //function to draw a bunny with randomizing features // that has variable x and y coordinates so it can be //redrawn over and over in different places void bunny(float x, float y){ smooth(); //body fill(random(0, 200)); ellipse(x, y+50, bodyWidth, bodyWidth); //randomizes some bunnies to have floppy ears if(random(0, 20) < 3){ // draw floppy ears //right beginShape(); vertex(x+5, y-15); bezierVertex(x-25, y-30, x-40, y-65, x-70, y+20); vertex(x-70, y+20); bezierVertex(x-60, y+25, x-40, y-15, x-30, y-20); endShape(); //left beginShape(); vertex(x-5, y-15); bezierVertex(x+25, y-30, x+40, y-65, x+70, y+20); vertex(x+70, y+20); bezierVertex(x+60, y+25, x+40, y-15, x+30, y-20); endShape(); } else{ // draw straight ears //right beginShape(); vertex(x-5, y-5); bezierVertex(x-6, y-15, x-8, y-70, x-30, y-90); vertex(x-30, y-90); bezierVertex(x-40, y-75, x-30, y-40, x-20, y-5); endShape(); //left beginShape(); vertex(x+5, y-5); bezierVertex(x+5, y-5, x+8, y-70, x+30, y-90); vertex(x+30, y-90); bezierVertex(x+40, y-75, x+30, y-40, x+20, y-5); endShape(); } //head ellipse(x, y+5, headWidth, headWidth); //feet ellipse(x-28, y+50+(bodyWidth/2), 50, 20); ellipse(x+28, y+50+(bodyWidth/2), 50, 20); ellipse(x-35, y+35+(bodyWidth/2), 50, 20); ellipse(x+35, y+35+(bodyWidth/2), 50, 20); //eyes fill(255); ellipse(x-17, y, eyeWidth, eyeWidth); ellipse(x+17, y, eyeWidth, eyeWidth); fill(random(50, 120), random(50, 150), random(0, 120)); //irises ellipse(x-17, y, eyeWidth-10, eyeWidth-10); ellipse(x+17, y, eyeWidth-10, eyeWidth-10); fill(0); //pupils ellipse(x-17, y, 10, 10); ellipse(x+17, y, 10, 10); //nose fill(222, 136, 210); ellipse(x, y+15, 20, 10); }