xxxxxxxxxx
77
let canvas;
let svgcanvas;
let dg;
let psystems = [];
let startingParticles = 10;
let mouseInfluence = 1;
// ##################
// ###### Setup #####
// ##################
function setup() {
createCanvas(500, 500);
smooth();
frameRate(60);
init();
}
// ##################
// ###### Init ######
// ##################
function init(center=createVector(width/2,height/2)) {
noiseSeed(random(0, 100));
background(255);
// # Particle System Init
particles = [];
particles2 = [];
let radius = 20;
for (let i = 0; i < startingParticles; i ++) {
let posx = map(i, 0, startingParticles, width/4, width - width/4);
let posy = map(i, 0, startingParticles, height/4, height - height/4);
let pos = createVector(posx, posy);
let vel = p5.Vector.random2D();
particles[i] = new Node(pos, vel);
}
psystems[0] = new ParticleSystem(particles, color(0,20));
dg = new DifferentialGrowth(psystems);
frameCount = 0;
}
// #################
// ###### Draw #####
// #################
function draw() {
let endframe = 180;
// let
// background(255);
dg.run();
let pivot = 0.95;
if(frameCount < endframe * pivot){
dg.psystems[0].c = color(0,map(frameCount,0,endframe*pivot,1,7));
}
else{
dg.psystems[0].c = color(0,map(frameCount,endframe*pivot,endframe,7,1));
}
dg.psystems[0].drawClosedBezier();
if(frameCount > endframe){
noLoop();
}
}