Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
/*
Interactive Drawing Tool 2
Making Grass
john@johnkeefe.net
January 8, 2011
*/
int[] grassColor = { 0, 1, 0 }; // allows for green in the stroke() line
float grassRandom;
void setup() {
size(500,500);
background(255);
smooth();
}
void draw() {
// when mouse is pressed
if(mousePressed) {
for(int i = 0; i < 10; i++) {
// randomizing the range of red, green or blue used
// grassColor[] elements are 0 or 1 depending on keyPressd
grassRandom = random(100,255);
stroke(grassColor[0]*grassRandom, grassColor[1]*grassRandom, grassColor[2]*grassRandom);
// make fence line extending above mouse position
// randomize the height of the blade mouseY-random(30,50)
// randomize the angle of the blade mouseX+random(-10,10)
line(mouseX,mouseY,mouseX+random(-10,10),mouseY-random(30,50));
}
}
}
void keyPressed() {
if(key == 'c') {
// clear the screen
background(255);
} else if(key == 'r') {
// make the color red
grassColor[0] = 1; // multiplier in the stroke() command is 1 for red
grassColor[1] = grassColor[2] = 0;
} else if(key == 'g') {
grassColor[1] = 1; // multiplier in the stroke() command is 1 for green
grassColor[0] = grassColor[2] = 0;
} else if(key == 'b') {
grassColor[2] = 1; // multiplier in the stroke() command is 1 for blue
grassColor[0] = grassColor[1] = 0;
} else if(key == 'p') {
grassColor[0] = 0.5; // purple is 128,0,255 ... so this gets us that
grassColor[1] = 0;
grassColor[2] = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.