PVector marker = new PVector (40, 250);
PVector arms = new PVector (200, 250);
PVector arm1 = new PVector ();
PVector arm2 = new PVector ();
float line_sm;
float angle_m;
float angle_mh;
float angle_sm;
float angle_sh;
PVector arms = new PVector (200, 250);
PVector arm1 = new PVector ();
PVector arm2 = new PVector ();
float line_sm;
float angle_m;
float angle_mh;
float angle_sm;
float angle_sh;
void setup (){
}
}
void draw (){
fill (200, 80);
rect (0, 0, width, height);
line_sm = sqrt (sq (marker.x)+sq (marker.y));
angle_m = acos (marker.x/line_sm);
angle_mh = acos ((sq (arms.y)-sq (arms.x)-sq (line_sm))/(-2*arms.x*line_sm));
angle_sm = acos ((sq (line_sm)-sq (arms.x)-sq (arms.y))/(-2*arms.x*arms.y));
angle_sh = angle_m + angle_mh;
arm1.x = arms.x*cos (angle_sh);
arm1.y = arms.x*sin (angle_sh);
arm2.x = arms.y*cos (angle_sm-(PI-angle_sh));
arm2.y = arms.y*sin (angle_sm-(PI-angle_sh));
pushMatrix ();
translate (width/2, 200);
stroke (255, 0, 0);
line (0, 0, marker.x, marker.y);
stroke (0, 0, 255);
line (0, 0, arm1.x, arm1.y);
translate (arm1.x, arm1.y);
line (0, 0, arm2.x, arm2.y);
popMatrix ();
marker.set (mouseX-width/2, mouseY-200);
}
fill (200, 80);
rect (0, 0, width, height);
line_sm = sqrt (sq (marker.x)+sq (marker.y));
angle_m = acos (marker.x/line_sm);
angle_mh = acos ((sq (arms.y)-sq (arms.x)-sq (line_sm))/(-2*arms.x*line_sm));
angle_sm = acos ((sq (line_sm)-sq (arms.x)-sq (arms.y))/(-2*arms.x*arms.y));
angle_sh = angle_m + angle_mh;
arm1.x = arms.x*cos (angle_sh);
arm1.y = arms.x*sin (angle_sh);
arm2.x = arms.y*cos (angle_sm-(PI-angle_sh));
arm2.y = arms.y*sin (angle_sm-(PI-angle_sh));
pushMatrix ();
translate (width/2, 200);
stroke (255, 0, 0);
line (0, 0, marker.x, marker.y);
stroke (0, 0, 255);
line (0, 0, arm1.x, arm1.y);
translate (arm1.x, arm1.y);
line (0, 0, arm2.x, arm2.y);
popMatrix ();
marker.set (mouseX-width/2, mouseY-200);
}
Geen opmerkingen:
Een reactie posten