xxxxxxxxxx
125
//rn its really stupid. itll just choose a direction to go in and then if it runs into no nutrients its like well guess ill die.
// implement some attraction/repulsion? or maybe tis fine like this. i kinda wanna emgroider this and see how it looks.
const xTiles = 15;
const yTiles = 15;
let toggleMap;
let layer1, layer2;
let nodes = []; //have all the nodes in an array since they cant all contain eachother
let nutrientMap = []; //2d array of which spaces are like available to crawl to
let nMapXSize, nMapYSize;
// default dna parameters:
const mutationMagnitude = 0.3;
//grow
const lengthToNode = 20;
const lengthToDie = 30;
const thornChance = 0.25;
const thornLength = 4;
const leafChance = 0;
const flowerChance = 0;
//runner
const distPerStep = 2;
const directionShift = 0.25;
//leaf
//flower
const drawNutrients = false;
const drawNodes = false;
function setup() {
createCanvas(580, 580);
background(255);
layer1 = createGraphics(width,height);
layer2 = createGraphics(width,height);
toggleMap = createButton('update nutrient map').mouseClicked(drawNutrientMap);
// fill nutrient map. could:
// -restrict this to a polygon/bitmap
// -generate an interesting layout for this
for(let x=0; x<xTiles;x++){
nutrientMap.push([]);
for(let y=0; y<yTiles;y++){
nutrientMap[x].push(1);
}
}
nMapXSize = width/xTiles;
nMapYSize = height/yTiles;
}
function draw() {
noFill();
stroke(0);
for(let i=0; i<nodes.length; i++){
if(nodes[i].isActive){
nodes[i].grow();
}
if(drawNutrients){
nodes[i].draw();
}
}
background(255);
image(layer1,0,0)
blendMode(MULTIPLY)
image(layer2,0,0)
blendMode(BLEND)
}
function mouseClicked(){
if(mouseX>width||mouseY>height){return}
nodes.push(new node(
nodes.length,
createVector(mouseX,mouseY),
// dna object:
{
mutationMagnitude: mutationMagnitude,
grow:{
lengthToNode: lengthToNode,
lengthToDie: lengthToDie,
thornChance: thornChance,
thornLength: thornLength,
leafChance: leafChance,
flowerChance: flowerChance
},
runner:{
distPerStep: distPerStep,
directionShift: directionShift
},
leaf:{
},
flower:{
}
},
[]
));
}
function drawNutrientMap(){
layer2.clear()
layer2.noStroke();
for(let x=0; x<xTiles;x++){
for(let y=0; y<yTiles;y++){
layer2.fill(255-nutrientMap[x][y]*50,255,255-nutrientMap[x][y]*50, 80);
layer2.rect(x*nMapXSize,y*nMapXSize,nMapXSize,nMapYSize);
}
}
}