fractalkitty looking for math? fractalkitty.com

100 days of code

trillium

#random#trig#interactive#animation#number-theory#symmetry#plants

genLeaftrilliumflower

function setup(){
  createCanvas(600,600);
  angleMode(DEGREES);
  background(60,60,60);
}
function draw(){
  background(60,60,60,0.5);
  strokeWeight(2)
  translate(width/2,width/2);
  trillium(1)
}

function genLeaf(s){
  fill(83, 140, 100);
  stroke(47, 74, 55);
  beginShape();
  for(let i=0;i<180;i++){
    y=i;
    x=s*sin(i);
    vertex(x,y);
  }
  for(let i=180;i>=0;i--){
    y=i;
    x=-s*sin(i);
    vertex(x,y);
  }
  endShape(CLOSE);
  beginShape();
  for(let i=0;i<180;i++){
    y=i;
    x=s/2*sin(i);
    vertex(x,y);
  }
  for(let i=180;i>=0;i--){
    y=i;
    x=-s/2*sin(i);
    vertex(x,y);
  }
  endShape(CLOSE);
  line(0,0,0,180)
}
function trillium(m){
  genLeaf(width/9);
  push();
  rotate(120);
  genLeaf(width/9);
  pop();
  push();
  rotate(-120);
  genLeaf(width/9);
  pop();
  p=int(random(0,2));
  if(p==1||m==1){
   flower(); 
  }
  
}

function mousePressed(){
  sc=random(0.1,0.8);//randomscale
  tr=random(-width/1.5,width/1.5);//randomtranslate
  rr=random(0,360);//randomrotate
  push()
  scale(sc,sc);;
  rotate(rr);
  translate(tr,tr);
  trillium()
  pop() 
}

function  flower(){
  noFill();
  strokeWeight(10);
  stroke(103, 158, 119)
  push()
  rotate(180)
  translate(-30,-60)
    arc(30,30,30,60,30,90);
  pop()
  strokeWeight(2);
  stroke(47, 74, 55);
  rotate(110)
  translate(62,7)
  fill(255);
  push()
  ellipse(20,4,80,7)
  ellipse(20,-4,80,7)
  ellipse(20,0,70,7)
  fill(103, 158, 119)
  beginShape()
  for(let i=0;i<360;i++){
    x=40*cos(i);
    y=10*sin(i)*sin(0.5*i)
    vertex(x,y);
  }
  endShape(CLOSE);
  pop()
}