xxxxxxxxxx
50
let x = [3];
let y = [3];
let pos_x, pos_y;
let trigger;
function setup() {
createCanvas(400, 400);
x[0] = int(random(width));
y[0] = int(random(height));
x[1] = int(random(width));
y[1] = int(random(height));
}
function draw() {
background(0);
stroke(255);
line(x[0], y[0], x[1], y[1]);
x[2] = mouseX;
y[2] = mouseY;
stroke(150, 0, 0);
line(x[0], y[0], x[2], y[2]);
stroke(0, 150, 0);
line(x[2], y[2], x[1], y[1]);
let A = (x[2] - x[1]) / (x[0] - x[1]);
let B = (y[2] - y[1]) / (y[0] - y[1]);
if (abs(A - B) <= 0.1) {
if (x[0] < x[1]) {
if ((x[2] > x[0]) && (x[2] < x[1])) {
trigger = 1;
}
}
else {
if ((x[2] < x[0]) && (x[2] > x[1])) {
trigger = 1;
}
}
}
else {
trigger = 0;
}
print(trigger, abs(A - B));
}