xxxxxxxxxx
97
/*
----- Coding Tutorial by Patt Vira -----
Name: Slime Molds (Physarum)
Video Tutorial: https://youtu.be/VyXxSNcgDtg
References:
1. Algorithm by Jeff Jones: https://uwe-repository.worktribe.com/output/980579/characteristics-of-pattern-formation-and-evolution-in-approximations-of-physarum-transport-networks
Connect with Patt: @pattvira
https://www.pattvira.com/
----------------------------------------
*/
let molds = [];
let num = 4000;
let d;
let pg;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
d = pixelDensity();
for (let i = 0; i < num; i++) {
molds[i] = new Mold();
}
pg = createGraphics(500, 500);
}
function drawBase(){
pg.background(0)
pg.push();
pg.noFill();
pg.strokeWeight(5);
pg.stroke(255,20);
// pg.ellipse(width / 2, height / 2, 100, 100 * sin(frameCount * 1));
pg.pop();
pg.push();
pg.translate(width / 2, height / 2);
pg.stroke(255,20);
pg.strokeWeight(5);
pg.noFill();
// ellipse(0, 0, 40 * sin(frameCount * 2), 40 * cos(frameCount * 2));
// pg.ellipse(0,0,40+map(mouseX,0,width,0,250),40+map(mouseY,0,height,0,250))
pg.pop();
}
function draw() {
background(0, 10);
push();
noFill();
stroke(255);
strokeWeight(1)
fill(255)
// ellipse(width / 2, height / 2, 100, 100 );
textAlign(CENTER,CENTER)
textSize(width/2 )
// text("S L I M E",0,0,width,height)
text(key,0,0,width,height)
pop();
push();
translate(width / 2, height / 2);
stroke(255);
strokeWeight(10);
noFill();
// ellipse(0, 0, 40 * sin(frameCount * 2), 40 * cos(frameCount * 2));
// ellipse(mouseX,mouseY,40,40)
ellipse(0,0,mouseX,mouseY)
pop();
drawBase()
// image(pg,0,0)
loadPixels();
for (let i = 0; i < num; i++) {
if (key == "s") {
// If "s" key is pressed, molds stop moving
molds[i].stop = true;
updatePixels();
noLoop();
} else {
molds[i].stop = false;
}
molds[i].update();
molds[i].display();
}
}