float x = 100; float y = 100; float angle1 = 0.0; float segLength = 50; float horizon; void setup() { size(640, 360); strokeWeight(20.0); stroke(255, 100); size( 600, 400 ); horizon= height/3; } void draw() { background(50,182,255); fill( 155, 255, 0); ellipseMode( CORNER ); ellipse(10, 0, 50, 50); fill( 100, 255, 100 ); //-- rectMode( CENTER ); //-- rect( 300, 200, 300, 200); rectMode( CORNER ); rect( 0, horizon, width, height*2/3); float dx = mouseX - x; float dy = mouseY - y; angle1 = atan2(dy, dx); x = mouseX - (cos(angle1) * segLength); y = mouseY - (sin(angle1) * segLength); segment(x, y, angle1); ellipse(x, y, 20, 20); } void segment(float x, float y, float a) { pushMatrix(); translate(x, y); rotate(a); line(0, 0, segLength, 0); popMatrix(); }