Project-03-Dynamic-Drawing

sketchDownload
var colorx=20
function setup() {
  createCanvas(600, 450);
  max_distance = dist(0, 0, width, height);//the distance of the canvas
}

function draw() {
  //measure how far mouse if from the center of canvas
  let distanceFromCenter= dist(width/2,height/2,mouseX,mouseY);
  var colorx = distanceFromCenter;
  background(116,colorx,255);//the mouse as a component of the background's color
  //set the distance of each ellipse
  for (let x = 0; x <= width; x += 15) {
    for (let y = 0; y <= height; y += 15) {
      let size = dist(mouseX, mouseY, x, y);//size is decided by the mouse location 
      size = (size / max_distance) * 40;
      fill(22,255,colorx);//the mouse as a component of the ellipse's color
      noStroke();
      ellipse(x, y, size, size);
    }
  }
}

Move the mouse to update the sizes of ellipses in both horizontal and vertical direction. The color of ellipses and the background color of canvas also varies based on the mouse’s location.

Leave a Reply