Tony Wang
Developer
Tony Wang
Developer
This week we were introduced a more complicated part of p5js.
Last week I mentioned how the limitations on for loops and creating new functions in p5js had limited what I want to do using p5js.
First, for loops is a really useful tool. I have taken couple cse classes when I was still a cse major during my first college year, so the things that were talking seem really easy and familar to me.
When we use for loops, we need a initial variable, for example, "i", and assign it with a value, for example, 0, this is where we want the loop to start.
Then we need to assign a value that limit the number of times the loop iterates, say "i < 10", which would limit the loop to iterate 10 times if it starts at 0.
For example, I used a for loop and a really simple function and draw a circle for ten times.
With the for loop, each time it draws the circle, it moves the position of the circle 20 in the x direction.
And the function I created is just drawing a circle, but the x, as its parameter, is something to input when you call the function. The nice thing about javascript is that you do not need to say what type of the parameter it is.
It is relatively easy to use comparing to java, which I used the most before.
So with these functions, I think I am able to create a interesting game, creating my own functions and so on.