1/9/2024 0 Comments Gravity lab simulation(This was a problem in early PC computer games: the game would draw as many frames as possible per second on the computer the game was written on. So if draw_frame is called 60 times per second, instead of 20, the ball will move three times as fast. The problem with increasing the frame rate is that each time draw_frame is called, the ball moves a constant amount: y = y + v_y ![]() But my computer is fast enough to easily draw 60 frames per second. In the last example, we drew frames at a rate of 20 frames per second. I’d like to make the animation a bit smoother. Because you have already written the pong game in Lab Assignment 1, you should be able to understand quite easily the code to make the ball bounce off the floor and ceiling. The sign of each component (+ or –) will tell us the direction in each component.Īt this point in the course, you’ve done a couple of animations, so you can probably figure out how this program works. Our program will keep track of the velocity, which we decompose into horizontal ( x) and vertical ( y) components. If you’ve ever seen vectors, you’ll recognize velocity as a vector and speed as the magnitude of the velocity. So “55 miles per hour” is a speed, and “heading northeast at 55 miles per hour” is a velocity. Velocity combines speed with a direction. Speed says how fast an object is moving, but it says nothing about the direction in which it’s moving. I’ll start with just making the ball move up and down at a constant speed.īefore we get to the program, a note about physics definitions. Having identified all those issues, I admit to myself that I’m just not clever enough to solve all those subproblems at once.Here’s something I can handle. How fast should the simulation be, what are the units to use, and do I know the gravitational constant measured in units of pixels/sec 2 (pixels per second-squared)? ![]() It’s a complicated problem: I have to take into account acceleration due to gravity, keeping track of positions and velocities, a floor and walls that the ball will bounce off of, and some graphics to draw as well. I would like to write a program to make a ball bounce on the screen under the influence of gravity. This lecture will go over the Newtonian physics you’d need, and give techniques for simulating those physics with a computer program. For example, you could write your own simulator for celestial bodies, and use that simulator to explore the motion of the solar system, as well as of the earth and moon. One of the more interesting things you can do with a computer is to write a program based around a simple physical law, such as f = m × a (force equals mass times acceleration), and use that program to see the complex and beautiful behavior of a physical system.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |