xxxxxxxxxx
85
var xarray = [];
var yarray = [];
var xyarray = [];
var coords = [];
function setup() {
createCanvas(600, 600);
for (let x = 0; x < 100; x++) {
xyarray[x] = []; // create nested array
}
}
function draw() {
background(220);
noFill();
strokeWeight(2);
// two 1D arrays (one for X, one for Y)
// beginShape();
// if (xarray.length < 100) {
// for (var a = 0; a < xarray.length; a++) {
// curveVertex(xarray[a], yarray[a]);
// }
// } else {
// for (var a = 0; a < 100; a++) {
// curveVertex(xarray[a], yarray[a]);
// }
// }
// endShape();
// one 2D array
// beginShape();
// if (xyarray[0].length < 100) {
// for (let b = 0; b < xyarray[0].length; b++) {
// curveVertex(xyarray[0][b], xyarray[1][b]);
// }
// } else {
// for (let b = 0; b < 100; b++) {
// curveVertex(xyarray[0][b], xyarray[1][b]);
// }
// }
// endShape();
// an array of Point2D objects
beginShape();
if (coords.length < 100) {
for (var c = 0; c < coords.length; c++) {
curveVertex(coords[c].x, coords[c].y);
}
} else {
for (var d = 0; d < 100; d++) {
curveVertex(coords[d].x, coords[d].y);
}
}
endShape();
}
function mouseMoved() {
var mx = pmouseX;
var my = pmouseY;
// two 1D arrays (one for X, one for Y)
// xarray.splice(0, 0, mx);
// yarray.splice(0, 0, my);
// one 2D array
// xyarray[0].splice(0, 0, mx);
// xyarray[1].splice(0, 0, my);
// an array of Point2D objects
var newCoord = new Point2D(mx, my);
coords.splice(0, 0, newCoord);
}
class Point2D {
constructor(x, y) {
this.x = x;
this.y = y;
}
}