xxxxxxxxxx
93
var index = 0;
var Arrayx = [];
var ArrayY = [];
var Array2D = [];
var pointArray = [];
function setup() {
createCanvas(600, 600);
}
function draw() {
//two1DArrays();
//one2DArray();
point2DArray();
}
function point2DArray(){
stroke(0);
if (mouseIsPressed === true) {
pointArray[index] = new point2D();
index++;
noFill();
stroke(color("pink"));
strokeWeight(2);
beginShape();
for (var i = 0; i < pointArray.length; i++){
let X = 0 ; let Y = 0;
X = pointArray[i].x;
Y = pointArray[i].y;
vertex(X, Y);
}
}
endShape();
}
class point2D {
constructor() {
this.x = mouseX;
this.y = mouseY;
}
}
function one2DArray() {
stroke(0);
Array2D[0] = [0, 0];
if (mouseIsPressed === true) {
index++;
Array2D[index] = [mouseX, mouseY];
noFill();
stroke(color("red"));
strokeWeight(2);
beginShape();
for (var i = 1; i < index; i++){
var x = Array2D[i][0];
var y = Array2D[i][1];
vertex(x, y);
}
}
endShape();
}
function two1DArrays() {
stroke(0);
if (mouseIsPressed === true) {
index++;
Arrayx[index] = mouseX;
ArrayY[index] = mouseY;
}
noFill();
stroke(color("orange"));
strokeWeight(2);
beginShape();
for (var i = 0; i < 2; i++){
vertex(Arrayx[index-i], ArrayY[index-i]);
}
endShape();
}