int lineWeight; color lineColor; int drawMode; // 0-eraser 1-brush float dx, dy, delta; int pKey = -1; int i; float angle; PFont font; void setup(){ size(400,200); background(255); lineWeight = 1; lineColor = color(random(255),random(255),random(255), random(40)); drawMode = 1; font = loadFont("ArialNarrow-12.vlw"); smooth(); } void draw(){ //get mouse speed dx = mouseX-pmouseX; dy = mouseY-pmouseY; delta = sqrt(dx*dx + dy*dy); if(mousePressed){ // Use the mouse as a brush... if(drawMode == 1){ stroke(lineColor); strokeWeight(lineWeight); for(i=0; i<200; i++){ pushMatrix(); translate(i,i); rotate(angle); bezier(mouseX*delta, pmouseY, 100, 10, 90, 200, pmouseX, mouseY*delta); bezier(400, 20, 10, 10, 90, 90, 15, 400); popMatrix(); } angle += 0.2; for(int i = 0; i < 100; i++){ pushMatrix(); translate(i,i); rotate(delta); bezier(pmouseX+40, pmouseY-40, 20, 10, 20, 10,mouseX, mouseY); bezier(pmouseX-40, pmouseY+40, 20, 10, 20, 10,mouseY, mouseX); popMatrix(); } } // use the mouse as an eraser... else if(drawMode == 0){ stroke(255); strokeWeight(delta); line(mouseX,mouseY,pmouseX,pmouseY); line(mouseY,mouseX,pmouseY,pmouseX); } } } void keyPressed(){ // Erase Screen and create transparent background if(pKey != key){ if(key == 't'){ background(0); fill(0,60); rect(0,0,width,height); } // change line width else if(key == '1'){ lineWeight = 1; } // increase line width else if(key == '2'){ lineWeight = 2; } // use the mouse as an eraser//// else if(key == 'e'){ drawMode = 0; lineColor = color(255); } //change line color else if(key == 'r'){ drawMode = 1; lineColor = color(random(255),random(0),random(0), random(40)); } else if(key == 'g'){ drawMode = 1; lineColor = color(random(0),random(255),random(0), random(40)); } else if(key == 'w'){ drawMode = 1; lineColor = color(random(255),random(60)); } //USER GUIDE else if(key == '?'){ textFont(font, 12); fill(0); String s = "use r or g to change color - use e to erase - use t for transparent background - use 1/2 to change lineWidth - use ? to view the user guide"; text(s, 15, 20, 200, 400); } } pKey = key; } void keyReleased(){ pKey = -1; }