//Greg Batha DESMA 28 Interactivity
//exercise E
import processing.xml.*;
import processing.candy.*;
SVG g;
void setup()
{
size(400,400);
background(255);
colorMode(HSB);
noStroke();
//imports svg "grass.svg" and sets draw mode to center
g = new SVG(this, "grass.svg");
g.drawMode(CENTER);
}
void draw()
{
//calculates the mouse's velocity
float v = dist(pmouseX, pmouseY, mouseX, mouseY);
println(v);
//puts an if statement around the entire draw method
//to prevent a drawing glitch
if(mouseX !=0 && (mouseY != 0))
{
//if mouse is pressed, draws grass
if (mousePressed == true)
{
//rotates the matrix so that the rotation of the
//grass is randomized
pushMatrix();
translate(mouseX, mouseY);
rotate(random(PI/-6, PI/6));
//ignores the svg style so that the brightness
//of the grass can be randomized with the fill function
g.ignoreStyles();
//if you move the mouse too quickly, the grass dies
//draw slowly for healthy grass!
if(v <= 10)
{
fill(65, 171, random(90, 220));
}
else
{
fill(40, 150, random(90, 220));
}
g.draw(random(-10, 10), random(-10, 10), random(20, 50), random(20, 50));
popMatrix();
}
//if mouse is not pressed, draws blue circles
else
{
//draw quickly for blue skies,
//draw slowly to draw clouds!
if(v <=7)
{
fill(180, 0, 255, random(0, 10));
}
else
{
fill(180, 161, 255, random(30, 75));
}
ellipse(mouseX, mouseY, 50, 50);
}
}
}
Gregory - E
on Wednesday, Oct 15, 2008 – 9:16 am
One Comment
this program is well written. i like the clearness and cleanness of it and how the purple turns into white. the transparency works beautifully. I also like how the grass accumulates when you keep on pressing the mouse button.