xxxxxxxxxx
var points = [];
var painting = false;
var strokeNumber = 0;
var maxProgress = 100; // used to limit spiral range
var maxStep = 3;
var r,g,b;
var colorChoice= 0
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
strokeWeight(0.3);
strokeCap(SQUARE);
}
function mousePressed() {
painting = true;
strokeNumber++;
newColor();
}
function mouseReleased() {
painting = false;
}
function newColor(){
var pallette = [
[210, 70, 50],
[245, 225, 50],
[50, 120, 170]
];
r=pallette[colorChoice][0];
g=pallette[colorChoice][1];
b=pallette[colorChoice][2];
colorChoice++;
if(colorChoice >= pallette.length) colorChoice=0;
}
function draw() {
if(painting){
var p1 = new Point(mouseX,mouseY,strokeNumber,r,g,b);
points.push(p1);
}
points.map(function(p){p.draw()});
}
class Point {
constructor(x,y,strokeNumber, r,g,b){
this.x=x;
this.y=y;
this.strokeNumber=strokeNumber;
this.spiral = new Spiral(x,y,120,r,g,b);
}
draw(){
this.spiral.draw();
}
}
// Spiral class
class Spiral {
constructor(ox,oy, alpha,r,g,b) {
this.setup(ox,oy, alpha,r,g,b);
}
setup(ox,oy, alpha){
this.r=r;
this.g=g;
this.b=b;
this.ox = ox;
this.oy = oy;
this.px = ox;
this.py = oy;
this.radius = 0;
this.a=0;
this.spirals = [];
this.alpha = alpha;
this.r_step = random(0.1,maxStep);
this.mod = maxProgress/5;
this.alpha_off = random(0,TWO_PI);
}
draw() {
if(this.a<maxProgress && this.alpha>0) {
var rad = map(this.a,0,maxProgress,0,2*TWO_PI)+this.alpha_off;
var x = this.ox+ cos(rad)*this.radius;
var y = this.oy + sin(rad)*this.radius;
this.alpha = min(this.alpha,map(this.a,0,maxProgress,255,0));
stroke(this.r,this.g,this.b,this.alpha);
line(this.px,this.py,x,y);
this.px=x;
this.py=y;
this.radius+=this.r_step;
this.a++;
if(this.a%this.mod==0) {
this.spirals.push(new Spiral(x,y, this.alpha));
}
}
else{
this.kill();
}
this.spirals.map(function(spiral){
spiral.draw();
})
}
kill() {
this.spirals.forEach(function(spiral){
spiral.kill();
})
this.spirals = [];
}
}