Hi, all! here is my prog: it calculates the trajectory of a cannon shell:
puts " give angle(degrees): "
angle = gets
puts " give speed(km/h)"
speed = gets
puts " convert degrees to radian: "
angle = angle.to_f * ((Math::PI)/180)
puts angle.to_s
#sticking da speed to axes:
xspeed = speed.to_f * Math.sin(angle.to_f)
yspeed = speed.to_f * Math.cos(angle.to_f)
time = 0
y=8
puts " flight trajectory: "
while y>0 do
time += 1
x = xspeed * time
y = yspeed * time-4.9*time**2
puts “x=”+x.to_s+" y="+y.to_s
end
this is the output if speed=45km/h and angle=45 degrees
give angle(degrees):
45
give speed(km/h)
45
convert degrees to radian:
0.785398163397448
flight trajectory:
x=31.8198051533946 y=26.9198051533946
x=63.6396103067893 y=44.0396103067893
x=95.4594154601839 y=51.3594154601839
x=127.279220613579 y=48.8792206135786
x=159.099025766973 y=36.5990257669732
x=190.918830920368 y=14.5188309203678
x=222.738636073762 y=-17.3613639262375
help me to see it, I mean, a graphic application (or console application), or >whatever… I want to see a shell flying on the screen. I am able to do it in
C++, but I wanna make it in Ruby, how can I use graphics mode?