xxxxxxxxxx
//Dana Hoppe
//Squiggle Paint Brush
//6-7-2019
//List for storing squiggles
let squigs = [];
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
}
function draw() {
//updates squiggle movement
for (i = 0; i < squigs.length; i ++){
squigs[i].update();
squigs[i].show();
//removes finished squiggles
if(squigs[i].r < 1){
squigs.splice(i, 1);
}
}
}
function mouseDragged() {
//adds new squiggles
squig = new squiggle(mouseX,mouseY);
squigs.push(squig);
}
class squiggle {
constructor(x,y) {
this.x = x;
this.y = y;
//initial radius
this.r = 200;
//initial degree of movement
this.p = 20;
//generates initial value for noise movement
this.offsetX = random(0,100);
this.offsetY = random(0,100);
}
update() {
if(this.r > 1){
//controls how much the radius changes
this.r -= .5;
//control how much the degree of movement changes
this.p -= .05;
this.x += map(noise(this.offsetX), 0, 1, -this.p, this.p);
this.y += map(noise(this.offsetY), 0, 1, -this.p, this.p);
//controls how quickly the direction changes
this.offsetX += .1;
this.offsetY += .1;
}
}
show() {
//draws current layer on screen
strokeWeight(.5);
fill(map(noise(this.offsetX), 0, 1, 0, 255),0,map(noise(this.offsetY), 0, 1, 0, 255));
ellipse(this.x,this.y, this.r, this.r);
}
}