Project 03 – Dynamic Drawing – srauch

Here is my interactive picture! As you move your mouse left to right, it gets dark outside and the moon comes up, and as you move your mouse up and down, the plant grows and its leaves open up.

sketch
//Sam Rauch / srauch / section B
//This code creates an interactive picture of a plant with a window behind it. As you move
//the mouse up and down, it gets darker and lighter outside. As you move the mouse side to
//side, the plant grows bigger and smaller. 

var windowTransparent //alpha for transparency of blue window, ie how light outside
var moonY = 300; //y position of moon
var moonview = 0; //alpha for transparency of moon
var potCenterX; //x center of pot
var potCenterY; //y center of pot
var bluefade = 0; //amount of blue added to colors as it gets darker outside
var colorfade = 0; //amount of color subtracted to colors as it gets darker outside
var plantTipY; //y tip of plant
var stemweight = 10;
var leafSizeX = 50; //width of leaf
var leafSizeY = 25; //height of leaf
var leftRotate; //rotates left-side leaves
var rightRotate; //rotates right-side leaves

var width;
var height;

function setup() {
    createCanvas(450, 600);
    background(220);
    text("p5.js vers 0.9.0 test.", 10, 15);

    width = 450;
    height = 600;
    windowTransparent = 255;
    potCenterX = 200; 
    potCenterY = 500; 
    plantTipY = potCenterY; //start the tip of the plant in the center of the pot

    leftRotate = 270;
    rightRotate = 90;

}

//draws an ellipse where the first two parameters are the ellipse's left tip
function lefttipellipse(tipX, tipY, wide, tall) {
    ellipseMode(CORNER);
    ellipse(tipX, tipY-tall/2, wide, tall);
    ellipseMode(CENTER);
}

//draws an ellipse where the first two parameters are the ellipse's right tip
function righttipellipse(tipX, tipY, wide, tall) {
    ellipseMode(CORNER);
    ellipse(tipX-wide, tipY-tall/2, wide, tall);
    ellipseMode(CENTER);
}

function draw() {

    background(230-colorfade*1.5, 230-colorfade*1.5, 120+bluefade);

    //window
    fill(240-colorfade, 240-colorfade, 230+bluefade);
    noStroke();
    rect(100, 0, 350, 450);

    //dark blue rect
    fill(26, 32, 128);
    rect(125, 0, 325, 425);

    //moon
    noStroke();
    fill(250, 250, 240, moonview); //moon white
    ellipse(300, moonY, 80);
    fill(26, 32, 128); //dark blue circle to make it a crescent
    ellipse(290, moonY-10, 70);

    //light blue sky color
    fill(185, 240, 250, windowTransparent);
    rect(125, 0, 325, 425);

    //table
    fill(110-colorfade, 60-colorfade, 37+bluefade); //brown
    rect(0, height-50, width, 50);
    //fill(100, 50, 27); //darker brown

    //plant stem
    stroke(74-colorfade, 150-colorfade, 74+bluefade); //green
    strokeWeight(stemweight);
    strokeCap(ROUND);
    line(potCenterX, potCenterY, potCenterX, plantTipY);
    noStroke();

    // the y coordinate of a point half the distance up the stem
    var yspot1 = potCenterY-(dist(potCenterX, potCenterY, potCenterX, plantTipY)/2);

    // y coordinate of a point 3/4 the distance up the stem
    var yspot2 = potCenterY-(dist(potCenterX, potCenterY, potCenterX, plantTipY)*(3/4));

    // y coordinate of a point at the top of the stem
    var yspot3 = potCenterY-(dist(potCenterX, potCenterY, potCenterX, plantTipY));

    //drawing them leaves at set points up the stem

    fill(90-colorfade*2, 180-colorfade*2, 90+bluefade); //leaf green

    //bottom right
    push();
    translate(potCenterX, yspot1);
    rotate(leftRotate);
    lefttipellipse(0, 0, leafSizeX, leafSizeY);
    pop();

    //bottom left
    push();
    translate(potCenterX, yspot1);
    rotate(rightRotate);
    righttipellipse(0, 0, leafSizeX, leafSizeY);
    pop();

    //middle right
    push();
    translate(potCenterX, yspot2);
    rotate(leftRotate);
    lefttipellipse(0, 0, leafSizeX*(7/8), leafSizeY*(7/8));
    pop();

    //middle left
    push();
    translate(potCenterX, yspot2);
    rotate(rightRotate);
    righttipellipse(0, 0, leafSizeX*(7/8), leafSizeY*(7/8));
    pop();

    //top right
    push();
    translate(potCenterX, yspot3);
    rotate(leftRotate);
    lefttipellipse(0, 0, leafSizeX*(2/3), leafSizeY*(2/3));
    pop();

    //top left
    push();
    translate(potCenterX, yspot3);
    rotate(rightRotate);
    righttipellipse(0, 0, leafSizeX*(2/3), leafSizeY*(2/3));
    pop();

    //pot
    fill(230-colorfade, 140-colorfade, 83+bluefade); //salmon
    rectMode(CENTER);
    rect(potCenterX, potCenterY, 120, 150);
    triangle(potCenterX-60, potCenterY-75, potCenterX-60,
        potCenterY+75, potCenterX-80, potCenterY-75);
    triangle(potCenterX+60, potCenterY-75, potCenterX+60,
        potCenterY+75, potCenterX+80, potCenterY-75);
    fill(240-colorfade, 150-colorfade, 93+bluefade);
    rect(potCenterX, potCenterY-90, 170, 60);
    rectMode(CORNER);

    //as move mouse left to right, the sky gets darker and colors fade to bluer shade
    windowTransparent = map(mouseX, width, 0, 0, 255);
    bluefade = map(mouseX, width, 0, 0, 40, true);
    colorfade = map(mouseX, 0, width, 0, 40, true);

    //as move mouse left to right, moon comes up
    moonY = map(mouseX, 0, width, 375, 100, true);
    moonview = map(mouseX, 0, 450, 0, 255);

    //as move mouse up and down, plant grows
    plantTipY = map (mouseY, height, 0, potCenterY, 230); //gets taller
    stemweight = map (mouseY, height, 0, 5, 25); //stem gets thicker
    leafSizeX = map (mouseY, height, 0, 50, 150); //leaves get longer
    leafSizeY = map (mouseY, height, 0, 30, leafSizeX/3); //leaves get taller
    leftRotate = radians(map(mouseY, height, 0, 270, 340)); //right leaves open up
    rightRotate = radians(map(mouseY, height, 0, 90, 20)); //left leaves open up
    //plant pot

}

Project 03: Dynamic Drawing

  1. Size of large circle changes
  2. Shade of large circle changes
  3. Rotation of smaller circle changes
  4. Stroke of smaller circles changes

var uniX = 0;
var uniY = 0;


function setup() {
    createCanvas(600, 450);
    background(0);
}

function draw() {
    uniX = mouseX;
    uniY = mouseY;
    background(0);
    push();
    fill(255);
    ellipse (uniX,uniY,200);
    pop();
    for (let i = 25; i <= 575; i+=50)
    {
        for (let j = 25; j <= 425; j+=50)
        {
            circleChange(i,j);
        }
    }
}

function circleChange(Cx,Cy) {
    distanceO = Math.sqrt((uniX-Cx)*(uniX-Cx) + (uniY-Cy)*(uniY-Cy));
    distance = constrain(distanceO, 10, 200);
    var diameter = distance/4;
    var angle = Math.atan2((uniY-Cy),(uniX-Cx));
    push();
    strokeWeight(1);
    stroke(0,0,255,255);
    noFill();
    arc(Cx, Cy, diameter, diameter, -0.25*PI, 0.75*PI);
    pop();
    push();
    strokeWeight(1);
    stroke(255,0,0,255);
    arc(Cx, Cy, diameter, diameter, 0.75*PI, 1.75*PI);
    pop();

    push();
    strokeWeight(0);
    fill(distance/200*255);
    ellipse (Cx,Cy,diameter-2);
    pop();

    fill(255);
    strokeWeight(distanceO/60);
    ellipse((Cx+diameter*Math.cos(angle)/3),(Cy+diameter*Math.sin(angle)/3),diameter/3);

}

anabelle’s project 03

This is my project! Try making the sky change from sundown to midnight, see the moon change phases, and the stars glitter! You can try to pet the cat as well <3

sketch
// kayla anabelle lee (kaylalee)
// section c
// project 03 ^^

moonX = 200; 
moonY = 150;
outline = 55;
inline = 50;

let direction = 0.8;
let speed = 1;
let starDiam = 20; 

let redValue = 231;
let greenValue = 157;
let blueValue = 193;

let skyScraperX = 300;
let skyScraperY = 100;

let happyMouthX = 60;
let happyMouthY = 450;

let triangleWindowX = 225;
let triangleWindowY = 185;
let catDirection = 1;
let catAngle = 1;
let moonSpin = 0;

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

function draw() {
    print(catAngle);
    background(redValue, greenValue, blueValue);

    // constrain the rbg values to the 2 sky colors i want
    redValue = constrain(redValue, 46, 231);
    greenValue = constrain(greenValue, 26, 157);
    blueValue = constrain(blueValue, 71, 193);

    // turns dusk when mouse on left, turns night when mouse on right
    if (mouseX > width/2) { 
        redValue -= 3;
        blueValue -= 3;
        greenValue -= 3;

    } if (mouseX < width/2) {
        redValue += 3;
        blueValue += 3;
        greenValue += 3;
    }

    // moon cycle
    if (mouseX <= 100) {
        newMoon(35, 290, 30, 30);
    } if (100 < mouseX & mouseX <= 200) {
        crescentMoon(115, 110, 30, 30);
    } if (200 < mouseX & mouseX <= 300) {
        gibbousMoon(190, 50, 30, 30);
    } if (300 < mouseX) {
        fullMoon(300, 50, 30, 30);
    }

    // triangular building
    stroke(164, 96, 175);
    strokeWeight(1);
    fill(119, 127, 199);
    fill(230, 209, 242);
    quad(95, 600, 220, 170, 390, 170, 390, 600);

    // triangle building windows
    // im sorry i couldnt use a forLoop for these as well -- whenever i tried, the program wouldnt load

    triangleWindow(triangleWindowX,triangleWindowY);
    triangleWindow(triangleWindowX - 5, triangleWindowY + 20);
    triangleWindow(triangleWindowX - 10, triangleWindowY + 40);
    triangleWindow(triangleWindowX - 15, triangleWindowY + 60);
    triangleWindow(triangleWindowX - 20, triangleWindowY + 80);
    triangleWindow(triangleWindowX - 25, triangleWindowY + 100);
    triangleWindow(triangleWindowX - 30, triangleWindowY + 120);
    triangleWindow(triangleWindowX - 35, triangleWindowY + 140);
    triangleWindow(triangleWindowX - 40, triangleWindowY + 160);
    triangleWindow(triangleWindowX - 45, triangleWindowY + 180);
    triangleWindow(triangleWindowX - 50, triangleWindowY + 200);
    triangleWindow(triangleWindowX - 55, triangleWindowY + 220);
    triangleWindow(triangleWindowX - 60, triangleWindowY + 240);
    triangleWindow(triangleWindowX - 65, triangleWindowY + 260);

    // skyscraper
    fill(217, 196, 236);
    stroke(164, 96, 175);
    strokeWeight(1);

    rect(300, 100, 150, 500);
    rect(350, 45, 100, 55);
    triangle(350, 40, 450, 0, 530, 40);

    // skyscraper windows
    for(skyScraperX = 300; skyScraperX < 440; skyScraperX += 40) {
        for(skyScraperY = 100; skyScraperY < 650; skyScraperY +=40) {
            push(); 
            translate(20, 20);
            skyWindow();
            pop();
        }
    }

    // happymouth building
    stroke(164, 96, 175);
    strokeWeight(1);
    fill(204, 183, 229);
    rect(40, 430, 195, 170);
    rect(50, 380, 170, 40);

    textSize(25);
    fill(244, 244, 211);
    stroke(119, 127, 199);
    text("happyMouth()", 60, 405);

    // happymouth windows
    for(happyMouthX = 40; happyMouthX < 200; happyMouthX += 60) {
        for(happyMouthY = 420; happyMouthY < 600; happyMouthY += 30) {
            push(); 
            translate(15, 30);
            happyWindow();
            pop(); 
        }
    }

    // if mouse on happymouth sign, stars pulse AND crescent moon rotates
    if (dist(135, 390, mouseX, mouseY) < 30) {
        starrySky();
        starDiam += direction * speed;

        if (starDiam > 30) {
            direction = -direction;
            starDiam = 30;

        } if (starDiam < 0) {
            direction = -direction;
            starDiam = 0;  
        } 

    } else starrySky();

    // rooftop building
    fill(177, 156, 216);
    stroke(64, 96, 175);
    quad(185, 550, 270, 420, 430, 420, 410, 550);
    fill(190, 169, 223);
    rect(185, 550, 225, 50);
    quad(410, 600, 410, 550, 430, 420, 430, 600);

    // cat perch and cat
    fill(117, 80, 166);
    rect(0, 180, 150, 60);

    cat(130, 120, 10, 10)
    triangle(43, 69, 39, 78, 45, 78);
    triangle(74, 82, 64, 84, 72, 93);

    push();
    rotate(radians(catAngle*catDirection));
    push();
    scale(0.7);
    rotate(radians(-20));
    catTail(-50, 250, catAngle*catDirection); 
    pop();
    pop();

    // cat tail animation
    if (dist(60, 50, mouseX, mouseY) < 50) { 
        push();
        rotate(radians(catAngle*catDirection));
        push();
        scale(0.7);
        rotate(radians(-20));
        catTail(-50, 250, catAngle*catDirection); 
        pop();
        pop();
    
        catAngle -= 1;
        if (catAngle < -10) {
            catAngle = -10;
        }

        } if (dist(40, 120, mouseX, mouseY) < 50) {
            catAngle += 1;
            if (catAngle > 10){
                catAngle = 10;
            }
   
        }
    }

// my catalogue of functions 

function cat(x, y, w, h) { 
    fill(50);
    noStroke();
    ellipse(x/2, y/2, 50, 50);
    ellipse(x/2 + 17, y/2 + 5, 25, 28);
    ellipse(x/2 - 20, y/2 + 65, 70, 100);
    arc(x/2 - 20, y/2 + 120, 90, 70, radians(180), radians(0));

    triangle(x/2 + 5, y/2 - 15, x/2 + 20, y/2 - 15, x/2 + 13, y/2 - 35);
    triangle(x/2 - 5, y/2 - 15, x/2 - 20, y/2 - 15, x/2 - 13, y/2 - 35);

    bezier(x/2 - 20, y/2 + 5, x/2 - 30, y/2 + 30, x/2 - 30, y/2 + 20, x/2 - 40, y/2 + 25);
    bezier(x/2 + 10, y/2 + 20, x/2 + 5, y/2 + 30, x/2 + 5, y/2 + 40, x/2 + 13, y/2 + 55);
}

function catTail(x, y, catAngle) {
    noStroke();
    beginShape();
    curveVertex(x, y);
    curveVertex(x, y);
    curveVertex(x - 5, y + 40);
    curveVertex(x + 20, y + 100);
    curveVertex(x + 80, y + 140);
    curveVertex(x + 150, y + 150);
    curveVertex(x + 160, y + 140);
    curveVertex(x + 145, y + 120);
    curveVertex(x + 70, y + 100);
    curveVertex(x + 40, y + 50)
    curveVertex(x + 30, y);
    curveVertex(x + 30, y);
    endShape();
}

function triangleWindow(triangleWindowX, triangleWindowY) {
    fill(244, 244, 211);
    quad(triangleWindowX, triangleWindowY, triangleWindowX -5, triangleWindowY + 15, triangleWindowX + 200, triangleWindowY + 15, triangleWindowX + 200, triangleWindowY);
}

function happyWindow() {
    rect(happyMouthX, happyMouthY, 50, 15);
}

function skyWindow() {
    fill(244, 244, 211);
    rect(skyScraperX, skyScraperY, 20, 20);
} 

function newMoon(newX, newY, w, h) {
    outline = 55;
    inline = 50;

    stroke(255);
    fill(redValue, greenValue, blueValue);
    ellipse(newX, newY, outline, outline);
    ellipse(newX, newY, inline, inline);
}
   
function crescentMoon(crescentX, crescentY, w, h) {
    outline = 55;
    inline = 50;

    fill(255);
    ellipse(crescentX, crescentY, inline, inline);
    fill(redValue, greenValue, blueValue);
    noStroke();
    rect(115, 80, outline/2, outline)
    stroke(255);
    noFill();
    ellipse(crescentX, crescentY, outline, outline);
    fill(redValue, greenValue, blueValue);
    noStroke();
    ellipse(crescentX, crescentY, inline/2, inline);
}
   
function gibbousMoon(gibbousX, gibbousY, w, h) {
    outline = 55;
    inline = 50;

    noStroke();
    fill(255);
    ellipse(gibbousX, gibbousY, inline, inline);
    fill(redValue, greenValue, blueValue);
    noStroke();
    fill(redValue, greenValue, blueValue);
    rect(190, 24, outline/2, outline);
    stroke(255);
    noFill();//Outline
    ellipse(gibbousX, gibbousY, outline, outline);
    fill(255)
    arc(gibbousX, gibbousY, inline/2, inline, PI/2, -PI/2);
}

function fullMoon (fullX, fullY, w, h) {
    outline = 55;
    inline = 50;

    noFill();
    stroke(255);
    ellipse(fullX, fullY, outline, outline);
    fill(255);
    ellipse(fullX, fullY, inline, inline);
}

function starrySky() {
    noStroke();
    fill(253, 253, 150);

    circle(140, 30, starDiam/5);
    circle(275, 136, starDiam/7);
    circle(61, 303, starDiam/4);
    circle(167, 38, starDiam/6);
    circle(10, 34, starDiam/7);
    circle(163, 147, starDiam/3);
    circle(292, 121, starDiam/8);
    circle(154, 328, starDiam/5);
    circle(360, 15, starDiam/2);
    circle(19, 386, starDiam/6);
}


// ALL moon functions were made by brantschen at https://editor.p5js.org/brantschen/sketches/bGH-klhrY
// cat mechanics inspired by jiatong li

Windows style dynamic drawing

I am trying to create a grid of circles and using my mouse cursor as an attraction point to control the size and color of the circles. The wavey movement of circles is created by changing the circle rotation angle based on the distance between the mouse cursor and the center of the circles.

//Jason Jiang
//Section E

//Setting variables 
var d = 40;
var size = d/2;
var h = 0;
var s = 0;
var a = 0;
function setup() {
    createCanvas(640, 450);
    angleMode(DEGREES);
    colorMode(HSB);
    
}

function draw() {
    background(0);
    fill(255);
    noStroke();
    //Create Grid of circles using loop
    for (var x = d/2 - d; x < width + d; x = x+d){
        for (var y = d/2 - d; y < height + d; y = y+d){
        var dis = dist(x, y, mouseX, mouseY);
        
        //Change Circle size according to distance
        
        //Remap distance to circle center to angle
        size = map(dis, 0, (width^2+height^2)^0.5, 30, 1);

        //Change Circle color according to distance
        
        //Remap distance to circle center to color value
        h = map(dis, 0, (width^2+height^2)^0.5, 0, 255);
        s = map(dis, 0, (width^2+height^2)^0.5, 50, 100);
        fill(h, s, 100);
        

        //Change circle rotation according to distance

        //Remap distance to circle center to angle
        let a = map(dis, 0, (width^2+height^2)^0.5, 0, 360);
            push();
            translate(x, y);
            rotate(a);
            circle(10, 10, size);
            pop();
        }
    }    
}

Project 03: Dynamic Drawing

sketch

var j=25
var l=15
var x=0
var y=0
var state=0
function setup() {
    createCanvas(600,450);
    background(0);
   
}

function draw() {
    //draw square according to the distance to the mosue
    /*if(mouseX<width/2){
        background(0);
    }else{
        background(255);
    }*/
    background(0);

    
    noStroke();
    
    for (x=5;x<=width;x+=j){

        for(y=5;y<=width;y+=j){
            //define variables for color changes
            var r =dist(mouseX,mouseY,x,y)
            var r2=dist(mouseX,mouseY,0,0)
            var r3=dist(mouseX,mouseY,width,height)
            var r4=dist(mouseX,mouseY,0,height)
            var r5=dist(mouseX,mouseY,width,0)
            var r6=dist(mouseX,mouseY,width/2,height/2)

            fill(r6,100-r,255-r+100)

            //fill(r+10,150-r,255-r+200);

            //color test 01
            /*if(mouseX<width/2 & mouseYheight/2){
                fill(r4,r4+100,r4+200);
            }else if(mouseX>width/2 & mouseYheight/2){
                fill(r3,r3+100,r3+200);
            }*/

            //color test 02
            /*if(mouseX<width/2 & mouseYheight/2){
                fill(r4,255-r,255-r+200);
            }else if(mouseX>width/2 & mouseYheight/2){
                fill(r3,255-r,255-r+200);
            }*/

            //color test 03
            /*if(mouseX<width/2 & mouseYheight/2){
                fill(255-(r+10),255-(150-r),r-200);
            }else if(mouseX>width/2 & mouseYheight/2){
                fill(255-r,r+100,r+200);
            }*/
            
            var l=(dist(mouseX,mouseY,x,y)/20+7)
            
                if(state==0){
                    rect(x,y,l,l);
                }else if(state==1){
                    circle(x+l/2,y+l/2,l);
                }else if (state==2){
                    triangle(x,y,x+l,y,x+l/2,y+l);
                    triangle(x,y+l,x+l,y+l,x+l/2,y);
                }
            
            }
            fill(255);
            text('press mouse please :)',10,15);
    }
    
    }
    function mousePressed(){
        state+=1;
        if(state>=3){
            state=0;
        }
}
    

Project 03: Dynamic Drawing

This is my project for dynamic drawing. The most difficult part for me is understanding the relationship between the size of the hearts and the distance between the hearts and my mouse.

sketch

//Jenny Wang
//Section B

function setup() {
    createCanvas(600,450);
    background(220);
    text("p5.js vers 0.9.0 test.", 10, 15);
    smooth();
    noStroke();
}

var s = 30 //space in between
var x = 0
var y = 0
var heart
var angle = 0
function draw() {
    background("lightblue");

    //set color variation
    var R = (dist(x,y,mouseX,mouseY)/100)*30;
    var G = (dist(x,y,mouseX,mouseY)/100)*20;
    var B = (dist(x,y,mouseX,mouseY)/100)*30;

    
     
    //draw hearts with for loops
    var maxD = 50;
    var maxS = 3;

    for (x = 0; x < width; x += s) {
      for (y = 0; y < height; y += s) {
      fill (R,G,B);
      var size = (dist(x,y,mouseX,mouseY)/maxD)*maxS;
      //set size variation
      heart(x+s/2, y+s/2, size);
      }
    }

    //draw heart
    var r = mouseX/2
    
    push()//square1
    fill("lightyellow");
    translate(width/2,height/2);
    rotate(radians(angle)+10);
    ellipse(mouseX/2,mouseY/2,r*2+mouseX/2);
    pop();
    angle += 2;

    push()//square2
    fill("lightgreen");
    translate(width/2,height/2);
    rotate(radians(angle)+20);
    ellipse(mouseX/2,mouseY/2,r*2+mouseX/2);
    pop();
    angle += 2;
    

    push();
    fill("pink");//circle 3
    translate(width/2,height/2);
    rotate(radians(angle)+30);
    ellipse(mouseX/2,mouseY/2,r*2+mouseX/2);
    pop()
    angle += 2;


function heart (x,y,size){
    // fill(R,G,B);
    beginShape();
    vertex(x, y);
    bezierVertex(x - size / 2, y - size / 2, x - size, y + size / 3, x, y + size);
    bezierVertex(x + size, y + size / 3, x + size / 2, y - size / 2, x, y);
    endShape(CLOSE);
}
//draw a heart


}




Project 03 Dynamic Drawing

project3

For this project, I wanted some kind of flower scene. I had a lot of fun figuring out how to make it seem like they can grow based on the position of the mouse, along with making the cloud interactive both with the sun and the mouse. I added the spinning parts to try the rotate and push & pop methods and figure out how they work.

Initial idea of moving flower and cloud with mouseX and mouseY. Also, figuring out how to make scene darker when cloud covers the sun.

// Rachel Legg / rlegg / Section C

var x;
var y;
var offset = 5;
var fOne;
var fThree;
var edge = 599;
var angle = 0;

function setup() {
    createCanvas(600, 450);
    background(255);
    x = 1/5 * width;
}

function draw() {
        //if mouse is on right side, it is night , or else it is day
    if (mouseX <= width / 2){
        background(135, 206, 235);    //dark blue
        noStroke();
        ellipse(75, 75, 40);
        fill("yellow");
        noStroke();
        ellipse(75, 75, 40);
    }else{
        background(0, 0, 102);
        fill(255);
        noStroke();
        ellipse(75, 75, 40);
        fill(0, 0, 102);
        ellipse(80, 70, 40);
    }
    
    //ground
    fill(111, 78, 55);                              //brown
    noStroke();
    rect(0, 4/5 * height, width, 4/5 * height);
    fill("green");                             //grass
    rect(0, 4/5 * height, width, 20);


//flower 1
//flower stem grows and shrink based on mouse location
    if(mouseX < 200 & mouseY <= (4/5 *height)){
        stroke("green");
        line(1/4 * width, 4/5 * height, 1/4 * width, mouseY);
        fill(255);
        noStroke();
        fOne = 1/4 * width;
        circle(fOne, mouseY - 17, 30);
        circle(fOne - 20, mouseY - 5, 30);
        circle(fOne + 20, mouseY - 5, 30);
        circle(fOne - 12, mouseY + 13, 30);
        circle(fOne + 12, mouseY + 13, 30);
        fill("yellow");
        stroke("pink");
        strokeWeight(4);
        circle(1/4 * width, mouseY, 20);
    //flower spinds when not interacting
    }else{
        strokeWeight(4);
        stroke("green");
        line(1/4 * width, 4/5 * height, 1/4 * width, 2/3 * height);
        fill(255);
        noStroke();
        push();      
        translate(150, 300);
        rotate(radians(angle));
        circle(0, -17, 30);
        circle(-20, -5, 30);
        circle(20, -5, 30);
        circle(-12, 13, 30);
        circle(12, 13, 30);
        fill("yellow");
        stroke("pink");
        strokeWeight(4);
        circle(0, 0, 20);
        pop();
        angle += 2
    }

    //flower 2
        if(mouseX < 400 & mouseX > 200 && mouseY <= (4/5 *height)){
            stroke("green");
            line(width / 2, 4/5 * height, width / 2, mouseY);
            fill(250, 172, 382);
            noStroke();
            circle(width / 2, mouseY, 40, 40);
            fill(77, 208, 99);
            circle(width / 2, mouseY, 25, 25);
            fill(255, 51, 51);
            circle(width / 2, mouseY, 10, 10);
        }else{
            strokeWeight(4);
            stroke("green");
            line(width / 2, 4/5 * height, width / 2, 2/3 * height);
            fill(250, 172, 382);
            noStroke();
            circle(width / 2, 2/3 * height, 40, 40);
            fill(77, 208, 99);
            circle(width / 2, 2/3 * height, 25, 25);
            fill(255, 51, 51);
            circle(width / 2, 2/3 * height, 10, 10);
    }

    //flower 3
    if(mouseX > 400 & mouseY <= (4/5 *height)){
        stroke("green");
        line(3/4 * width, 4/5 * height, 3/4 * width, mouseY);
        noStroke();
        fThree = 3/4 * width;
        fill(0, 128, 255);
        circle(fThree + 20, mouseY - 17, 25);
        circle(fThree - 20, mouseY - 17, 25);
        circle(fThree + 20, mouseY + 17, 25);
        circle(fThree - 20, mouseY + 17, 25);
        fill(0, 51, 102);
        ellipse(fThree, mouseY - 17, 20, 30);
        ellipse(fThree - 20, mouseY, 30, 20);
        ellipse(fThree + 20, mouseY, 30, 20);
        ellipse(fThree, mouseY + 17, 20, 30);
        fill(255, 153, 204);
        circle(3/4 * width, mouseY, 30);
        fill(255, 51, 153);
        stroke(204, 204, 255);
        strokeWeight(4);
        circle(3/4 * width, mouseY, 20);
    }else{
        strokeWeight(4);
        stroke("green");
        line(3/4 * width, 4/5 * height, 3/4 * width, 2/3 * height);
        fill(255);
        noStroke();
        noStroke();
        push();      
        translate(450, 300);
        rotate(radians(angle));
        fill(0, 128, 255);
        circle(20, -17, 25);
        circle(-20, -17, 25);
        circle(20, 17, 25);
        circle(-20, 17, 25);
        fill(0, 51, 102);
        ellipse( 0, -17, 20, 30);
        ellipse(-20, 0, 30, 20);
        ellipse(20, 0, 30, 20);
        ellipse(0, 17, 20, 30);
        fill(255, 153, 204);
        circle(0, 0, 30);
        fill(255, 51, 153);
        stroke(204, 204, 255);
        strokeWeight(4);
        circle(0, 0, 20);
        pop();
        angle += 2
    }

    //cloud follows mouse back and forth
    if (mouseX > x) {
        x += 0.5;
        offset = -5;
    }
    if (mouseX < x) {
        x -= 0.5;
        offset = 5;
    }
    if (x > 599){             //constrain to frame
        x = 599;
    }

    fill(255);
    noStroke();
    ellipse(x, 100, 100);
    ellipse(x + 50, 110, 70);
    ellipse(x - 50, 110, 70);


    //if cloud covers sun, screen gets darker
    var shadeCover = 20;

    if (x <= 125 & x >= 30){
        background(0, 0, 102, shadeCover);
    }

}




Project-03-Dynamic-Drawing Section D

I enjoyed the freeform in this project which was more open-ended. I had lots of fun playing tricks on the eye in addition to the mouse interaction. Move your mouse left and right and see what happens!!

dynamic drawing sketch
var angle = 0;
var x;
var y;
var w = 80;
var h = 80;
var xe;
function setup() {
    createCanvas(600, 450);
    background(220);
    frameRate(15); 
    
}

function draw() {
    background(204);
    var x = width/2;
    var y = height/2;
    var xe = width/2;
    var ye = height/2;
    

    angle = angle + 1; 
    if (mouseX <= width/2) {  // when mouse moves to left
        background(255); // black background
        // make square bigger
        w = w + 8;
        h = h + 8;

        // bigger white rectangle
        push();
        translate(x,y);   
        rotate(-angle);
        rectMode(CENTER);
        fill (0);
        rect(0, 0, w*20, h*20);
        pop();
        //bigger white circle
        fill(255);
        ellipse(xe, ye, w*17); 
        // big black rectangle 
        push();
        translate(x,y);   
        rotate(angle);
        rectMode(CENTER);
        fill (0);
        rect(0, 0, w*10, h*10);
        pop();
        // big white circle
        fill(255);
        ellipse(xe, ye, w*8);  
        // black rectangle
        push();   // this keeps whatever code that is inside push and pop "self contained" without affecting other code/ "undo"
        translate (x,y);
        rotate(-angle); 
        rectMode(CENTER);
        fill(0);
        rect(0, 0, w*4, h*4);
        // draw black ellipse in center of square
        pop(); 
        fill(255);
        ellipse (xe, ye, w*3);  
         // square inside of ellipse that rotates the opposite direction 
        push();
        translate(x,y);  
        rotate(angle);
        rectMode(CENTER);
        fill(0);
        rect(0, 0, w, h);
        pop();
        // small white circle that approaches center
        push();
        translate(300, 225);
        rotate(radians(angle)); 
        ellipse(xe -100, ye - 100, 50);
        pop();
        angle = angle + 8; // used to be 50

        
    } else if (mouseX >= width/2) {  // when mouse moves to right
        background(0); // white background
        // make square bigger
        w = w - 8; 
        h = h - 8;
         // bigger black rectangle
        push();
        translate(x,y);   
        rotate(angle);
        rectMode(CENTER);
        fill (255);
        rect(0, 0, w*20, h*20);
        pop();
        // bigger black circle
        fill(0);
        ellipse(xe, ye, w*17); 
        // big white rectangle
        push();
        translate(x,y);   
        rotate(-angle);
        rectMode(CENTER);
        fill (255);
        rect(0, 0, w*10, h*10);
        pop();
        // really big black circle
        fill(0);
        ellipse(xe, ye, w*8);  
        // big white rectangle
        push();
        translate (x,y);  
        rotate(angle); 
        rectMode(CENTER);
        fill(255);
        rect(0, 0, w*4, h*4);
        pop();
        // smaller black circle 
        fill(0);
        ellipse (xe, ye, w*3); 
        // white rectangle that rotates in opposite direction
        fill(255);        
        translate(x,y);  
        rotate(-angle);
        rectMode(CENTER);
        fill(255);
        rect(0, 0, w, h);
        // small black circle with white outline that approaches center
        push();
        translate(300, 225);
        rotate(radians(angle)); 
        stroke(255);
        fill(0);
        ellipse(xe -100, ye - 100, 50);
        pop();
        angle = angle - 8;

    }
}
    

Project-03-Dynamic-Drawing

TIME 2 PARTY!

sketch

// Zoe Lin (ID: youlin)
// Section B

var x, y, r, g, b, rad;

function setup() {
  createCanvas(500, 500);
  noStroke();
  rectMode(CENTER);
}

function draw() {
  background(random(0, 15));
  
  //party lights!!!
  push();
  blendMode(SCREEN);
  r = random(255); //randomizes color
  g = random(50);
  b = random(255);
  x = random(width); //randomizes where lights spawn
  y = random(height);
  rad = random(2, 50); //randomizes size of circle
  noStroke();
  fill(r, g, b, random(75, 125)); //sets a random transparency
  circle(x, y, rad); //spawns a circle anywhere on canvas
  circle(mouseX, mouseY, rad*2); //spawns lights where the cursor is
  pop();
  
  let r1 = map(mouseX, 0, height/2, 0, width/2); //tracks horizontal location of mouse
  let r2 = width - r1;
  
  let up = map(mouseY, 0, height, 0, width); // tracks vertical location of mouse
  let down = height - up; //the other way

  //circle1
  let circle1X = width / 3 + r2 * 0.75 //x position of circle 1
  let circle1Y = height / 3 - r2 / 3.5 //y position of circle 1
  let circle1Mouth = up/4 //mouth location of circle 1
  
  //body
  noStroke();
  fill(up/3,r1/3,down/3,r2/3);
  ellipse(circle1X, circle1Y, down, r2); //fluid body
  
  //eye
  fill(0, r2);
  circle(circle1X - up/4, circle1Y - r2/10 , down/20);
  
  //eye
  fill(0, r2);
  circle(circle1X + up/4, circle1Y - r2/10 , up/12);
  
  //mouth
  noFill();
  stroke(0, r2);
  strokeWeight(4);
  arc(circle1X, circle1Y + r2/12, circle1Mouth, circle1Mouth, TWO_PI, PI);

  //circle2
  let circle2X = width / 2
  let circle2Y = height / 2 + down / 2
  let circle2Mouth = down/4
  
  noStroke();
  fill(r2/3,up/3,r1/3,down/3);
  ellipse(circle2X, circle2Y,  down*1.25, up*1.5);
  
  fill(0, r2)
  circle(circle2X - r2/4, circle2Y - down/10 , up/8);
  
  fill(0, r2)
  circle(circle2X + r2/4, circle2Y - down/10 , down/8);
  
  noFill();
  stroke(0, r2);
  strokeWeight(4);
  arc(circle2X, circle2Y + r2/20, circle2Mouth, circle2Mouth, TWO_PI, PI);
  
  //circle3
  let circle3X = width / 1.5 + r2 / 2
  let circle3Y = height / 2
  let circle3Mouth = down/10
  
  noStroke();
  fill(down/3,r2/3,up/3,r1/3);
  ellipse(circle3X, circle3Y, r2*1.5, r2*1.5);
  
  fill(0, r2)
  circle(circle3X - r2/4, circle3Y - r2/10 , r2/8);
  
  fill(0, r2)
  circle(circle3X + r2/4, circle3Y - up/10 , r2/8);
  
  noFill();
  stroke(0,r2 );
  strokeWeight(4);
  arc(circle3X, circle3Y + r2/12, circle3Mouth, circle3Mouth, TWO_PI, PI);
  
  //circle4
  let circle4X = width / 1.5 - r1/1.7
  let circle4Y = height / 4 + r2/4
  let circle4Mouth = down/10
  
  noStroke();
  fill(r1/3,down/3,r2/3,up/2.5);
  ellipse(circle4X, circle4Y, r1*1.25, down);
  
  fill(0, r2)
  circle(circle4X - r1/4, circle4Y - r2/15 , r1/8);
  
  fill(0, r2)
  circle(circle4X + r1/4, circle4Y - r1/10 , r1/8);
  
  noFill();
  stroke(0,r2);
  strokeWeight(4);
  arc(circle4X, circle4Y + r1/10, circle4Mouth, circle4Mouth, TWO_PI, PI);
  
  //circle5
  let circle5X = width / 3 - r2 / 1.5
  let circle5Y = height / 2.5
  let circle5Mouth = r2/4
  
  noStroke();
  fill(down/3,r2/2,r1/2,r2/3);
  ellipse(circle5X/1.5, circle5Y/2, up, up*1.25);
  
  fill(0, r2)
  circle(circle5X - up/4, circle5Y - up/3 , r1/8);
  
  fill(0, r2)
  circle(circle5X + r1/4, circle5Y - r1/3 , r1/8);
  
  noFill();
  stroke(0,r2);
  strokeWeight(4);
  arc(circle5X, circle5Y + r1/20, circle5Mouth, circle5Mouth, TWO_PI, PI);
  
  //circle6
  let circle6X = width / 5 + r1 / 2.5
  let circle6Y = height - 10
  let circle6Mouth = r1/5
  
  noStroke();
  fill(r2/3,up/4,r2/2,up/3);
  ellipse(circle6X, circle6Y, up*0.6, down*1.2);  
  
  fill(0, r2)
  circle(circle6X - up/5, circle6Y - up/10 , r1/10);
  
  fill(0, r2)
  circle(circle6X + r1/7, circle6Y - r1/10 , r1/10);
  
  noFill();
  stroke(0,r2);
  strokeWeight(4);
  arc(circle6X, circle6Y + r1/10, circle6Mouth, circle6Mouth, TWO_PI, PI);
 
  //circ7
  let circle7X = width - 10
  let circle7Y = height / 2 - up
  let circle7Mouth = up/4
  
  noStroke();
  fill(up/3,r1/4,down/2,r2/3);
  ellipse(circle7X, circle7Y, down*0.5, up);
  
  fill(0, r2)
  circle(circle7X - up/4, circle7Y - up/10, r1/8);
  
  fill(0, r2)
  circle(circle7X + r1/4, circle7Y - r1/10 , r1/8);
  
  noFill();
  stroke(0,r2);
  strokeWeight(4);
  arc(circle7X, circle7Y+r1/20, circle7Mouth, circle7Mouth, TWO_PI, PI);
}

Project-03-Dynamic-Drawing

I began this project by writing down my main actions for the animation and what conditions caused them to change. After I got one part working, I slowly added more conditions and commands, ensuring they worked before continuing.

The animation starts with a simple circle of lines. The user can click on the screen to make the second row of lines appear. If the user clicks on the left half then the direction that the lines are drawn changes. Depending on the quadrant the user clicks in the number of rows and color will change.

sketch
// Emily Franco
// efranco
// Section C

//line distance from center
var fromCenter = 5;

//x and y positions of pts for lines
var ptX = 0;
var ptY = 0;

//default line length
var length = 5;

//current rotation degree
var deg = 0;
var rot = 5;
var dir = 1;
var degTwo = 0;

//tracks how many times mouse is clicked
var clicked = 0;
//tracks number of circle sets
var cirSet = 0;

//stores mouseX and mouseY when clicked 
var mX =0;
var mY = 0;

//store previous tranlation to subtract from when new center is clicked
var transX;
var transY;

//num of rows around circle
var rows = 6; 

//colors
var r = 255;
var g = 255;
var b = 0;


//color increment
var colorInt = 20;

function setup() {
    createCanvas(600, 450);
    background(220);
    text("p5.js vers 0.9.0 test.", 10, 15);
    frameRate (70);
    background ("black");

}

function draw() {
	//change origin to center of canvas
	transX = width/2;
	transY = height/2;
	translate (transX,transY);
	
	//if mouse is clicke five times now center is 
	//at mouse position
	if (cirSet==1){
		translate (mX-transX,mY-transY);
		transX = mX-transX;
		transY = mY-transY;
	}

	//only reset at start of each set
	if(clicked == rows){
		//reset values
		fromCenter = 5;
		length = 5;
		clicked = 0;
	}

	if (deg <= 360){
		//rotate lines
		rotate (radians(deg));
		deg += rot*dir;

		//if mouse is in left half turn clockwise 
		//if mouse is in right hald turn counterclockwise
		//draw lines towards center of canvas
		stroke (g,r,b);
		line (ptX+fromCenter,ptY,ptX+fromCenter+length,ptY);
	}

	//line "chases white lines" and draws over them
	push();
	stroke (b,g,r);
	rotate (radians(degTwo));
	degTwo += rot*dir;
	line (ptX+fromCenter,ptY,ptX+fromCenter+length,ptY);
	//rect (ptX-1,ptY-length-fromCenter-1,2,length+2); 
	pop();
}

function mousePressed (){
	//increase distance of lines from center
	fromCenter += length + 10; 
	//increase length of lines
	length+=10;

	//if mouse clicked left of center draw counter clockwise
	if (mouseX<=width/2){
		dir = -1;
	}else if (mouseX>=width/2){
		dir = 1;
	}

	//if circle is complete set degree back to zero
	//this will let next row start where previous row ended for only white lines
	if (Math.abs(deg)>=360){
		deg = 0;  
	}


	//add one to clicked each time mouse pressed
	clicked += 1;
	
	//store x and y position for new center
	if (clicked==rows){
		cirSet = 1;
		mX = mouseX;
		mY = mouseY; 
	}

	//number of rows per circle changed on first click of each set
	if (clicked==1){
		//number of rows per circle set changes in depending
		//on the quadrant clicked in
		if (mouseX<=width/2 & mouseY<=height/2){
				rows = 3;
				//blue
				r = 255;
				g = 0;
				b = 0;
		}if (mouseX>=width/2 & mouseY<=height/2){
				rows = 4;
				//yellow
				r = 255;
				g = 255;
				b = 0;
		}if (mouseX>=width/2 & mouseY>=height/2){
				rows = 2;
				//green
				r = 128;
				g = 255;
				b = 0;
		}if (mouseX<=width/2 & mouseY>=height/2){
				rows = 6;
				//orange
				r = 255;
				g = 128;
				b = 0;
				
		}
	}

}