BrandonHyun-Project-03-Dynamic-Drawing

sketch

//Brandon Hyun
//15104 Section B
//bhyun1@andrew.cmu.edu
//Project-03

function setup() {
  createCanvas (640, 480);
}

function draw() {
//darkens the background as mouse gets closer (0,0) and lighten when the mouse gets closer to (640,0)
  background(mouseX,mouseY);
  fill(0);
  noStroke();

//left upper corner chaos circle
  //setting cordinates of where the circles are going to be drawn.
  randomXlocation = random (width/2 +1);
  randomYlocation = random (height/2 +1);
  //drawing the circles with the cordinates and the size of the circle.
  ellipse (randomXlocation, randomYlocation, 50,50);


//right lower corner chaos circle
  //setting cordinates of where the circles are going to be drawn.
  randomXlocation = width/2+ random (width/2 +1);
  randomYlocation = height/2+ random (height/2 +1);
  //drawing the circles with the cordinates and the size of the circle.
  ellipse (randomXlocation, randomYlocation, 50,50);

}

For this project, I wanted to create something that had a simple concept but complicated visuals. While I was working, I wanted to express the emotion of hecticness that could only be hidden by shadows.

When I was working on this, I had a hard time in the beginning because I wasn’t really sure what variables I needed this code to work.

I think I figured it out.

 

abradbur-Project-03-Dynamic Drawing

Dynamic Drawing

function setup() {
    createCanvas(640, 480);
    
}

function draw() {
    background(33, 32, 29);

    //clouds follow or pass by the mouse
    var cloudcover = -mouseX + 640;
    var cloudsize =  mouseY * 0.25;
    fill(140, 138, 146);
    noStroke();
    ellipse(mouseX, 100, cloudsize, cloudsize);
    ellipse(mouseX + 20, 150, cloudsize, cloudsize);
    ellipse(mouseX + 5, 200, cloudsize, cloudsize);
    ellipse(mouseX - 50, 207, cloudsize, cloudsize);
    ellipse(mouseX + 100, 200, cloudsize, cloudsize);
    ellipse(mouseX -15, 200, cloudsize, cloudsize);
    ellipse(cloudcover, 350, cloudsize, cloudsize);
    ellipse(cloudcover + 50, 340, cloudsize, cloudsize);
    ellipse(cloudcover - 8, 330, cloudsize, cloudsize);
    ellipse(cloudcover + 10, 315, cloudsize, cloudsize);
    ellipse(cloudcover - 10, 290, cloudsize, cloudsize);
    ellipse(cloudcover - 45, 350, cloudsize, cloudsize);
    
    //stage
    fill(0);
    rect(0, 420, 640, 60);
    rect(40, 360, 560, 60);

    //lights
    fill(255);
    quad(45, 480, 55, 420, 105, 450, 85, 480);
    quad(555, 480, 525, 450, 575, 420, 595, 480);
    quad(45, 0, 55, 60, 105, 30, 85, 0);
    quad(555, 0, 525, 30, 575, 60, 595, 0);

    //Edward
    fill(0);
    //head
    triangle( 80, 200, 95, 230, 110, 200);
    triangle( 80, 200, 75, 190, 85, 200);
    triangle( 105, 200, 110, 190, 110, 200);
    triangle( 75, 190, 70, 215, 100, 200);
    //shoulders
    triangle( 65, 230, 95, 275, 125, 230);
    //waist
    quad( 85, 260, 90, 280, 100, 280, 105, 260);
    //flair
    quad( 90, 280, 75, 310, 95, 330, 105, 260);
    //legs
    triangle(100, 255, 103, 360, 105, 260);
    triangle(85, 290, 88, 360, 90, 280);
    //arms
    triangle(75, 240, 70, 280, 77, 240);
    triangle(70, 280, 90, 300, 70, 280);
    triangle(120, 230, 135, 200, 125, 230);
    triangle(135, 200, 150, 190, 136, 200);

    // depending on the position of the mouse
    //different lights will turn on
    if ((mouseX < 320) & (mouseY > 240)){
        fill(252, 18, 58, 51);
        quad( 55, 420, 320, 0, 105, 0, 105, 450);
    } if((mouseX > 320) & (mouseY > 240)){
        fill(254,205,68,51);
        quad( 525, 450, 70, 0, 575, 0, 575, 420);
    } if((mouseX <320) & (mouseY < 240)){
        fill(252, 51, 170, 51);
        quad (55, 60, 250, 480, 270, 480, 105, 30);
    } else{
        fill( 52, 253, 47, 51);
        quad (525, 30, 200, 480, 260, 480, 575, 60);
    }

    // if mouse in canvas, reveal text
    textSize(40);
    var W = "Welcome to Wonderland!"
    if((mouseX < 640) & (mouseX > 0) & (mouseY > 0) & (mouseY < 480)){
        fill(162, 16, 110);
        } else {
            fill(33, 32, 29);
        }
    text(W, 100, 35, 500, 200);
    
    //Wheel of Misfortune
    //move origin to the center
    translate(320, 240);
    rotate(radians(2 * frameCount));
    //first wheel slice
    fill(162, 16, 110);
    arc(0, 0, 300, 300, PI + 3 * QUARTER_PI, TWO_PI);
    //second
    fill(243, 226, 53);
    arc(0, 0, 300, 300, PI + 2 * QUARTER_PI, 7 * PI/4);
    //third 
    fill(253, 99, 169);
    arc(0, 0, 300, 300, PI + QUARTER_PI, 3 * PI/2);
    //fourth
    fill(37, 213, 161);
    arc(0, 0, 300, 300, PI, 5 * PI/4);
    //fifth
    fill(37, 213, 161);
    arc(0, 0, 300, 300, 0, PI/4);
    //sixth
    fill(162, 16, 110);
    arc(0, 0, 300, 300, PI/4, PI/2);
    //seventh
    fill(243, 226, 53);
    arc(0, 0, 300, 300, PI/2, 3 * PI/4);
    //eighth 
    fill(253, 99, 169);
    arc(0, 0, 300, 300, 3 * PI/4, PI);

}

I was really inspired by the description of a dungeon in one of my favorite podcasts, “The Adventure Zone”, and I thought this would be a really fun project to try to realize that scene in simple shapes. I did my best to use a whimsical color scheme and incorporate a lot of motion. I think that out of what we’ve done so far this is the project I’m most proud of, and the one I’ve spent the most time on.

cduong-Project-03-Dynamic-Drawing

project03

/*
Name: Colleen Duong
Lab Section: D
Email: cduong@andrew.cmu.edu
Project-03 Dynamic Drawing
*/

var sunsize = 50;
var BR = 6; //Sky R color
var BG = 6; //Sky G color
var BB = 50; //Sky B color
var BRG = 25; //Ground R color
var BGG = 62; //Ground G color
var BBG = 16; //Ground B color
var SR = 255 //Sun R color
var SG = 255 //Sun G color
var SB = 255 //Sun B color
var sproutstemh = 610; //sprout stem height


function setup() {
    createCanvas(640, 480);
}

function draw() {
  background(BR, BG, BB);
  noStroke();

//Sky   Start
  //Setting the boundaries for the morning colors to appear
  if ((mouseX >= 640) & (mouseX <= 640)){
      mouseX = 640;
  }

  //Setting the boundaries for the night colors to appear
  //background nighttime colors (6, 6, 50)
  //background daytime colors (187, 235, 235)
  if ((mouseX > 0) & (mouseX < 400)){
    BR = mouseX*((187-6)/400) + 6;
  	BG = mouseX*((235-6)/400) + 6;
  	BB = mouseX*((235-50)/400) + 50;
    }
//Sky   End


//The Sun   Start
  fill(SR, SG, SB);

  //Setting a constraint so the sun cannot leave the canvas
  var constrainy = constrain(mouseY, 0, 300);
  var constrainx = constrain(mouseX, 0, 600);

  //Creating the sun shape
  ellipse(constrainx, constrainy, sunsize, sunsize); //The circle

  //Setting the boundaries for sun to change to morning color
  if ((mouseX > 640) & (mouseX < 640)){
      mouseX = 640;
  }

  //Setting the boundaries for sun to change to night color
  //Daytime Grass (255, 199, 5)
  //Nighttime Grass (255, 255, 255)
  if ((mouseX > 0) & (mouseX < 640)){
    SR = mouseX*((255-255)/640) + 255;
    SG = mouseX*((199-255)/640) + 255;
    SB = mouseX*((5-255)/640) + 255;
    }

  //Changing the Sun Size depending on Location
  sunsize = (0.5*(mouseX+mouseY)); 
//The Sun   End


//Grass   Start
  //Ground
  fill(BRG, BGG, BBG);
  rect(0, 400, 680, 100);

  //Setting the boundaries for the morning grass colors to appear
  if ((mouseX > 640) & (mouseX < 640)){
      mouseX = 640;
  }

  //Setting the boundaries for the night grass colors to appear
  //Daytime Grass (78, 174, 55)
  //Nighttime Grass (25, 62, 16)
  if ((mouseX > 0) & (mouseX < 640)){
    BRG = mouseX*((78-25)/640) + 25;
    BGG = mouseX*((174-62)/640) + 62;
    BBG = mouseX*((55-16)/640) + 16;
    }
//Grass   End

//Stems Start
  //Make stems grow as the arrow moves across the x-axis
  push();
  translate(35, -mouseX+200); //Make the stems grow upward
  sproutS = rect(35, sproutstemh, 10, 300, 10);
  sprout2S = rect(105, sproutstemh, 10, 300, 10);
  sprout3S = rect(175, sproutstemh, 10, 300, 10);
  sprout4S = rect(245, sproutstemh, 10, 300, 10);
  sprout5S = rect(315, sproutstemh, 10, 300, 10);
  sprout6S = rect(385, sproutstemh, 10, 300, 10);
  sprout7S = rect(455, sproutstemh, 10, 300, 10);
  sprout8S = rect(525, sproutstemh, 10, 300, 10);
  pop();

  //Leaves that pop out of the stem depending on where your mouse is on the x axis
  //Key: SproutL is the first stem's sprouts, Sprout 2L is the second stem's sprouts, etc
  //Key2: SproutL2 is the second leaf from the ground, etc.
  if ((mouseX > 450)){ //First to pop up
    sproutL = ellipse(60, 380, 25, 20);
    sprout3L = ellipse(200, 370, 25, 20);
    sprout7L = ellipse(480, 360, 25, 20);
  }
  if ((mouseX > 480)){ //Second to pop up
    sprout2L = ellipse(130, 385, 25, 20);
    sprout4L = ellipse(300, 360, 25, 20);
    sprout6L = ellipse(410, 370, 25, 20);
    sproutL2 = ellipse(90, 320, 25, 20);
    sprout3L2 = ellipse(230, 320, 25, 20);
    sprout7L2 = ellipse(510, 330, 25, 20);
  }
  if ((mouseX > 520)){ //Third to pop up
    sprout5L = ellipse(340, 355, 25, 20);
    sprout8L = ellipse(580, 350, 25, 20);
    sprout2L2 = ellipse(160, 325, 25, 20);
    sprout3L3 = ellipse(200, 300, 25, 20);
    sprout4L2 = ellipse(270, 310, 25, 20);
    sprout6L2 = ellipse(440, 320, 25, 20);
    sprout7L3 = ellipse(480, 290, 25, 20);
  }
  if ((mouseX > 540)){ //Fourth to pop up
    sproutL3 = ellipse(60, 260, 25, 20);
    sprout2L3 = ellipse(130, 280, 25, 20);
    sprout3L4 = ellipse(230, 275, 25, 20);
    sprout4L3 = ellipse(300, 255, 25, 20);
    sprout5L2 = ellipse(370, 260, 25, 20);
    sprout6L3 = ellipse(410, 260, 25, 20);
    sprout7L4 = ellipse(510, 250, 25, 20);
    sprout8L2 = ellipse(550, 260, 25, 20);
  }

//Last to pop up: Flowers   Start
  if ((mouseX > 575)){ //Petal 1
    fill(247, 154, 185); //Pink Color
    ellipse(50, 200, 40, 40); //Pink

    fill(255, 180, 0); //Orange Color
    ellipse(190, 200, 40, 40); //Orange

    fill(191, 63, 63); //Red Color
    ellipse(120, 200, 40, 40); //Red

    fill(31, 144, 0); //Green Color
    ellipse(330, 200, 40, 40); //Green

    fill(255, 234, 0); //Yellow Color
    ellipse(260, 200, 40, 40); //Yellow

    fill(136, 73, 189); //Purple Color
    ellipse(470, 200, 40, 40); //Purple

    fill(17, 46, 173); //Blue Color
    ellipse(400, 200, 40, 40); //Blue

    fill(70, 63, 69); //Black Color
    ellipse(540, 200, 40, 40); //Black
}

  if ((mouseX > 565)){ //Petal 2
    fill(247, 154, 185); //Pink Color
    ellipse(100, 200, 40, 40); //Pink

    fill(255, 180, 0); //Orange Color
    ellipse(240, 200, 40, 40); //Orange

    fill(191, 63, 63); //Red Color
    ellipse(170, 200, 40, 40); //Red

    fill(31, 144, 0); //Green Color
    ellipse(380, 200, 40, 40); //Green

    fill(255, 234, 0); //Yellow Color
    ellipse(310, 200, 40, 40); //Yellow

    fill(136, 73, 189); //Purple Color
    ellipse(520, 200, 40, 40); //Purple

    fill(17, 46, 173); //Blue Color
    ellipse(450, 200, 40, 40); //Blue

    fill(70, 63, 69); //Black Color
    ellipse(590, 200, 40, 40); //Black
}

if ((mouseX > 570)){ //Petal 3
    fill(247, 154, 185); //Pink Color
    ellipse(75, 180, 40, 40); //Pink

    fill(255, 180, 0); //Orange Color
    ellipse(215, 180, 40, 40); //Orange

    fill(191, 63, 63); //Red Color
    ellipse(145, 180, 40, 40); //Red

    fill(31, 144, 0); //Green Color
    ellipse(355, 180, 40, 40); //Green

    fill(255, 234, 0); //Yellow Color
    ellipse(285, 180, 40, 40); //Yellow

    fill(136, 73, 189); //Purple Color
    ellipse(495, 180, 40, 40); //Purple

    fill(17, 46, 173); //Blue Color
    ellipse(425, 180, 40, 40); //Blue

    fill(70, 63, 69); //Black Color
    ellipse(565, 180, 40, 40); //Black
}

if ((mouseX > 555)){ //Petal 4
    fill(247, 154, 185); //Pink Color
    ellipse(60, 225, 40, 40); //Pink

    fill(255, 180, 0); //Orange Color
    ellipse(200, 225, 40, 40); //Orange

    fill(191, 63, 63); //Red Color
    ellipse(130, 225, 40, 40); //Red

    fill(31, 144, 0); //Green Color
    ellipse(340, 225, 40, 40); //Green

    fill(255, 234, 0); //Yellow Color
    ellipse(270, 225, 40, 40); //Yellow

    fill(136, 73, 189); //Purple Color
    ellipse(480, 225, 40, 40); //Purple

    fill(17, 46, 173); //Blue Color
    ellipse(410, 225, 40, 40); //Blue

    fill(70, 63, 69); //Black Color
    ellipse(550, 225, 40, 40); //Black
}

if ((mouseX > 560)){ //Petal 5
    fill(247, 154, 185); //Pink Color
    ellipse(90, 225, 40, 40); //Pink

    fill(255, 180, 0); //Orange Color
    ellipse(230, 225, 40, 40); //Orange

    fill(191, 63, 63); //Red Color
    ellipse(160, 225, 40, 40); //Red

    fill(31, 144, 0); //Green Color
    ellipse(370, 225, 40, 40); //Green

    fill(255, 234, 0); //Yellow Color
    ellipse(300, 225, 40, 40); //Yellow

    fill(136, 73, 189); //Purple Color
    ellipse(510, 225, 40, 40); //Purple

    fill(17, 46, 173); //Blue Color
    ellipse(440, 225, 40, 40); //Blue

    fill(70, 63, 69); //Black Color
    ellipse(580, 225, 40, 40); //Black
}

  if ((mouseX > 550)){ //Flower Centers
    fill(211, 86, 115); //Dark Pink Center
    ellipse(75, 205, 25, 25);

    fill(194, 139, 7); //Dark Orange Center
    ellipse(215, 205, 25, 25);

    fill(160, 38, 38); //Dark Red Center
    ellipse(145, 205, 25, 25);

    fill(21, 99, 0); //Dark Green Center
    ellipse(355, 205, 25, 25);

    fill(220, 202, 0); //Dark Yellow Center
    ellipse(285, 205, 25, 25);

    fill(96, 39, 144); //Dark Purple Center
    ellipse(495, 205, 25, 25);

    fill(8, 32, 132); //Dark Blue Center
    ellipse(425, 205, 25, 25);

    fill(33, 30, 31); //Dark Black Center
    ellipse(565, 205, 25, 25);
  }
//Stems   End
}

1) You can only see the flowers fully grow if you’re looking at the code on a full 640×480 canvas

This project was really difficult for me because there were so many options that I could have done and it was hard for me to really decide what I wanted to code for this project.

These were some initial sketches I did of possible things that I could have attempted to code (unsure if the drawings even make sense), but I decided to try and stick with my theme that I had in my last project, which is the idea of using sprouts. I wanted to try to make the sprouts look like they were growing depending on where the sun is (on the x-axis) and I wanted to change the color of the sky, grass, and the sun depending on where the mouse is (on the x-axis) and also allowing the sun to grow smaller and bigger depending on where it is on the canvas.

It was difficult for me to try and figure out how to code certain things, especially the growing stems for the plants because I tried to do that for my last project. I figured out a way to do it, but I’m sure there is a more efficient way to do it that I want to try and figure out next time.

Another aspect that I wanted to incorporate in this project was to try and draw different flowers like sunflowers, but I found it too difficult to do sadly. Maybe next time.

manuelr – project03 – curtains

sketch

var posx = 20;
var posy = 20;
var posyb = 20;
var posx1 =20;
var posy1 = 20;
var dirX = 1;
var diam = 30;
var falling = 1.1;
var diam1 =30;

function setup() {
    createCanvas(600, 600);

}

function draw() {
    background (157,156,201);

    for (var x = 5; x < width; x = x+50){
        for (var y = 5; y < height; y = y+50){
            push();
            translate(x, y);
            fill(255,255,102); //yellow            
            ellipse(posx1,posy,diam,diam);
            pop();
        }   
    } 
    //
    if (mouseX > width/2) {
        for (var x = diam; x < width; x = x+50){
            for (var y = diam; y < height; y = y+50){
                push();
                translate(x, y);
                fill(204,255,153);  //green         
                ellipse(-posx1,posy1,diam1,diam1);
                diam1 += .0001;
                pop();
            }   
        } 
    }
    //bluish
    if (mouseX < width/2) {
        for (var x = diam; x < width; x = x+50){
            for (var y = diam; y < height; y = y+50){
                push();
                posyb += falling*0.01;
                posy1+= falling*0.01*-1;
                translate(x, y);
                fill(153,255,255);           
                ellipse(posy1,posy1,diam,diam);
                pop();
            }   
        } 
    }
    // pink
    if (mouseY > height/2) {
        for (var x = diam; x < width; x = x+50){
            for (var y = diam; y < height; y = y+50){
                push();
                posyb += falling*0.01;
                posy1+= falling*0.01*-1;
                translate(x, y);
                fill(255,102,255);           
                ellipse(posx,posyb,diam1,diam1);
                pop();
            }   
        } 
    }
    // orange
    if (mouseY < height/2) {
        for (var x = diam; x < width; x = x+50){
            for (var y = diam; y < height; y = y+50){
                push();
                posyb += falling*0.01*-1;
                posx1 += falling*0.01*1;
                translate(x, y);
                fill(224,96,92);           
                ellipse(posx,posyb,diam,diam);
                pop();
            }   
        } 
    }
}




I wanted to create a curtain of balls that slide through the canvas in an uncomfortable way depending on the direction of the mouse. Are you able to make them dissapear? What if you wait for a little bit?

Project-03

sketch

//Cora Hickoff
//Section D 
//chickoff@andrew.cmu.edu
//Project-03

function setup() {
    createCanvas(640, 480);
    rectMode(CENTER);
    frameRate(10);
}

function draw() {

    //mouseX controls the degrees
    var deg = mouseX;
    var rad = radians(deg);

    background(144,180,180);
    //make background change color
    //when mouse midway point of canvas width
    if (mouseX > (width / 2)) {
        background (232,180,180);
    }

    //small gold circle
    fill(255, 214, 169);
    noStroke();
    //restrict mouseX to 0-135
    var m = max(min(mouseX, 40), 135);
    var size = m * 120.0 / 400.0;
    ellipse(10 + m * 190.0 / 400.0, 200.0, size, size);

    //white circle
    fill(255);
    noStroke();
    //restrict mouseX to 0-400
    var m = max(min(mouseX, 400), 35);
    var size = m * 120.0 / 300.0;
    ellipse(10 + m * 190.0 / 400.0, 200.0, size, size);

    //big gold circle
    fill(255, 214, 169);
    noStroke();
    //restrict mouseX to 0-335
    //mouseX, 920 causes mouseX 
    //to control bid golden circle
    //once white circle overlaps
    var m = max(min(mouseX, 920), 335);
    var size = m * 120.0 / 400.0;
    ellipse(10 + m * 190.0 / 400.0, 200.0, size, size);

    //peach square
    fill(240,140,130);
    //as mouseX moves across
    //canvas, its degrees determine
    //the square's rotation
    rotate(rad);
    rect(300 + m * 190.0 / 400.0, 200.0, size, size);

}

In this project, I wanted to make a shape rotate based on the mouse’s x coordinates. By adding the other ellipses, I realized that the end result made them all look like planets in a solar system and the rectangle looked as though it were orbiting them.

yoonyouk-project03-dynamicdrawing

sketch_project03

//Yoon Young Kim
//Section E
//yoonyouk@andrew.cmu.edu
//Project-03

function setup() {
    createCanvas(640, 480);
    background(256);

}

function draw() {

    angleMode(DEGREES);

    var a = mouseX
    var b = mouseY

    //underwater background change
    //This will change the color values as the mouse moves down
    //Water will change into a darker blue
    var Rx = map(b,0,height,116,20);
    var Gx = map(b,0,height,188,21);
    var Bx = map(b,0,height,252,138);

    noStroke();
    fill(Rx, Gx, Bx);
    rect(0, 0, 640, 480);

    
    //SCUBA DIVER
    // The tiny figure will follow the mouse
    
    //head
    noStroke();
    fill(13, 0, 69);
    ellipseMode(CENTER);
    ellipse(a, b+10, 40, 40);
   
   //eyes
    stroke(247, 209, 9);
    strokeWeight(3);
    fill(224, 162, 115);
    rect(a-15, b+5, 30, 15);

    //eyeballs
    noStroke();
    fill(0);
    ellipse(a-5, b+15, 5, 5);
    ellipse(a+5, b+15, 5, 5);


    //body
    noStroke();
    fill(13, 0 , 69);  
    rect(a-20, b+25, 40, 60);


    //SCUBA DIVER ARMS/LEGS

    //left hand
    //left hands moves from 80 below the mouse to 5 above the mouse
    var lefthand = map(b, 0, height, b+80, b-5);

    stroke(13, 0, 69);
    strokeWeight(5);
    line(a-15, b+40, a-50, lefthand);

    //moving the right hand
    //right hands moves from 80 below the mouse to 5 above the mous
    var righthand = map(b, 0, height, b+80, b-5);

    stroke(13, 0, 69);
    strokeWeight(5);
    line(a+15, b+40, a+50, righthand);



    //left leg

    //moving left foot in a rotating manner using mapping
    var leftfootX = map(b, 0, height, a-15, a-70);
    var leftfootY = map(b, 0, height, b+140, b+60);
    stroke(13, 0, 69);
    strokeWeight(5);
    line(a-15, b+80, leftfootX, leftfootY);


    //right leg
    //moving right foot in a rotating manner using mapping
    var rightfootX = map(b, 0, height, a+15, a+70);
    var rightfootY = map(b, 0, height, b+140, b+60);
    stroke(13, 0, 69);
    strokeWeight(5);
    line(a+15, b+80, rightfootX, rightfootY);

    //SMILE
    noFill();
    if (b < 100){
    stroke(247, 72, 79);
    strokeWeight(2);
    arc(a, b+20, 5, 5, 0, 180);
    }

    if (b >= 100 & b < 300){
    stroke(247, 72, 79);
    strokeWeight(2);
    ellipse(a, b+20, 5, 5);
    }
    
    if (b >= 300 & b <= 480){
    stroke(247, 72, 79);
    strokeWeight(2);
    arc(a, b+20, 5, 5, 180, 360);
    }

    //BUBBLES
    //bubble1

    //bubble location
    var bubbleX = a+40;
    var bubbleY = b-20;

    //expanding the bubble sizes as the mouse moves up and down
    var bubbleSize = map(b, 0, height, 2,25);
    noStroke();
    fill(160, 222, 255);
    ellipse(bubbleX, bubbleY, bubbleSize, bubbleSize);

    //bubble2
    var bubbleX = a+60;
    var bubbleY = b-50;
    var bubbleSize = map(b,0,height,4, 40);
    noStroke();
    fill(160, 222, 255);
    ellipse(bubbleX, bubbleY, bubbleSize, bubbleSize);
   

}

 

I wanted to create a small animated cartoon drawing for this assignment and thought a scuba diver as the subject would be appropriate. Because scuba divers swim in deep depths, I explored changing the image elements dependent on the mouse moving up or down, mouseY. This project allowed me to explore change in color, size, and position of the different components to complete a cohesive dynamic drawing.

rfarn Project-03

For this project, I struggled with figuring out where to start with my coding. The assignment was fairly open and creative, so it was hard to come up with an idea on the spot for what I wanted to do. I played around with stationary shapes and then incorporated some transformations and movement to create a dynamic drawing.

sketch

var w1 = 40;
var h1 = 40;
var w2 = 40;
var h2 = 40;
var w3 = 40;
var h3 = 40;
var w4 = 40;
var h4 = 40;
var R = 105;

function setup() {
    createCanvas(640, 480);
}

function draw() {
    background(R, 98, 109);
    noStroke();
    
    
    if(mouseX < 640  & mouseX > 0){ //changing background color
        R = mouseX * (1/4);
    }

    fill(232, 199, 222); //top circle
    ellipse(width/2, height/4, w1, h1);
    if(mouseX > width/2 - w1/2 & mouseX < width/2 + w1/2 && 
       mouseY > height/4 - h1/2 && mouseY < height/4 + h1/2 && 
       dist(mouseX, mouseY, width/2, height/4) < w1/2) { //when mouse is in border of circle
        w1 += 5;//grows bigger
        h1 += 5;
    } else { if(w1 > 40 & h1 > 40){ //shrinks back down to 40 x 40
        w1 -= 5;
        h1 -= 5;
        }
    }

    fill(217, 189, 197); //right circle
    ellipse(width * (3/4), height/2, w2, h2);
    if(mouseX > width * (3/4) - w2/2 & mouseX < width * (3/4) + w2/2 && 
       mouseY > height/2 - h2/2 && mouseY < height/2 + h2/2 && 
       dist(mouseX, mouseY, width * (3/4), height/2) < w2/2) { //when mouse is in border of circle
        w2 += 5; //grows bigger
        h2 += 5;
    } else { if(w2 > 40 & h2 > 40){ //shrinks back down to 40 x 40
        w2 -= 5;
        h2 -= 5;
        }
    }

    fill(203, 190, 179); //bottom circle
    ellipse(width/2, height * (3/4), w3, h3);
    if(mouseX > width/2 - w3/2 & mouseX < width/2 + w3/2 && 
       mouseY > height * (3/4) - h3/2 && mouseY < height * (3/4) + h3/2 && 
       dist(mouseX, mouseY, width/2, height * (3/4)) < w3/2) { //when mouse is in border of circle
        w3 += 5; //grows bigger
        h3 += 5;
    } else {if(w3 > 40 & h3 > 40){ //shrinks back down to 40 x 40
        w3 -= 5;
        h3 -= 5;
        }
    }

    fill(188, 175, 156); //left circle
    ellipse(width/4, height/2, w4, h4);
    if(mouseX > width/4 - w4/2 & mouseX < width/4 + w4/2 && 
       mouseY > height/2 - h4/2 && mouseY < height/2 + h4/2 && 
       dist(mouseX, mouseY, width/4, height/2) < w4/2) { //when mouse is in border of circle
        w4 += 5; //grows bigger
        h4 += 5;
    } else { if(w4 > 40 & h4 > 40){ //shrinks back down to 40 x 40
        w4 -= 5;
        h4 -= 5;
        }
    }

    fill(255); //white dots
    ellipse((mouseX - width/5) * 2, (mouseY - height/5) * 2, 15, 15);
    ellipse((mouseX - width/5) * 2, (mouseY + height/5) * 2, 15, 15);
    ellipse((mouseX + width/5) * 2, (mouseY - height/5) * 2, 15, 15);
    ellipse((mouseX + width/5) * 2, (mouseY + height/5) * 2, 15, 15);
    

}

mecha-project03-dynamic-drawing

sketch

//alters
//position of eyebrows, eyes, blush, mouth, bird, face
//color of blush, face, bird
//size of blush, face

var colorR = 0;
var colorG = 0;
var colorB = 0;
var topY = 70;
var bottomY = 640-70;
var ellipseSize = 140;
var angle = 0;

function setup() {
    createCanvas(480,640);
    angleMode(DEGREES);
}

function draw() {
    background(210-colorR,240-colorG,240);
    noStroke();

    angle+=1;
    //rotating sun moon thing
        push();
        translate(240,300);
        rotate(angle);
        noStroke();
        fill(255);
        ellipse(-40,-250,40,40)
        pop();
    
    fill(210-colorR,240-colorG,240);
    noStroke();
    rect(0,260,600,600);

    //constrain mouseY so ball doesn't go past top and bottom part of canvas
    var yConstrain = constrain(mouseY, topY, bottomY);
    var ellipseSize = constrain(mouseY-400, 140,220);
    var ellipseSize2 = constrain(mouseY+400,100,140);

    //little bird friend
    //beak
    noStroke();
    fill(230+colorR,180+colorG,130+colorB);
    triangle(230,yConstrain-145,190,yConstrain-120,240,yConstrain-110);
    noFill();
    stroke(80);
    line(240,yConstrain-100,240,yConstrain)
    line(230,yConstrain-100,230,yConstrain)
    noStroke();
    fill(255,160+colorR,160+colorR);
    arc(238,yConstrain-110,50,50,30,220,CHORD);
    ellipse(220,yConstrain-130,40,40);
    //wing
    fill(255,140+colorR,140+colorR);
    arc(250,yConstrain-110,40,40,30,220,CHORD);

    //face
    noStroke();
    fill(230+colorR,180+colorG,130+colorB);
    ellipse(240,yConstrain,ellipseSize,ellipseSize2);

    //eyebrows
    noFill();
    strokeWeight(2);
    stroke(80);
    arc(205, yConstrain-10,40,40,30,70,OPEN);
    arc(270, yConstrain-10,40,40,-270,-230,OPEN);
    
    //eyes and mouth
    //eyes open while mouse is in top part of screen
    if(mouseY<250){
        noStroke();
        fill(80);
        ellipse(220,yConstrain+30,6,6);
        ellipse(260,yConstrain+30,6,6);
        
        noFill();
        stroke(80);
        strokeWeight(2);
        arc(240,yConstrain+35,30,30,40,140,OPEN);

        ellipse(220,yConstrain-125,2,2);

        //blush
        noStroke();
        fill(250+colorR,140+colorG,100+colorB)
        ellipse(200, yConstrain+40, ellipseSize/10, 14);
        ellipse(280, yConstrain+40, ellipseSize/10, 14);

    }
    if(mouseY<450 & mouseY >=250){
        noStroke();
        fill(80);
        ellipse(220,yConstrain+30,6,6);
        ellipse(260,yConstrain+30,6,6);

        stroke(80);
        strokeWeight(2);
        fill(255);
        line(230,yConstrain+45,250,yConstrain+45);

        ellipse(220,yConstrain-125,2,2);

        //text box
        fill(255);
        strokeWeight(1.5);
        noStroke();
        rect(47,yConstrain-150,104,40,30,30,0,30);
        triangle(120,yConstrain-140,120,yConstrain-110,160,yConstrain-110);
        noFill();
        stroke(80);
        strokeWeight(1);
        text("please stop",70,yConstrain-126);

        //blush
        noStroke();
        fill(250+colorR,140+colorG,100+colorB)
        ellipse(200, yConstrain+40, ellipseSize/10, 14);
        ellipse(280, yConstrain+40, ellipseSize/10, 14);

    }
    //eyes closed while mouse is in bottom part of screen
    if(mouseY>=450){
        noFill();
        strokeWeight(2);
        stroke(80);
        line(210,yConstrain+30,220,yConstrain+25);
        line(260,yConstrain+25,270,yConstrain+30);

        noFill();
        stroke(80);
        strokeWeight(2);
        arc(240,yConstrain+45,30,30,180,360,OPEN);

        fill(255);
        strokeWeight(1.5);
        noStroke();
        rect(47,yConstrain-150,104,40,30,30,0,30);
        triangle(120,yConstrain-140,120,yConstrain-110,160,yConstrain-110);
        noFill();
        stroke(80);
        strokeWeight(1);
        text("how could you",62,yConstrain-126);

        strokeWeight(2);
        line(213,yConstrain-126,220,yConstrain-124);

        //blush
        noStroke();
        fill(250+colorR,140+colorG,100+colorB)
        ellipse(200, yConstrain+40, ellipseSize/10, 14);
        ellipse(280, yConstrain+40, ellipseSize/10, 14);

    }
    //changes color of face as mouse goes down
    if(mouseY < height/2){
        if(colorR < 20){
        colorR++;
        colorG--;
        colorB-=5;}
    } else{
        if(colorR > -20){
        colorR--;
        colorG++;
        colorB-=5;
    }
}
}

At first, I struggled with the open ended nature of this prompt. I couldn’t figure out how exactly I wanted to implement all of the changing aspects in such a small canvas without making it seem too cluttered. My first idea was utilizing mouseY to create something that looked like it was being stepped on, and ended up with the code above. Although it ended up a lot different than what I had first planned, I decided that rather than limit myself to a specific sort of theme, I would just roll with whatever came to my mind first. I thought that the hardest part of this was definitely calculating the position of all of the elements I used in relation to mouseY.

daphnel-Project 03-Dynamic Drawing

Dynamic Drawing

var circleW=150;
var circleH=150;
var circleX=320;
var circleY=240;
var earL=280;
var earR=200;
var earW=70;
var earH=320;
var innerearL=200;
var innerearR=280;
var innerearW=24;
var innerearH=280;
var smallerCircleW=50;
var smallerCircleH=50;
var smallerCircleX=160;
var armR=120;
var armL=360;
var eyes=15;
var eyesR=210;
var eyesL=265;
var pupil=8;
var pupilL=212;
var pupilR=267;
var rectY=165;
var rectW=150;
var rectH=150;
var antennaR=210;
var antennaL=265;
var angle=10;
var x1=50;
var y1=0;
var x2=250;
var y2=25;
var x3=50;
var y3=50;

function setup() {
    createCanvas(480, 480);
}

function draw() {
    background(230, mouseX, mouseY);
    //made the background change based on the mouseX and mouseY positions
    strokeWeight(0);
    fill(255);
    push();
    translate(370,350);

//divided by 50 to make sure it rotates slower
    rotate(mouseX/50);

//ears
    ellipse(mouseX/7,earL,earH,earW);
    ellipse(mouseX/7,earR,earH,earW);

//inside of ears
    fill(255, 204, 204);
    ellipse(mouseX/7,innerearL,innerearH,innerearW);
    ellipse(mouseX/7,innerearR,innerearH,innerearW);

//the face
    fill(255);
    ellipse(mouseX / 7, circleY, circleW, circleH);

//the two circular arms
    ellipse(mouseX / 7, armR, mouseX/7, mouseX/7);
    ellipse(mouseX / 7, armL, mouseX/7, mouseX/7);
//body
    rect(mouseX / 7, rectY, rectW, rectH);
    fill(0);
//the two white eyes in the green blob
    ellipse(mouseX / 8,eyesR,eyes,eyes);
    ellipse(mouseX / 8,eyesL,eyes,eyes);
    fill(255);
    ellipse(mouseX/8,pupilR,pupil,pupil);
    ellipse(mouseX/8,pupilL,pupil,pupil);
//carrot body
    fill(mouseX, 153, 0);
    triangle(x1,y1,x2,y2,x3,y3);
//the greens of the carrot
    fill(102, 204, 0);
    ellipse(40,5,mouseX/7,mouseX/7);
    ellipse(25,15,mouseX/7,mouseX/7);
    ellipse(20,30,mouseX/7,mouseX/7);
    ellipse(50,25,mouseX/7,mouseX/7);
    ellipse(40,40,mouseX/7,mouseX/7);

//blush will show up on the bunny's cheeks when mouse goes past 400 px of
//the canvas
if (mouseX>400){
  fill(255, 153, 153);
  ellipse(mouseX/7,innerearL-5,13,25);
  ellipse(mouseX/7,innerearR,13,25);
}
    pop();
}

This project was actually extremely hard for me. I had a lot of ideas and inspirations but it was hard for me to actually execute them. I started off with something like this where I wanted the rectangles to move in a clockwise direction. After I got the rectangles moving the direction I wanted, I couldn’t really figure out how to slow down the rate at which they were moving and to make sure they stayed within the canvas, so this idea ended up being scrapped. I then started fiddling with the mouseX and mouseY functions and was able to use that for background in my current project. I threw in a circle since I originally wanted to create something where there was a circle in the middle and as the mouse moved to the left, the circle would split into 4, then 16 and so forth, but then that too was a little too hard for me to comprehend. I ended up connecting to together random shapes that somehow ended up looking like an Android figure. I tried using the translate, push, pop and rotate functions we learned in lab to finish off my project.

The result was a figure that looked something like this.

I tried to refine the work and make it look a little more presentable and nicer to look at as well as changed the color scheme a bit. I hope I can learn to use new and different functions to use in my future projects but as of right now, I still don’t have a full grasp of many functions so this was the best I could do.

jiaxinw-section B-Project 03-Dynamic Drawing

sketch

var rectSize = 20;
var dir = -1;

//the distance between corner circles and the center
var distCorner;
//the distance between up, bottom, left and right circle and the center
var dist1;
//color

//thin rectangle Y position 
var rectY = 5;

//thin rectangle height
var rectH = 5

function setup() {


    createCanvas(480, 640);
    distCorner = sqrt(11250);
    dist1 = 150;  

}

function draw() {			

	//if mouse is outside the canvas, then the movements stop
	if(mouseX > 480){
		mouseX = 480;
	}

	if(mouseX < 0){
		mouseX = 480;
	}

	background(40);
	noStroke();
	rectMode(CENTER);
	fill(255, 70);	
	
	//the center rectangles 
	push();
	fill(255, 90);
	//change color when mouse is hovering on the rect
	if( dist(mouseX, mouseY, width/2, height/2) < Math.abs(rectSize/2)) {
		fill(230,97,71);
	};
	//when mouse move, the rectangles rotate
	rectMode(CENTER);
	translate(width/2, height/2);
	rotate(mouseX*0.01)	
	//central big rect
	rect(0, 0, rectSize, rectSize);
	//four small rectangles on the center
	fill(255,40);
	rect(-10, 10, rectSize/2, rectSize/2);
	rect(10,-10, rectSize/2, rectSize/2);
	rect(10, 10, rectSize/2, rectSize/2);
	rect(-10,-10, rectSize/2, rectSize/2);
	pop();

	//the left rect
	push();
	//change color when mouse is hovering on the rect
	if( dist(mouseX, mouseY, width/2-100, height/2) < Math.abs(rectSize/2) ){
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2-100, height/2);
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//the up rect 
	push();
	if( dist(mouseX, mouseY, width/2, height/2-100) < Math.abs(rectSize/2)) {
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2, height/2-100);
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//the right rect
	push();
	if( dist(mouseX, mouseY, width/2+100, height/2) < Math.abs(rectSize/2)) {
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2+100, height/2);
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//the bottom rect
	push();
	if( dist(mouseX, mouseY, width/2, height/2+100) < Math.abs(rectSize/2)) {
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2, height/2+100);
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//left top rect
	push();
	if( dist(mouseX, mouseY, width/2-sqrt(5000), height/2-sqrt(5000)) < Math.abs(rectSize/2)) {
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2-sqrt(5000), height/2-sqrt(5000));
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//right top rect
	push();
	if( dist(mouseX, mouseY, width/2+sqrt(5000), height/2-sqrt(5000)) < Math.abs(rectSize/2)) {
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2+sqrt(5000), height/2-sqrt(5000));
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//right bottom rect
	push();
	if( dist(mouseX, mouseY, width/2+sqrt(5000), height/2+sqrt(5000)) < Math.abs(rectSize/2)) {
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2+sqrt(5000), height/2+sqrt(5000));
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//left bottom rect
	push();
	if( dist(mouseX, mouseY, width/2-sqrt(5000), height/2+sqrt(5000)) < Math.abs(rectSize/2)) {
		fill(125,201,198,90);
	};
	rectMode(CENTER);
	translate(width/2-sqrt(5000), height/2+sqrt(5000));
	rotate(mouseX*0.01)	
	rect(0, 0, rectSize, rectSize);
	pop();

	//outside circles
	push();
	//rotate as a big circle when the mouse moves 
	translate(width/2, height/2);	
	rotate(mouseX*0.01)
	ellipse(-dist1, 0, 15, 15);
	ellipse(dist1, 0, 15, 15);
	ellipse(0, -dist1, 15, 15);
	ellipse(0, dist1, 15, 15);
	ellipse(distCorner, -distCorner, 15, 15);
	ellipse(-distCorner, -distCorner, 15, 15);
	ellipse(distCorner, distCorner, 15, 15);
	ellipse(-distCorner, distCorner, 15, 15);
	pop();

	//instruction
	fill(255, 70);
	textSize(15);
	text("move your mouse to the squares or drag your mouse", 60, height-20); 

}

function mouseDragged(){	
	//when the mouse is dragged, the size of rects become bigger
	rectSize += 2;
	dist1 +=1.5;
	distCorner +=1.5;
	//if the size is bigger than 120, the rects become smaller
	if (rectSize > 120){
		rectSize *= dir;
		distCorner *=dir;	
		dist1 *=dir;	
	}

	//if the size is 0,the circles go back to original places
	if (rectSize == 0 ){
		distCorner = sqrt(11250);
		dist1 = 150;
		
	};

	//if the mouse if off the canvas, the graphic stop moving
	if(mouseX > 480 || mouseY > 680){
		rectSize = 100;
		distCorner = 1.5*sqrt(11250);
    	dist1 = 1.5*150;
	}
}


 

I planned to make a rotating dynamic drawing at first, so I started to build a circle of squares and when the mouse wheel was moved, the size of squares would be changed. However, I realized moving the wheel can also scroll down the page which would be very inconvenient. Therefore, I decided to change moving the wheel by dragging the mouse. Also, I realized it would be fun to change the color of squares, so I have made the color can be changed whenever the mouse is hovering on the squares.