Navigate

Thursday, February 16, 2017

TechIMPACT - Day 3

Today we started learning about variables. Variables are containers for information you want the computer to remember. They also make adjusting code and parameters a lot easier because everything you want to change ideally would be located in one place. 

The simple example we started with was making a circle move from one side of the screen to the other by incrementing it's X coordinate by one. We used that example to show how much easier it is to assign the circles coordinates using variables, and then we made it even simpler by listing all of the variables as keys belonging to one 'circle' object. 

From there, we were allowed to experiment in pairs. The first thing we wanted to figure out was how to make the circle bounce because in the original code, it would continue moving to the right indefinitely and it would no longer be visible on the screen. That certainly took a while to figure out, but I knew it needed a conditional statement to achieve the bounce. We figured out (with some help from GitHub) that the conditional statement needs to identify both the left and right boundaries of the canvas using an OR statement and then declare that the X value of the circle should change to its negative value...in plain English, once the circle hits the edge of the canvas, it reverses direction. From there the Y was easy and we got our circle to bounce around. We changed our circle to a square, added a random function to have it change color and played with the speed of movement to observe the types of patterns it made. Pretty cool even though this one little project took us 2 hours!



~ Lisa Lou

No comments:

Post a Comment

Let me know what you think....