Week 5: Functions

This week was the perfect week to return to my week 2 mission. Three weeks ago I couldn't get to the result I desired so I thought that now, with an extra three week knowledge I can solve it. So this was the sketch:

The original plan was to animate the shapes movement and create the number 2020. First of all I started to reduce my code by writing one function for the 2 number and one function for the zero number.

The parameters that were different inside every function are the position and the colors of every number. Because I had 3 different colors for every number I initialized their values in the setup function.

Then I added the new parameters in to the function. It was completed! I wrote the same code - only now it was organized as two functions.

Now it was time to deal with the animation. I initialized a movement object in the setup function, then added as a parameter in the two and zero functions.

And then I added an if statement and added it to the shapes data. It took me a lot of time to understand what numbers need to be inside the if statement and even got really confused to which parameters I should add the new parameters

Eventually with a few guesses and help with the calculations it worked:

This is the result: https://editor.p5js.org/ds6298/sketches/JoHtGL2uH

8 views0 comments

Recent Posts

See All