Graphics mode again

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?

I can’t believe none can help me. Give me a punch, I can’t go on.

On Fri, Dec 4, 2009 at 8:37 AM, Teodor C. [email protected]
wrote:

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?

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 = Gnome::Canvas.new(true)

@foozle = Gnome::CanvasEllipse.new(
  @canvas.root,
  {
    :x1 => 10, :y1 => 20,
    :x2 => 30, :y2 => 40,
    :fill_color => "white",
    :outline_color => "steelblue",
    :width_pixels => 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.

On Fri, Dec 4, 2009 at 4:12 PM, Teodor C. [email protected]
wrote:

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.

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.

Thanks a lot!

Posted via http://www.ruby-forum.com/.


Paul S.
http://www.nomadicfun.co.uk

[email protected]

On Fri, Dec 4, 2009 at 11:12 AM, Teodor C.
[email protected] wrote:

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.

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",
    :outline_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()

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.

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!

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!

Teodor C. wrote:

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.

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
[email protected]

Marnen Laibow-Koser wrote:

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:
How To Ask Questions The Smart Way

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.

On Fri, Dec 4, 2009 at 12:11 PM, Teodor C.
[email protected] wrote:

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",
    :outline_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()

On Fri, Dec 4, 2009 at 5:02 PM, Teodor C. [email protected]
wrote:

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.

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 => 10, :y1 => 10,
:x2 => 20, :y2 => 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.


Posted via http://www.ruby-forum.com/.


Paul S.
http://www.nomadicfun.co.uk

[email protected]

Teodor C. wrote:

I can’t believe none can help me. Give me a punch, I can’t go on.

You might try HTML 5’s Canvas. Here are two good tutorials:

http://diveintohtml5.org/canvas.html
http://www.canvasdemos.com

and reference

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html

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!

Steve W. wrote:

Teodor C. wrote:

I can’t believe none can help me. Give me a punch, I can’t go on.

You might try HTML 5’s Canvas. Here are two good tutorials:

http://diveintohtml5.org/canvas.html
http://www.canvasdemos.com

and reference

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html

Some good working examples:

http://www.efeion.com/canvastest/balls1.js
http://js-fireworks.appspot.com/fireworks.js