xxxxxxxxxx
206
// Particle System Simulation
// The Nature of Code
// The Coding Train / Daniel Shiffman
// https://youtu.be/syR0klfncCk
// https://thecodingtrain.com/learning/nature-of-code/4.1-particle-system-simulation.html
// https://editor.p5js.org/codingtrain/sketches/QRzgzQLnQ
// More color, more fun
// More size, more pleasure
// More more, more more more.
// Modification by Joseph Gabriel
// instagram: https://www.instagram.com/youpjoseph/
// (come listen some music and watch strange stuff)
// youtube: https://www.youtube.com/channel/UCR5tmqqIXaWlfkx3smKczhw
let particles = [];
let numberMaxParticle = 300;
let particleAtOnce = 0;
let particleAtOnceMax = 5;
let grayScale = 0;
let particles1 = [];
let numberMaxParticle1 = 100;
let particleAtOnce1 = 0;
let particleAtOnceMax1 = 7;
// note to myself. Later I should use and array.
let particles2 = [];
let numberMaxParticle2 = 200;
let particleAtOnce2 = 0;
let particleAtOnceMax2 = 2;
// fancy useless BG for fancy not useless people
let BGColor = 230; let BGCmin = 210; let BGCmax = 255; let BGCmod = 0.2;
function setup() {
createCanvas(900, 700);
// Creating the Array
for (let i = 0; i < numberMaxParticle; i++)
{
particles.push(null);
}
// Copy and paste for more and more particles
for (let i = 0; i < numberMaxParticle1; i++)
{
particles1.push(null);
}
// Even more particles.
for (let i = 0; i < numberMaxParticle2; i++)
{
particles2.push(null);
}
}
function draw() {
/// Fancy BG ////
// background(BGColor,BGColor,240); //Choose what you pref between BG or rect
fill(BGColor,BGColor,240,80); // low opacity for funky stuff. High for no fun.
stroke(BGColor,BGColor,240,165);
rectMode(CORNER);
rect(0,0,width,height); //here
BGColor += BGCmod;
if (BGColor <= BGCmin || BGColor >= BGCmax)
{BGCmod *= -1;}
/// End Fancy BG ///
// Fancy pipeline //
// there's a leak, time to find a new engineer //
grayScale = 60;
rectMode(CENTER);
for (let i=0; i<10; i++)
{ fill(grayScale+i*10); stroke(grayScale+i*10);
rect (width/2, height/2,width/(8+i), height );
fill(grayScale-20+i*10); stroke(grayScale-20+i*10);
ellipse(width/2, 50,200-i*10,80-i*5);}
fill(50); stroke(50);
ellipse(width/2, 50,30,30);
fill(10); stroke(10);
ellipse(width/2, 50,22,22);
for (let i=0; i<10; i++)
{ fill(grayScale+i*10); stroke(grayScale+i*10);
rect (width/5, height/2,width/(8+i), height );
fill(grayScale-20+i*10); stroke(grayScale-20+i*10);
ellipse(width/5, 200,220-i*10,80-i*5);}
for (let i=0; i<10; i++)
{ fill(grayScale+i*10); stroke(grayScale+i*10);
rect (4*width/5, height/2,width/(8+i), height );
fill(grayScale-20+i*10); stroke(grayScale-20+i*10);
ellipse(4*width/5, 200,150-i*10,80-i*5);}
fill(50); stroke(50);
ellipse(width/2, 50,30,30);
ellipse(width/5, 200,30,30);
ellipse(4*width/5, 200,30,30);
fill(10); stroke(10);
ellipse(width/2, 50,22,22);
ellipse(width/5, 200,22,22);
ellipse(4*width/5, 200,22,22);
// End of (not so tbh) Fancy Pipeline //
// First particle Spot //
particleAtOnce = 0;
for (let i = 0; i < numberMaxParticle; i++)
{if (particles[i] == null )
{
if (particleAtOnce < particleAtOnceMax)
{particles[i] = new Particle(width/2, 50);
particleAtOnce +=1
}
else{break;}
}
}
for (let i = 0; i < numberMaxParticle; i++){
if (particles[i] != null){
let gravity = createVector(0, 0.2);
particles[i].applyForce(gravity);
particles[i].update();
particles[i].show();
if (particles[i].finished()) { particles[i] = null;}
}
}
// Second particle Spot //
particleAtOnce1 = 0;
for (let i = 0; i < numberMaxParticle1; i++)
{if (particles1[i] == null )
{
if (particleAtOnce1 < particleAtOnceMax1)
{particles1[i] = new Particle(width/5, 200);
particleAtOnce1 +=1
}
else{break;}
}
}
for (let i = 0; i < numberMaxParticle1; i++){
if (particles1[i] != null){
let gravity = createVector(0, 0.2);
particles1[i].applyForce(gravity);
particles1[i].update();
particles1[i].show();
if (particles1[i].finished()) { particles1[i] = null;}
}
}
// Last particle Spot //
particleAtOnce2 = 0;
for (let i = 0; i < numberMaxParticle2; i++)
{if (particles2[i] == null )
{
if (particleAtOnce2 < particleAtOnceMax2)
{particles2[i] = new Particle(4*width/5, 200);
particleAtOnce2 +=1
}
else{break;}
}
}
for (let i = 0; i < numberMaxParticle2; i++){
if (particles2[i] != null){
let gravity = createVector(0, 0.2);
particles2[i].applyForce(gravity);
particles2[i].update();
particles2[i].show();
if (particles2[i].finished()) { particles2[i] = null;}
}
}
}