public
Last active

  • Download Gist
interactive_line_2_keys.pde
Processing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/*
 
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;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.