fractalkitty looking for math? fractalkitty.com

100 days of code

Aspens_Day13

#random#trig#interactive#animation#nature#plants

treeAtreeWtreeArray

let f = 0,r=100,s=100;
let treeA = [];
let treeW = [];
let n = 0;
function setup() {
  createCanvas(500, 500);
  angleMode(DEGREES);
  fill(0);
  treeArray();
  
}

function draw() {
  background(205,245,255,10);
  fill(255,255,255,25)
  translate(width/2,width/2);
  noStroke();
  for (let i=0;i<n;i++){
    rect(treeA[i],-width/2,treeW[i],width)  
  }
  
  t = frameCount
  strokeWeight(1)
  stroke(250, 201, 5);
  a = r-90*sin(frameCount)
  b = s-50*cos(frameCount)
  for(let j=0;j<50;j++){
    fill(230+j, 101+j/2, 5,5)
    beginShape()
    for(let i=0;i<360;i++){
        x =a*sin(i)*sin(i)*sin(i)
        y =b*cos(i)-j+40
        vertex(x,y);
    }
    endShape(CLOSE);
    a = a-5;
    b = b-5;
  }
}

function treeArray(){
  treeA=[];
  treeW = [];
  n = int(random(3,20));
  for (let i = 0;i<n;i++){
    treeA[i] = random(-width/2,width/2)
    treeW[i] = random(5,30)
  }
}

function mousePressed(){
  treeArray();
  s = random(20,150)
  r = random(50,150)
}