xxxxxxxxxx
93
x = []
y = []
pairs = []
objs = []
method = 0;
function setup() {
createCanvas(400, 400);
method = random([0, 1, 2]);
}
function draw() {
background(220);
noFill();
// storing them in 2 lists
if(method == 0){
beginShape();
for(var i = 0; i < x.length; i ++){
vertex(x[i], y[i]);
}
endShape();
}
if(method == 1){
beginShape();
for(var j = 0; j < pairs.length; j ++){
var point_x = pairs[j][0];
var point_y = pairs[j][1];
vertex(point_x, point_y);
}
endShape();
}
if(method == 2){
beginShape();
for(var k = 0; k < objs.length; k ++){
vertex(objs[k].x, objs[k].y);
}
endShape();
}
}
function mouseDragged(){
if(method == 0){
if(x.length < 100){
x.push(mouseX);
y.push(mouseY);
}
else{
x.shift();
y.shift();
}
}
if(method == 1){
if(pairs.length < 100){
pairs.push([mouseX, mouseY]);
}
else{
pairs.shift();
}
}
if(method == 2){
if(objs.length < 100){
objs.push(new P(mouseX, mouseY));
}
else{
objs.shift();
}
}
}
class P {
constructor(x, y){
this.x = x;
this.y = y;
}
}