hdw – Project 3 – Dynamic Drawing

Press any key to interact.

sketch

var x = 180
var r = 30;
var ellipseX;//ellipse's x position
var ellipseY;
var z = 0 //distance from center + opacity
var canBig = 1;

function setup() {
    background(255, 255, 255);
    createCanvas(640, 480);
    ellipseY = .5*height;
    ellipseX = .5*width;

}

function keyPressed() {
  if(canBig == 1){
    r=r+5;
    x=x-5;
    z=z+1;
  }
  if(r>320 & canBig == 1){
    canBig = 0;
    print(boundary);
  }
  if(canBig == 0){
    r=r-5;
    x=x+5;
    z=z-1;
  }
  if(r < 5 & canBig == 0){
    canBig = 1;
  }
}

function draw() {

    background(255, 255, 255, 200);
    noStroke();
    fill(0);

//middle flower
    //outer right
    fill(255,0,x,30+z*.15)
    ellipse(ellipseX+z, ellipseY, r, r);

    //white
    fill(255,255,255,30)
    ellipse(ellipseX, ellipseY, r, r);

    //outer left
    fill(255,0,x,30+z*.15)
    ellipse(ellipseX-z, ellipseY, r, r);

    //outer bottom
    fill(255,0,x,30+z*.15)
    ellipse(ellipseX, ellipseY+z, r, r);

    //white
    fill(255,255,255,30)
    ellipse(ellipseX, ellipseY, r, r);

    //outer top
    fill(255,0,x,30+z*.15)
    ellipse(ellipseX, ellipseY-z, r, r);

    //white center
    fill(255,255,255,5+.25*z)
    ellipse(ellipseX-0.7,ellipseY,2*z,2*z)
    ellipse(ellipseX+0.7,ellipseY,2*z,2*z)
    ellipse(ellipseX,ellipseY-0.7,2*z,2*z)
    ellipse(ellipseX,ellipseY+0.7,2*z,2*z)

    //center ellipses
    fill(255,0,x,30+z*.15)
    ellipse(ellipseX,ellipseY,2*z,z)
    ellipse(ellipseX,ellipseY,z,2*z)

    //magenta center
    fill(255,0,x+3*z,30+z*.15)
    ellipse(ellipseX,ellipseY,1.3*z,z)
    ellipse(ellipseX,ellipseY,z,1.3*z)

    //white center bud
    fill(255,255,255)
    ellipse(ellipseX,ellipseY,z*.1,z*.1)
  }

This week’s drawing is a blooming flower. I had originally wanted to do something more complicated but struggled with the code as is. I had Stella Han help me figure out how to create boundaries so that when it hit a certain height it would shrink again. I also had Shovik Mani help me figure out a bug in my code. Originally I had posted the function for keyPress inside the drawing function and couldn’t figure out why it wouldn’t draw.

Leave a Reply