xxxxxxxxxx
173
const brs = [[0,0],[15,15],[185,185],[200,200]] //since its always square brs i can just do like topleft1, topleft2 botright1, botright 2? this doesn't account for margins between stem & leave but i think i should automate those anyway
const leafMargin = 3;
let stbrs = [[brs[0][0] + leafMargin, brs[0][1] + leafMargin],
[brs[1][0] - leafMargin, brs[1][1] - leafMargin],
[brs[2][0] + leafMargin, brs[2][1] + leafMargin],
[brs[3][0] - leafMargin, brs[3][1] - leafMargin]]; //stem borders. really dumb way of defining this shit but ok
let bmp;
let pixelSize = 3;
let sos = [];
let sosno = 5;
let stemMode = 'noise' //'sos' for sum of sines or 'noise' for perlin noise
let animate = true;
let speed = 5;
function setup() {
createCanvas(brs[3][0]*pixelSize, brs[3][0]*pixelSize);
pixelDensity(1)
bmp = createGraphics(brs[3][0], brs[3][1]);
noStroke();
bmp.background(255);
bmp.loadPixels();
randomizeSoS();
marchStem();
findTiles();
fillTiles();
bmp.updatePixels();
}
function draw() {
// bmp.background(220);
bmp.loadPixels();
marchStem();
bmp.updatePixels();
// image(bmp,0,0,width,height)
// i can use this one
background(255);
fill(0)
for(let x=0; x< bmp.width; x++){
for(let y=0; y< bmp.height; y++){
if(bmp.pixels[y*bmp.width*4 + x*4] < 10){
rect(x*pixelSize,y*pixelSize, pixelSize, pixelSize);
}
}
}
// noLoop();
}
//----//
function marchStem(){
//this is cringe as hell rn
let t=0;
//top
let h = brs[1][1] - brs[0][1]
for(let i=0;i<brs[2][0]-brs[1][0];i++){
if(t>frameCount*speed&&animate){break;}
setPx(brs[1][0] + i,
brs[1][1] - int(h*stemHeight(t)));
t++;
}
//topright
for(let angle=1.5*PI; angle<2*PI; angle+= (0.5*PI)/30){
if(t>frameCount*speed&&animate){break;}
setPx(brs[2][0] + int( cos(angle) * h*stemHeight(t)) ,
brs[1][1] + int( sin(angle) * h*stemHeight(t)) );
t+=0.25;
}
//right
for(let i=0;i<brs[2][1]-brs[1][1];i++){
if(t>frameCount*speed&&animate){break;}
setPx(brs[2][0] + int(h*stemHeight(t)),
brs[1][1] + i);
t++;
}
//botright
for(let angle=0*PI; angle<0.5*PI; angle+= (0.5*PI)/30){
if(t>frameCount*speed&&animate){break;}
setPx(brs[2][0] + int( cos(angle) * h*stemHeight(t)) ,
brs[2][1] + int( sin(angle) * h*stemHeight(t)) );
t+=0.25;
}
//bottom
for(let i=brs[2][0]-brs[1][0];i>0;i--){
if(t>frameCount*speed&&animate){break;}
setPx(brs[1][0] + i,
brs[2][1] + int(h*stemHeight(t)));
t++;
}
//botleft
for(let angle=0.5*PI; angle<1.0*PI; angle+= (0.5*PI)/30){
if(t>frameCount*speed&&animate){break;}
setPx(brs[1][0] + int( cos(angle) * h*stemHeight(t)) ,
brs[2][1] + int( sin(angle) * h*stemHeight(t)) );
t+=0.25;
}
//left
for(let i=brs[2][1]-brs[1][1];i>0;i--){
if(t>frameCount*speed&&animate){break;}
setPx(brs[1][0] - int(h*stemHeight(t)),
brs[1][1] + i);
t++;
}
//topleft
for(let angle=1.0*PI; angle<1.5*PI; angle+= (0.5*PI)/30){
if(t>frameCount*speed&&animate){break;}
setPx(brs[1][0] + int( cos(angle) * h*stemHeight(t)) ,
brs[1][1] + int( sin(angle) * h*stemHeight(t)) );
t+=0.25;
}
}
function randomizeSoS(){
for(let i=0; i<sosno; i++){
}
}
function stemHeight(t){
if(stemMode=='noise'){
return noise(t*0.05) ;
}
if(stemMode=='sos'){
let value = 0;
for(let i=0;i<sosno;i++){
value+=(sin(t*sos[i].freq)+1)*sos[i].amp
}
return value;
}
}
function findTiles(){
}
function fillTiles(){
}
function setPx(x,y){
for(let i=0; i<3; i++){
bmp.pixels[y*bmp.width*4 + x*4 + i] = 0;
}
}