// Graffitti Machine
// Created Nov 12th, 2006
// Move the mouse to drop paint
// Press mouse button for spray paint
// Press backspace to erase slightly
// Press backspace 3 times to erase completely
// Hold backspace while moving or clicking mouse for a cheap trick
int x, y, prevx, prevy, strokeSize;
float dispx, radius, rotation, distance;
boolean move = false;
int sprayJittrX=-15, sprayJittrY=-13;
void setup() {
size(400, 400);
smooth();
noStroke();
frameRate(30);
background(255);
fill(0);
noCursor();
}
void draw() {
if((keyPressed)&&(key == BACKSPACE)){
fill(255, 100);
rect(0, 0, width, height);
fill(0);
}
//////////////// assigning variable values ////////////////
dispx = random(30);
rotation = (random(1) * TWO_PI);
x = mouseX;
y = mouseY;
if (move)
{
prevx = pmouseX;
prevy = pmouseY;
distance = dist(x, y, prevx, prevy);
radius = random(15);
//////////////// random dots ////////////////
pushMatrix();
translate(x, y);
rotate (rotation);
translate(dispx, 0);
ellipse(0, 0, radius, radius);
//////////////// large & splashy spots ////////////////
if (radius >= 14){
ellipse(0, 0, radius+3, radius/4);
rotate(rotation);
ellipse(0, 0, radius+3, radius/4);
rotate(rotation);
ellipse(0, 0, radius+3, radius/4);
rotate(rotation);
ellipse(0, 0, radius+3, radius/4);
}
popMatrix();
//////////////// Small directional spots and lines ////////////////
if(distance>14)
strokeSize --;
else
strokeSize = 4;
if ((distance >= 10)&&(distance<=75)&&(strokeSize >=0)){
ellipse(prevx, prevy, 5, 5);
ellipse(prevx, prevy, radius, radius);
stroke(0);
strokeWeight(strokeSize);
line(prevx, prevy, x, y);
ellipse((prevx+x)/2, (prevy+y)/2, radius/2, radius/2);
noStroke();
ellipse(x, y, strokeSize*2, strokeSize*2);
}
}
//////////////// Spray Paint ////////////////
if (mousePressed){
spray(10);
}
move = false;
}
void mouseMoved(){
move = true;
}
void spray(int times){
float dispx1 = random(-60, 60);
float dispx2 = random(-60, 60);
pushMatrix();
translate(x+sprayJittrX, y+sprayJittrY);
if(sprayJittrX < 15)
sprayJittrX++;
else sprayJittrX = -15;
if(sprayJittrY < 15)
sprayJittrY++;
else sprayJittrY = -13;
fill(150, 0, 0, 50);
rotate(rotation);
ellipse(dispx, 0, 2, 2);
ellipse(-dispx, 0, 2, 2);
ellipse(0, dispx, 2, 2);
ellipse(0, -dispx, 2, 2);
ellipse(dispx1, 0, 2, 2);
ellipse(-dispx1, 0, 2, 2);
ellipse(0, dispx1, 2, 2);
ellipse(0, -dispx1, 2, 2);
ellipse(dispx2, 0, 2, 2);
ellipse(-dispx2, 0, 2, 2);
ellipse(0, dispx2, 2, 2);
ellipse(0, -dispx2, 2, 2);
rotation = rotation+random(PI);
times--;
popMatrix();
if(times>0)
spray(times);
fill(0);
}
Exercise 07: Make a custom software drawing tool that makes a different quality of marks when the mouse is pressed and not pressed.