Mari Kubota- Project- 03- Dynamic-Drawing

sketch

/*  Mari Kubota
    49-104 Section D
    mkubota@andrew.cmu.edu 
    Assignment 3
*/
var x = 300;
var y = 300;
var diameter = 8;
var diffx = 0;
var diffy = 0;
var targetX = 300;
var targetY = 300;
var angle = 0;

function setup() {
    createCanvas(640, 480);
    
}
//following mouse
let value = 0;
function mouseMoved() {
    value = value + 5;
    if (value > 255) {
    value = 0;
}
}

function draw(){
    background (200-mouseY,220-mouseY,250);
//trees

    translate(100 - mouseX/2, 0);
    fill(0);
    rect (-100, 400,1050,80);

    rect (30,200,20,200);
    triangle (40,150,80,350,0,350);

    rect (180,200,20,200);
    triangle (190,150,100,350,280,350);

    rect (330,200,20,200);
    triangle (340,150,380,350,300,350);

    rect (530,200,20,200);
    triangle (530,100,640,350,440,350);

    rect (750,200,20,200);
    triangle (750,100,860,350,660,350);

//firefly
    fill(value-100, value, value-200);
    diffx = mouseX - x;
    diffy = mouseY - y;
    x = x + 0.1*diffx;
    y = y + 0.1*diffy;
    noStroke();
    ellipse(x, y, diameter, diameter);

}

In this project, I created a drawing of a firefly flying through the forest. The color of the sky, the movement of the trees, and the movement of the firefly are all controlled by the mouse.

Leave a Reply