float dx, dy, delta,angle; float centerX,centerY; int drawIndex; int valueR,valueG,valueB; void setup(){ size(400,400); background(255); centerX=random(400); centerY=random(400); PFont f = loadFont("ArialNarrow-64.vlw"); textFont(f,20); } void draw(){ if (mousePressed){ if(keyPressed){ if(key=='1'){ drawIndex=1; stroke(255,0,0,50); rect(mouseX,mouseY,dx,dy); line(mouseX,mouseY,centerX,centerY); valueR++; fill(0); text ("red:"+valueR,10,320); } else if(key=='2'){ drawIndex=1; stroke(0,255,0,50); rect(mouseX,mouseY,dx,dy); strokeWeight(delta); line(mouseY,mouseY,pmouseX,pmouseY); line(mouseX,mouseY,centerX,centerY); valueG++; fill(100); text ("green:" +valueG ,10,340); } else if(key=='3'){ drawIndex=1; stroke(0,255,255,50); rect(mouseX,mouseY,dx,dy); strokeWeight(delta/5); line(mouseX,mouseY,centerX,centerY); valueB++; fill(100); text ("blue:"+ valueB ,10,360); } else if(key=='4'){ drawIndex=0; background(255); } keyReleased(); centerX=random(400); centerY=random(400); } ///////////////////////////// dx = mouseX - pmouseX; dy = mouseY - pmouseY; delta = sqrt(dx*dx + dy*dy); dx = mouseX - pmouseX; dy = mouseY - pmouseY; angle = atan2(dy,dx)-PI/2; ///////////////////////////// } }