xxxxxxxxxx
38
function setup() {
// put setup code here
createCanvas(600, 600);
background(255,0.4);
}
let xandy = [];
let straight = false;
function draw() {
// put drawing code here
stroke(0);
noFill();
strokeWeight(4);
beginShape();
for (var i = 0; i < xandy.length; i++) {
vertex(xandy[i][0], xandy[i][1]);
}
endShape();
}
function flatten(list){
for (var i=1; i<xandy.length-1;i++){
xandy[i][0] = (xandy[i-1][0] + xandy[i+1][0])/2;
xandy[i][1] = (xandy[i-1][1] + xandy[i+1][1])/2;
}
}
function mousePressed(){
if (xandy.length < 100) {
xandy.push([mouseX, mouseY]);
} else {
xandy.shift();
}
}
function mouseReleased(){
flatten(xandy);
}