float dx, dy, delta,angle; float centerX,centerY; void setup(){ size(400,400); background(255); centerX=200; centerY=200; } void draw(){ if (mousePressed){ if(keyPressed){ if(key=='1'){ stroke(255,0,0); rect(mouseX,mouseY,dx,dy); line(mouseX,mouseY,centerX,centerY); } if(key=='2'){ stroke(0,255,0); rect(mouseX,mouseY,dx,dy); line(mouseX,mouseY,centerX+50,centerY+50); } if(key=='3'){ stroke(0,0,255); rect(mouseX,mouseY,dx,dy); line(mouseX,mouseY,centerX+100,centerY+100); } ///////////////////////////// dx = mouseX - pmouseX; dy = mouseY - pmouseY; delta = sqrt(dx*dx + dy*dy); dx = mouseX - pmouseX; dy = mouseY - pmouseY; angle = atan2(dy,dx)-PI/2; ///////////////////////////// } } }