let x=0,
y=0,
a=100,
b=270;
function setup() {
createCanvas(400, 400);
background(0);
plotP();
}
function draw() {
translate(15,width/2); stroke(random(50,155),random(50,255),random(50,255))
strokeWeight(0.08);
mBeam();
}
function mBeam(){
if(mouseX-15>width/2-a && mouseX-15 < width-a-30){
msX = mouseX- 15;
msY = mouseY-width/2;
m1 = (msY)/(msX-a);//slope
m2 = (msY)/(msX-b);//slope2
a1 = m1*m1;
a2 = m2*m2;
b1 = -(2*a*m1*m1+4*a);
b2 = 4*a-2*b*m2*m2;
c1 = a*a*m1*m1;
c2 = b*b*m2*m2-4*370*a;
tmp = (b1*b1-4*a1*c1)
tmp2 = (b2*b2-4*a2*c2)
x1 = (-b1-sqrt(tmp))/(2*a1);
x2 = (-b2+sqrt(tmp2))/(2*a2);
y1 = sqrt(4*a*x1);
y2 = sqrt(370*4*a-4*a*x2);
if(msY<0){
line(msX,msY,x1,y1);
line(msX,msY,x2,y2);
line(x1,y1,width-x1-30,y1)
line(x2,y2,-x2+width-30,y2)
}
if(msY>=0){
line(msX,msY,x1,-y1);
line(msX,msY,x2,-y2);
line(x1,-y1,width-x1-30,-y1)
line(x2,-y2,-x2+width-30,-y2)
}
}
}
function plotP(){
if (x===0){translate(15,width/2)};
for (i=-100;i<100;i=i+1){
t=i/90;
y=2*a*t;
x=a*t*t;
g =-a*t*t+370
circle(x,y,2);
circle(g,y,2)
circle(b,0,10)
circle(a,0,10);
line(-a,-width/2,-a,width/2)
}
}
function mousePressed(){
background(0);
plotP()
}