Worksheet

worksheet 1

https://editor.p5js.org/spss-ssps/full/gfIcFGBly

worksheet 2

https://editor.p5js.org/spss-ssps/full/4dzxfM_Rv

worksheet 3

https://editor.p5js.org/spss-ssps/full/MPtRp0eas

worksheet 4

https://editor.p5js.org/spss-ssps/full/2Evvu_MTA

sketch

For my sketch for this week I looked back on my flower week 2 sketch. I started by reworking the code by compiling it into distinctive functions:

function leaves
function petals
function fcenter

original sketch

original sketch

Along with this, since the code had a a few different variables that were used for the same purpose (moving individual petals up or down depending on if the mouse is pressed or not), I tried using the material on Objects explained in the videos/readings for this week.

let petPosY = [250, 150, 250, 150];

Something that I was struggling on was reseting the position and movement of the petals when going over or under the canvas height. Initially I tried something along the lines of this:

flower sketch practice with for loop and random feature

flower sketch practice with for loop and random feature

If (petPosY[0] > height && petPosY.[1] > height && petPosY.[2] > height && petPosY[3] > height) {
   petPosY[0] = height/2
   petPosY[1] = height/2
   petPosY[2] = height/2
   petPosY[3] = height/2
  } else if (
//...same as above put oposite
  }
 if (mouseIsPressed) {
    petPosY[0] -= random(0.5, 1.5);
    petPosY[1] -= random(1.5, 2.5);
    petPosY[2] -= random(1, 2);
    petPosY[3] -= random(0.5, 2);
  } else {
   //same as above but oposite

So, using the Array material from the video/reading, I tried using this:

  for (let i = 0; i < petPosY.length; i++) {
    if (mouseIsPressed) {
      petPosY[i] -= random(1, 3);
    } else {
      petPosY[i] += random(1, 3);
    }
    
    if (petPosY[i] > height) {
      petPosY[i] = height / 2 - 50;
    } else if (petPosY[i] < 0) {
      petPosY[i] = height / 2 + 50; 
    }
  }
}

Ver. 1

https://editor.p5js.org/spss-ssps/full/KKLUIBXbe

Ver. 2

https://editor.p5js.org/spss-ssps/full/JGtYoi5fS