xxxxxxxxxx
let xPosArray = [];
let yPosArray = [];
let xyPosArray = [];
let pointsArray = [];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
xPosArray.push(mouseX);
yPosArray.push(mouseY);
xyPosArray.push([mouseX, mouseY]);
pointsArray.push(createVector(mouseX, mouseY));
if (xPosArray.length > 100) {
xPosArray.shift();
yPosArray.shift();
xyPosArray.shift();
pointsArray.shift();
}
noFill();
stroke(0, 0, 255);
beginShape();
for (let i = 0; i < xPosArray.length; i++) {
vertex(xPosArray[i], height / 4);
}
endShape();
stroke(0, 255, 0);
beginShape();
for (let i = 0; i < yPosArray.length; i++) {
vertex(yPosArray[i], height / 2);
}
endShape();
stroke(255, 0, 0);
beginShape();
for (let i = 0; i < xyPosArray.length; i++) {
let x = xyPosArray[i][0];
let y = xyPosArray[i][1];
vertex(x, height * 3 / 4);
}
endShape();
for (let i = 0; i < pointsArray.length; i++) {
let point = pointsArray[i];
fill(0);
ellipse(point.x, point.y, 5, 5);
}
}