Graphics mode again

T

Teodor Carstea

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
 
B

brabuhr

Hi, all! here is my prog: it calculates the trajectory of a cannon shell: [...]
this is the output if speed=3D45km/h and angle=3D45 degrees

=A0give angle(degrees):
45
=A0give speed(km/h)
45
=A0convert degrees to radian:
0.785398163397448
=A0flight trajectory:
x=3D31.8198051533946 =A0y=3D26.9198051533946
x=3D63.6396103067893 =A0y=3D44.0396103067893
x=3D95.4594154601839 =A0y=3D51.3594154601839
x=3D127.279220613579 =A0y=3D48.8792206135786
x=3D159.099025766973 =A0y=3D36.5990257669732
x=3D190.918830920368 =A0y=3D14.5188309203678
x=3D222.738636073762 =A0y=3D-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
Google: ruby gnome canvas
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gnome+Canvas+Clock

Based on that:

#!/usr/bin/env ruby

require 'gnomecanvas2'

class Foozle < Gtk::Window
def initialize
super

@canvas =3D Gnome::Canvas.new(true)

@foozle =3D Gnome::CanvasEllipse.new(
@canvas.root,
{
:x1 =3D> 10, :y1 =3D> 20,
:x2 =3D> 30, :y2 =3D> 40,
:fill_color =3D> "white",
:eek:utline_color =3D> "steelblue",
:width_pixels =3D> 1
}
)

@canvas.show
add(@canvas)
end
end

Gtk.init()
Foozle.new.show
Gtk.main()

Draws a single ball on the screen.

There are of course (as others have pointed out) other libraries that
may be more or less suited to your needs.
 
T

Teodor Carstea

It works! As you said, a single ball on the screen.

Question 1: what kind of parameters a these:
:x1 => 10, :y1 => 10,
:x2 => 20, :y2 => 20,

is it a kind of width/height? which variables point to the center of da
ball,? I need it in order to manage its position using the coordinates.

Question 2:

what method like "repaint()" or "clrscr()" or "cleardevice()" could I
use in Ruby to make the ball dissappear?

Thanks a lot!
 
P

Paul Smith

It works! As you said, a single ball on the screen.

Question 1: what kind of parameters a these:


is it a kind of width/height? which variables point to the center of da
ball,? I need it in order to manage its position using the coordinates.

He already told you he used Gnome Canvas. He already showed you a
link he found from Google. I suggest you start doing some independent
research from here. You've been given many very good starting points.
What else do you want us to do, write the whole application for you?
Question 2:

what method like "repaint()" or "clrscr()" or "cleardevice()" could I
use in Ruby to make the ball dissappear?

Stop thinking in terms of your existing C++ graphics library.
Graphics does not work like that any more. Pick a graphics library to
use, and read up on it. This example was in Gnome. Join a Gnome
mailing list. Read tutorials on Gnome. Buy a book on Gnome. However
suits you.
 
B

brabuhr

It works! As you said, a single ball on the screen.

Question 1: what kind of parameters a these:


is it a kind of width/height? which variables point to the center of da
ball,? I need it in order to manage its position using the coordinates.

Assuming you had the center of the ball in instance variables @x and @y:

:x1 => @x - 5, :y1 => @y - 5,
:x2 => @x + 5, :y2 => @y + 5,
Question 2:

what method like "repaint()" or "clrscr()" or "cleardevice()" could I
use in Ruby to make the ball dissappear?

I don't know, that's the first ruby-gnome code I've written. Looking
at the clock example, I made a change:

#!/usr/bin/env ruby

require 'gnomecanvas2'

class Foozle < Gtk::Window
def initialize
super

@canvas = Gnome::Canvas.new(true)

@foozle = Gnome::CanvasEllipse.new(
@canvas.root,
{
:x1 => 10, :y1 => 20,
:x2 => 30, :y2 => 40,
:fill_color => "white",
:eek:utline_color => "steelblue",
:width_pixels => 1
}
)

@canvas.show
add(@canvas)

Gtk::timeout_add(1000) { @foozle.x1-=5; true }
Gtk::timeout_add(1100) { @foozle.y1-=5; true }
Gtk::timeout_add(1200) { @foozle.x2+=5; true }
Gtk::timeout_add(1300) { @foozle.y2+=5; true }
Gtk::timeout_add(9000) { @foozle.hide }
end
end

Gtk.init(); Foozle.new.show; Gtk.main()
 
T

Teodor Carstea

What else do you want us to do, write the whole application for you?

Of course not. I'm gonna do it by myself. Well, I understand this forum
is not for newbies. "Stop asking stupid questions" is that you mean? No
problem, I'll be back when I'm smarter.
 
T

Teodor Carstea

to unknown (Guest)

yeah! THANKS! By the way, I've made several tests, you don't need x2 and
y2 at all to draw a single ball.

And... err.. I think there IS something like "repaint", because the
clock moves its pointers, example:they dissappear at 12:00 mark and
appear at 12:01. I'll find it. I'll be looking for more documentation
upon this.

thanks again!
 
M

Marnen Laibow-Koser

Teodor said:
Of course not. I'm gonna do it by myself. Well, I understand this forum
is not for newbies. "Stop asking stupid questions" is that you mean? No
problem, I'll be back when I'm smarter.

This forum *is* for newbies -- but only newbies who take the initiative
to do independent research and experimentation. Please do come back
when you're ready to do that.

Meanwhile, read this:
http://www.catb.org/~esr/faqs/smart-questions.html

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
(e-mail address removed)
 
B

brabuhr

to unknown (Guest)

yeah! THANKS! By the way, I've made several tests, you don't need x2 and
y2 at all to draw a single ball.

And... err.. I think there IS something like "repaint", because the
clock moves its pointers, example:they dissappear at 12:00 mark and
appear at 12:01. I'll find it. I'll be looking for more documentation
upon this.

thanks again!

Sure. Here's a bit better example, I think:

gnome_canvas_ball.rb
require 'gnomecanvas2'

class GnomeCanvasBall
def initialize(canvas, x, y, radius)
@canvas, @x, @y, @radius =
canvas, x, y, radius

@ellipse = Gnome::CanvasEllipse.new(
@canvas.root,
{
:x1 => @x - @radius, :y1 => @y - @radius,
:x2 => @x + @radius, :y2 => @y + @radius,
:fill_color => "white",
:eek:utline_color => "steelblue",
:width_pixels => 1
}
)
end

def show; @ellipse.show; end
def hide; @ellipse.hide; end

def x=(val)
@x = val
@ellipse.x1 = @x - @radius
@ellipse.x2 = @x + @radius
end
def y=(val)
@y = val
@ellipse.y1 = @y - @radius
@ellipse.y2 = @y + @radius
end
end

foozle.rb
require 'gnome_canvas_ball'

class Foozle < Gtk::Window
def initialize
super

@canvas = Gnome::Canvas.new(true)

@foozle = GnomeCanvasBall.new(
@canvas, 50, 50, 10
)

@canvas.show
add(@canvas)

signal_connect_after('show') { start }
signal_connect_after('hide') { stop }
signal_connect("delete_event") { Gtk::main_quit }
end

def start
@tid= Gtk::timeout_add(1000) {
@foozle.x = rand(100)
@foozle.y = rand(100)
true
}
end
def stop
Gtk::timeout_remove(@tid) if @tid; @tid = nil
end
end

Gtk.init(); Foozle.new.show; Gtk.main()
 
T

Teodor Carstea

Marnen said:
This forum *is* for newbies -- but only newbies who take the initiative
to do independent research and experimentation. Please do come back
when you're ready to do that.

Meanwhile, read this:
http://www.catb.org/~esr/faqs/smart-questions.html

thank you, I realy apreciate that! Vrey useful link... All my life I had
to follow rules(including stupid ones), and now you give me another
ones. But it's ok, as I am a programmer, I have PLENTY of FREE time to
read that staff. I'll do it.
 
P

Paul Smith

Of course not. I'm gonna do it by myself. Well, I understand this forum
is not for newbies. "Stop asking stupid questions" is that you mean? No
problem, I'll be back when I'm smarter.

You haven't asked a stupid question. That's not what offends me.
What offends me is that you've been given several good answers,
ignored them, and asked the same question.

You were given a code example with

:x1 =3D> 10, :y1 =3D> 10,
:x2 =3D> 20, :y2 =3D> 20,

and asked - "What kind of parameters are these? Are they a width/height?"

I don't know anything about Gnome Canvas. But, I do know that if I
google for what parameters CanvasEllipse and Canvas.root takes I can
probably figure it out. I also know that they're numbers, and I can
reason from there that if I change the number 10 to 15 or 20,
something on the screen will change. I know that's it's quicker to
change a 10 into a 15 and run it than to ask a mailing list what will
happen.

If I change my 10 into a 15 and nothing happens, I'll write to the
mailing list and ask why. If I try to google for the meaning of the
parameters and can't find anything, I'll ask specifically to be
pointed to the GnomeCanvas documentation please.

Do your own work, and ask the mailing list when you've tried to do it
yourself and failed. Give yourself the chance to figure it out
yourself. Don't make us feel like we're doing the job for you by
asking questions before you've tried them yourself.

I think I've overstated my point now.
--=20
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)
 
T

Teodor Carstea

Come on everybody! Stop answering to my questions! Enough! Please!
Stop posting sugestions about what I did and what should I do! OK!I got
it!
don't reply to this post! aufwiedersehen!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top