Created
October 1, 2014 23:00
-
-
Save nataliefreed/a6e748d21482355b8cd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//diamonds sprinkled randomly | |
//Natalie Freed Oct. 2014 | |
int numberOfDiamonds; //we will randomize this | |
float diamondWidth; //we will randomize this | |
float diamondHeight; //related to height | |
void setup() | |
{ | |
size(500, 500); | |
noFill(); | |
} | |
void draw() | |
{ | |
background(255); | |
numberOfDiamonds = round(random(0, 100)); | |
diamondWidth = random(20, 100); | |
diamondHeight = diamondWidth * 2; | |
for(int i=0;i<numberOfDiamonds;i++) | |
{ | |
translate(random(0, 100), random(0, 100)); //move a diamond | |
rotate(random(0, TWO_PI)); //rotate it | |
drawDiamond(diamondWidth, diamondHeight); | |
} | |
noLoop(); //don't repeat | |
} | |
void drawDiamond(float w, float h) | |
{ | |
beginShape(); | |
vertex(w/2, -h/2); | |
vertex(w, 0); | |
vertex(w/2, h/2); | |
vertex(0, 0); | |
endShape(CLOSE); | |
} | |
void mousePressed() | |
{ | |
redraw(); //call draw again on click to re-randomize | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment