xxxxxxxxxx
26
var x2 = 200, y2 = 200; // initial ordered pairs (at center of screen)
function setup() {
createCanvas(400, 400); //create the canvas
background(60); //black background
frameRate (9); //frame rate or speed
}
function draw() {
stroke(random(20), random(255), 255) //random linecolor
strokeWeight(100-frameCount/3);//shrinking line width with each frame
x1 = random(400);//random x1 value
y1 = random(400);//random y1 value
x2 = random(400);
y2 = 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
b1 = y1-x1*m1 //find b for line 1
m2 = -1/(m1) //perpendicular slope is -1/m for line 1
b2 = y1-x1*m2 //find b of line2 (y = mx+b)
line(x2,m2*x2+b2,x1,m2*(x1)+b2) //two points (x2,y2) and (x1,m2(x1)+b2)
if(frameCount >300){
noLoop();
}
}