Yingying Yan Project 3 Dynamic Drawing

sketch

/*
Yingying Yan
Waitlist for Section E
yingyiny@andrew.cmu.edu
Assignment-02-A
*/

//this code allow you do draw flowers! hold you mouse
//still and see what you get!

var k =4;
var R = 255;

//setup background and allow drawing to show
function setup() {
  createCanvas(480, 640);
  background(230);
}

function draw() {
  //the graphic of the lower right eraser box
  push();
  strokeWeight(0);
  fill(255);
  rect(340, 480, 140,160);
  pop();
  text("erase", 360,520);

  //color of the stokes of the flower
  stroke(R,100,100);
  // position of the drawing = position of the mouse
  translate(mouseX, mouseY);
  // the mouse controls how fast you can draw the flower
  //e.g. smaller x = draw faster
  var speed = frameCount / mouseX;
  // rose formula from Wekipedia and allow the computer
  //to draw the flower
  var x = cos(k*speed) * sin(speed);
  var y = cos(k*speed) * cos(speed); 
  // how big the drawing depends on the Y coordinate of the mouse
  scale(mouseY / 5, mouseY / 5);

  
  // controls the color of the drawing 0f the flower
  R -= .5;
  if (R < 0) {
    R = 255;
  }

  //the circles that draw the flower
  ellipse(x , y,.001,.001);

  //lower right corner of the canvas and clear the 
  //background of the canvas = erase
  if (mouseX > 340 & mouseY > 480) {
    background (230);
  }
}

I wanted to draw something geometrical, so I went online and search for a flower formula. This drawing is based on the rose formula. It took me forever to figure everything out but I am glad that I somehow finished it. I think this project is very interesting, and I wish I have more time and know more code for this.

Leave a Reply