Since we had a three day weekend and it was right after our hackathon, we didn't have much to do and I was pretty bored by today (Sunday). I decided to go to the awesome coffee shop a block away (Bennu!) and started to make an archery game. I wanted to do something visual (animation) and incorporate some physics into it so I thought projectile motion would be the easiest thing to start out with. We didn't really learn any animation stuff yet but it wasn't too difficult to figure out. Basically, this app allows you to enter the initial velocities in the x direction and the y direction (in meters per second) and when you click start, the arrow will make a parabola. In the x direction I didn't want to include drag (friction from the atmosphere) so I assumed that there was no negative acceleration slowing the arrow down. In the y direction, I incorporated gravity (-9.81 m/s^2). The kinetics equation I used was yposition = yvelocity * time + 0.5 * (-9.81 * time^2). The hardest part was converting the pixels into meters and choosing the most optimal dimensions. I settled on 1000px = 100 meters (so 10px per meter). Another difficulty was getting the time. I was using the Javascript function setTimeout which can be used in a function to call itself in a set interval. Here I chose every 10 milliseconds because I wanted the motion to look pretty smooth but I also didn't want it to make things more complicated. So for each second, the function to change the position of the arrow in both the x position and y position was called 100 times (1000 milliseconds in a second). I couldn't really find a simple function that just times things for you but I made one by defining a variable 'time' to start with the value 0, and incremented it by 0.01sec each time setTimeout would call the move arrow method. Anddd it works! The next step for me is to incorporate some type of scoring system but I need to do more reading on collisions so I'll save that for another day. One thing though, I started talking to a random kid this afternoon and he was interested in this mini project. I made him a collaborator on my github account and we finished around the same time and compared. He got the angles to correspond to the arch perfectly and didn't even use help from a single jQuery function. Well there goes my self-confidence... Gotta study more and get on his level!
*The first four slideshow pictures are mine and the last one with the pink background is his. The code is mine and is a screenshot of the javascript portion
*The first four slideshow pictures are mine and the last one with the pink background is his. The code is mine and is a screenshot of the javascript portion