xxxxxxxxxx
20
var x2 = 200, y2 = 200; // initial ordered pairs (at center of screen)
function setup() {
createCanvas(400, 400); //create the canvas
background(255); //black background
frameRate (3); //frame rate or speed
}
function draw() {
stroke(random(255), random(255), random(255)) //random linecolor
strokeWeight(random(50));//random line width
x1 = random(400);//random x1 value
y1 = random(400);//random y1 value
x3 = random(400);
y3 = random(400);
line1 = line(x1,y1,x2,y2) //draw line from center (200,200) to random (x1,y1)
m1 = (y2-y1)/(x2-x1); //calculate slope of line1
m2 = -1/(m1) //perpendicular slope is -1/m for line 1
b2 = y3-x3*m2 //find b of line2 (y = mx+b) using a new point (x3,y3)
line(x3,m2*x3+b2,x1,m2*(x1)+b2) //two points (x2,y2) and (x1,m2(x1)+b2)
}