Recitation5: Imaginary Creature

Title: eyes in dark

Link: https://editor.p5js.org/LafouCC/sketches/Jms6bbfVE

Description: My inspiration partly came from the movie My Neighbor Totoro. I draw the Susuwatari in my code as the first creature. And then I draw a second creature—a bunny because I like bunnies very much. Making the bunny flip its ears making it cuter. Also, the idea of switching the light on and off is because the color of the Susuwatari is black making me want to change the background and make the picture look like a pair of eyes floating in the dark.

Video: 

 

 

Code Snippets:

One problem I encountered is how to make the bunny_ear rotate in the opposite direction by changing the parameter of the defined function.

method 1: change the paramater so the angle is increasing/decreasing.

let s=1;
let i=0;
function one(angle, direction) {
  // display the ellipse
  push();
  rotate(angle + i * direction);
  ellipse(100, 0, 100, 50);
  pop();

  // update the angle
  i += s * 0.5;
  if (abs(i) >= 15) {
    s *= -1;
  } 

method 2: utilize sin():

function one(angle, speed, range) {
  // get the desired rotation angle
  let rotAngle = angle + sin(frameCount * speed) * range;

  // display the ellipse
  push();
  translate(0,50);
  rotate(rotAngle);
  ellipse(100, 0, 100, 50);
  pop();
} 

Reflections:

  • Describe what values were stored in the array(s) and how you utilized them. Share your experience while using the array(s).

I used arrays to generate a color palette and stored multiple dark colors in it. Then I generate a random index number to call a random color from the array.

  • Explain when/why translate(), push() and pop().

Using translate means you can change the original point and therefore can change the rotation point. So when you use rotate(), it is normally necessary to use translate(). Also, using translate() can simplify the position calculation. 

Using push() and pop() means declaring a new state. It is essential because sometimes we don’t want accumulative functions to ruin our code.

  • What is the effectiveness of User-Defined Functions?

User-defined functions can make our code looks neater and therefore easier for others to read. Also, it can be called many times with different parameters greatly simplifying our code. And sometimes it can also return a value to be used later on.

  • What parameters did you add to your functions? How were they manipulating the effects of the functions?

The first kind I add is the position of the “creature” with the help of translate(). The second kind is the initial angle, moving speed, and moving range of the buuny_ear. 

  • Are you able to identify methods/processes in your programming that are radically changed because of the uses of the functions you defined?

First, my code looks neater. Second, I can easily call my defined functions to draw similar things like the left and the right ear without writing the code twice. Third, I can easily change the position, and the initial angle by changing the parameters of my defined functions.

 

Leave a Reply

Your email address will not be published. Required fields are marked *