# Program: a small ball in a window

I need a program which shows a simple ball on the screen, just a ball.
Its position must be defined by (x,y) coordinates.I mean I would be able
to play with (x,y) in order to change the position.

P.S.: it is NOT my homework, I just need this piece of code to go
further.

Teodor C. wrote:

I need a program which shows a simple ball on the screen, just a ball.
Its position must be defined by (x,y) coordinates.I mean I would be able
to play with (x,y) in order to change the position.

P.S.: it is NOT my homework, I just need this piece of code to go
further.

Take a look at the SFML - Simple and Fast Media Library. It can most
Or… Did you mean in Ruby? Do you want it text-based or graphics-based?
Should we choose for you the graphics library which will determine the

look: I study C/C++ in the college, but Ruby I study by myself, I want
to write a first course program in Ruby(it was a C code of a shell
trajectory, launched by user’s speed and angle). I’ve already written
the program in Ruby, it calculates the shell position at every period of
time.The output looks like

give angle(degrees):
45
give speed(km/h)
150
0.785398163397448
flight trajectory:
x=106.066017177982 y=101.166017177982
x=212.132034355964 y=192.532034355964
x=318.198051533946 y=274.098051533946
x=424.264068711928 y=345.864068711929
x=530.330085889911 y=407.830085889911
x=636.396103067893 y=459.996103067893
x=742.462120245875 y=502.362120245875
x=848.528137423857 y=534.928137423857
x=954.594154601839 y=557.694154601839
x=1060.66017177982 y=570.660171779821
x=1166.7261889578 y=573.826188957803
x=1272.79220613579 y=567.192206135786
x=1378.85822331377 y=550.758223313768
x=1484.92424049175 y=524.52424049175
x=1590.99025766973 y=488.490257669732
x=1697.05627484771 y=442.656274847714
x=1803.1222920257 y=387.022292025696
x=1909.18830920368 y=321.588309203678
x=2015.25432638166 y=246.35432638166
x=2121.32034355964 y=161.320343559642
x=2227.38636073762 y=66.4863607376246
x=2333.45237791561 y=-38.1476220843933

ok, now I need to make it “alive”. In C/C++ I can, but in Ruby, I have
no idea.
Therefore I need a piece of code which creates a window and point a
ball(it will be the shell). Any ideas?

Teodor C. wrote:

look: I study C/C++ in the college, but Ruby I study by myself, I want
to write a first course program in Ruby(it was a C code of a shell
trajectory, launched by user’s speed and angle). I’ve already written
the program in Ruby, it calculates the shell position at every period of
time.
Therefore I need a piece of code which creates a window and point a
ball(it will be the shell). Any ideas?

“ruby game library” will be a useful google search, you’ll find
libraries like:

On 12/11/2009 10:13 AM, Teodor C. wrote:

I need a program which shows a simple ball on the screen, just a ball.
Its position must be defined by (x,y) coordinates.I mean I would be able
to play with (x,y) in order to change the position.

P.S.: it is NOT my homework, I just need this piece of code to go
further.

If you’re ok with flash (or js) you’ll probably get lots of headway fast
with haXe. Try this tutorial:
http://www.derepas.com/fabrice/haxe/

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

I need a program which shows a simple ball on the screen, just a ball.
Its position must be defined by (x,y) coordinates.I mean I would be able
to play with (x,y) in order to change the position.

P.S.: it is NOT my homework, I just need this piece of code to go
further.

Google Code Archive - Long-term storage for Google Code Project Hosting. should get you started
nicely.

martin

Thanks to all! hope it will help. and it’s better than getting the code

2009/12/11 Teodor C. [email protected]

## Thanks to all! hope it will help. and it’s better than getting the code already done. Cheers!

Posted via http://www.ruby-forum.com/.
Also you find many examples of graphic programming using Ruby and Shoes
here

Teodor C. wrote:

actually, I kannot comment the code between lines 6 and 14. I just knew
I had to insert it into my main code and add #include<graphics.h> and my
program will work.

Hmm, that’s a new API to me. Googling around suggests it’s part of Turbo
C++, possibly BGI:

In principle there’s no reason why someone couldn’t write a ruby binding
for BGI, but I can’t find one. So I think you’ll need to look at some of
the alternatives. See
http://wiki.github.com/rdp/ruby_talk_faq/ruby-gui-toolkit-comparison

Teodor C. wrote:

ok, now I need to make it “alive”. In C/C++ I can, but in Ruby, I have
no idea.

What library did you use in C/C++ to draw the graphics? You may find
that there’s a Ruby binding to the same library, so you won’t have to
learn a new API.

Brian C. wrote:

Teodor C. wrote:

ok, now I need to make it “alive”. In C/C++ I can, but in Ruby, I have
no idea.

What library did you use in C/C++ to draw the graphics? You may find
that there’s a Ruby binding to the same library, so you won’t have to
learn a new API.

well, take a look, it’s a bit of code I needed to use to initialize
graphics mode(I’ve used Borland 3):

0 #include <stdio.h>
1 #include <conio.h>
2 #include <stdlib.h>
3 #include <graphics.h>
4 int main(){
5 //initializing graphics mode
6 int gdriver=DETECT, gmode, errorcode;
7 initgraph(&gdriver, &gmode, “C:\Progra~1\BORLANDC\BGI”);
8 errorcode = graphresult();
9 if(errorcode!=grOk) {
10 cout<<“Graphics error!!!\n”
11 <<“Press any key…”;
12 getch();
13 exit(1);
14 }
15 /*
16 AND HERE IS BLA-BLA-BLA CODE OF MY PROGRAM(let’s say: a square on
the 17 screen, which changes its color, every time you hit “Enter”)
18 */
19 return 0;
20 }

actually, I kannot comment the code between lines 6 and 14. I just knew
I had to insert it into my main code and add #include<graphics.h> and my
program will work. I thought there is smth like that in Ruby, and I have
just to insert it into my code, look the posts above…