ball falling due to gravity
Author |
Message |
baby_bubblz
|
Posted: Sun Apr 03, 2005 12:52 pm Post subject: ball falling due to gravity |
|
|
hey, i'm having trouble on how to do this program, so if anyone could help it'd be great..thanks!
Draw a ball in motion starting at the top of the screen so that its center moves to the position it would move to under gravity in each step of the animation. The equation for the y-coordinate of the center is
y = ymax - (1/2) * a * t **2
where a is the acceleration of gravity, namely 32 m sec - 2, and t is the time in seconds. If each pixel is in the y-direction represents 1 meter choose an appropriate time scale to watch the motion : in real time, in slow motion, and in time lapse motion.
------------------------
this is what i have so far:
var y:int:=ymax
for i: 1.. 10
y:=ymax-9.8
drawfilloval(100,y,10,10,blue)
delay(1000)
cls
end for
but i don't know how to incoporate the equation y = ymax - (1/2) * a * t **2 and whether of not y should be declared an interger or real |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Drakain Zeil
|
Posted: Sun Apr 03, 2005 2:09 pm Post subject: (No subject) |
|
|
You should use real numbers, but round them after calculations to integers for pixel-use.
I think the problem you're having is that you're working with one-direction, not two. Unless you've done something I didn't see, your ball should move down, but only down.
edit: I had some stuff here, it was wrong physics, disregard it if you saw it. |
|
|
|
|
|
lordofall
|
Posted: Sun Apr 03, 2005 3:25 pm Post subject: Re: ball falling due to gravity |
|
|
baby_bubblz wrote: this is what i have so far:
var y:int:=ymax
for i: 1.. 10
y:=ymax-9.8
drawfilloval(100,y,10,10,blue)
delay(1000)
cls
end for
but i don't know how to incoporate the equation y = ymax - (1/2) * a * t **2 and whether of not y should be declared an interger or real
code: | var y:real
for i: 1.. 10
y:=maxy-9.8*i**2
drawfilloval(100,round(y),10,10,blue)
delay(1000)
cls
end for |
i am assuming this is a ball in freefall so it would only be going down so basically.
issue 1) ymax doesn't exist its maxy =^D and that gives you the height of the screen starting the ball at the top
issue 2)y := maxy- 9.8 doesn't incorporate time so the ball would be stationary the whole time,
if we let i = time the for loop draws the ball every second(the delay) and the formula
y:=maxy-9.8*i**2 calculates the height after every second
issue 3) y is a real to be accurate so we round it because the y in a picture must be an integer.
and your done!
btw
d = v1t + 1/2at^2
so in that equation
y =d
v1 =0
so y = (top spot)- 1/2at^2 so the equation works out. |
|
|
|
|
|
Carino
|
Posted: Sun Apr 03, 2005 4:06 pm Post subject: (No subject) |
|
|
You could use the equations of motion, or you could use something like this, which is what i prefer.
code: |
setscreen ("offscreenonly")
var x, y, newy, gravity : real
x := maxx div 2
y := maxy - 50
newy := -5
gravity := 0.8
loop
y += newy
newy -= gravity
if y < 0 then
y := maxy - 50
newy := -5
end if
drawfilloval (round (x), round (y), 10, 10, red)
View.Update
delay (1)
cls
end loop
|
|
|
|
|
|
|
|
|