Re: setPixel
- Posted by Brian Broker <bkb at CNW.COM> Feb 03, 2000
- 388 views
Plotting the path of a projectile... I will give you some psuedocode so as not to take the fun out of your programming experience. variables: v = initial velocity a = initial angle from horizon vx = initial velocity in x direction vy = initial velocity in y direction t = time g = gravity ( tweak this value for whatever looks best ) vx = v * cos( a ) = a constant value (assuming no friction/wind) vy = v * sin( a ) - g*t as time (t) advances from zero, your object will be at: x = v * cos( a ) * t y = v * sin( a ) * t + g*t*t / 2 use the above equations to plot points as long as they are on the screen: t = 0 x = initial x value y = initial y value while (x < MAX_X ) and (y < MAX_Y ) do x = v * cos( a ) * t y = v * sin( a ) * t + g*t*t / 2 plot( x, y ) t = t + 1 --(or t = t + time_increment) end while Keep in mind that Euphoria trig functions expect values in radians, not degrees. To convert from degrees to radians, use: r = d * PI / 180 where r = value in radians and d = value in degrees hope this helps! -- Brian