Skip to content

Instantly share code, notes, and snippets.

@nataliefreed
Created October 1, 2014 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nataliefreed/a6e748d21482355b8cd4 to your computer and use it in GitHub Desktop.
Save nataliefreed/a6e748d21482355b8cd4 to your computer and use it in GitHub Desktop.
//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