xxxxxxxxxx
161
// important fixes & improvements:
// - slow the fuck down (towards the end). the start is good and then it should speed up but id like it to stabilize at a certain point not get exponentially fatter
// - along those lines im thinking maybe leaves should be stored differently so the stems can find their leaves. idk. like yea i could give them their hash but that's so convoluted
// - make it branch less & instead spread seeds after flowering
// - moving leaf angle? with how it works now theyd all just wanna get horizontal thoo
// honestly this is almost ready for like a trial launch with some minor fixes and testing:
// - add a simple interaction (dropping a seed?)
// - make flower colors exportable (do all of those first & then go over it w the outline or do them when we get to them?) (also get colored threads)
let stitchdist = 20; // stitch interpolation (in units of .1mm)
let embroideryScale = 4; // how much to scale the final embroidery from the p5 canvas size in units of .1mm (so if canvas is 500x500 and scale is 3 the embroidery will be 1500x1500 = 15x15cm. for reference embroidery windows are 10x10cm and 13x18cm)
let flowerFillAngularResolution = 0.07; //the flowers are filled like a fan with each step being this angle (in radians)
let filename = 'fgr7 sd' + stitchdist + ' sc' + embroideryScale + ' far' + flowerFillAngularResolution;
let stems = [];
let leaves = [];
let flowers = [];
let energy = 0;
let pEnergy = 0;
let stemcount = 0;
let pullstepdiv = 0.5; //how much to divide the steps taken each frame
let maxLeafSize = 20;
let stemLength = 20;
let horSpread = 10;
let leafPull = 0.10; //how strongly the leaves' sun search affects the position of the stem
let sunPenetration = 99; //how many leaves the sun goes down
let bloomSpd = 0.2; //how fast flowers go from 0 > all petals
// chance parameters
let rootChance = 0.1;
let leafChance = 0.008;
let growthFalloff = 0.9;
let branchingFalloff = 0.050;
let leavesFalloff = 0.5;
//these control the conditions for stems to DIE
let stemdeathMult = 5;
let stemdeathPow = 1.15;
// saving/downloading stuff:
let coords = [];
let paused = false;
let showData = true;
// stitchdist = stitchdist/embroideryScale;
function setup() {
createCanvas(500, 500);
colorMode(HSB);
csvExporter = new CSVExporter(filename, stitchdist, embroideryScale)
//saving stuff
createButton('pause/play').mousePressed(() => {paused = !paused }).position(20,height + 20);
createButton('download csv').mousePressed(() => {csvExporter.saveCSV()}).position(120,height + 20);
createButton('print stems').mousePressed(() => {print(stems); print(leaves)}).position(230,height + 20);
createButton('toggle data').mousePressed(() => {showData = !showData}).position(320,height + 20);
stems.push(new Stem(
50+random()*(width-100),
height-10,
[],
rootChance,
createVector(0,0.1),
true));
}
function draw() {
if(paused){
return
}
background(255);
noFill();
//do sunrays (currently vertical)
for(let x=0; x<width; x++){
let hitLeaves = [];
for(let i=leaves.length-1; i>=0; i--){
let lx1= stems[leaves[i].stemId].pos.x;
let lx2= lx1 + leaves[i].leafVector.x;
if(x>min(lx1,lx2) && x<max(lx1,lx2)){
hitLeaves.push({
index:i,
rayheight:stems[leaves[i].stemId].pos.y + leaves[i].leafVector.y,
leafmid: stems[leaves[i].stemId].pos.x + 0.5*leaves[i].leafVector.x
});
}
}
hitLeaves.sort((a,b) => {return a[1] - b[1]});
for(let i=0; i<sunPenetration && i<hitLeaves.length; i++){
const raystrength = 1/(i+1);
stroke(0,0,100 - i*2);
leaves[hitLeaves[i].index].sunRays[i].push(x);
leaves[hitLeaves[i].index].energy += raystrength
// leaves[hitLeaves[i].index].leafPull += raystrength * (x - hitLeaves[i].leafmid);
stems[leaves[hitLeaves[i].index].stemId].externalPull.add(
createVector(raystrength * (x - hitLeaves[i].leafmid) * leafPull, 0)
);
energy += raystrength;
line(x,height-10,x,hitLeaves[i].rayheight)
}
}
stroke(0)
for(let i=0;i<leaves.length;i++){
leaves[i].leafGrowth();
}
for(let i=0;i<stems.length;i++){
stems[i].grow();
}
for(let i=1;i<stems.length;i++){
stems[i].pushPull();
}
for(let i=0;i<stems.length;i++){
// point(stems[i].pos.x,stems[i].pos.y);
stems[i].drawLinks();
}
for(let i=0;i<leaves.length;i++){
leaves[i].drawLeaf();
}
for(let i=0;i<flowers.length;i++){
flowers[i].drawFlower();
}
line(20,height-10,width-20,height-10)
//max height for bucket line
line(20,height-10-800/embroideryScale,width-20,height-10-800/embroideryScale)
if(showData){
fill(0);
noStroke();
text('stems: ' + stemcount, 10, 15);
text('leaves: ' + leaves.length, 10, 25);
text('flowers: ' + flowers.length, 10, 35);
text('draw time: ' + int(deltaTime) + ' ms', 10, 45)
text('energy: ' + int(energy), 10, 60);
}
pEnergy = energy;
energy = 0;
}