[New to C] Creating a simple animation using C.

B

bfowlkes

Hi,

I am new to the C programming language and programming in general. I am
writing a simple roulette program. I have everything working so far but
it seems a little plain. What I would like to do, but I have no idea
how to do, would be to create a simple animation each time the roulette
wheel is spun. Something like this.


1 2 3 4 5 6 7 8 9 10 11
31 12
30 13
29 14
28 15
27 16
26 17
25 24 23 22 21 20 19 18

Well it would actually be number 1 -36, but it is good enough to show
what I want to accomplish. Basically I would like to have brackets []
spin around the numbers 3 or 4 times and then finally stop on a random
number. I dont have access to the C graphics library, its not a school
assignment, but actually a work assignment, we are in training. I would
appreciate any help in any form.

Thanks
 
O

osmium

I am new to the C programming language and programming in general. I am
writing a simple roulette program. I have everything working so far but
it seems a little plain. What I would like to do, but I have no idea
how to do, would be to create a simple animation each time the roulette
wheel is spun. Something like this.


1 2 3 4 5 6 7 8 9 10 11
31 12
30 13
29 14
28 15
27 16
26 17
25 24 23 22 21 20 19 18

Well it would actually be number 1 -36, but it is good enough to show
what I want to accomplish. Basically I would like to have brackets []
spin around the numbers 3 or 4 times and then finally stop on a random
number. I dont have access to the C graphics library, its not a school
assignment, but actually a work assignment, we are in training. I would
appreciate any help in any form.

This is not terribly easy. You have no signficant control over the screen
without supporting libraries or an API, such as Windows. It appears you are
using Windows so you can clear the screen using the system() function. Then
completely redraw the entire screen; with reasonable luck it might not even
blink. Store the data in a two-dimensional array. Look at the clock()
function to control the repainting process, rand() to get the chosen number,
and the DOS function cls to clear the screen. It might be kind of neat to
have the brackets move slower and slower as time goes by.

Kind of a clever idea and sounds like a lot of fun to me!

Figure on a few months of learning curve to learn to use Windows to do this
properly.
 
S

santosh

Hi,

I am new to the C programming language and programming in general. I am
writing a simple roulette program. I have everything working so far but
it seems a little plain. What I would like to do, but I have no idea
how to do, would be to create a simple animation each time the roulette
wheel is spun. Something like this.


1 2 3 4 5 6 7 8 9 10 11
31 12
30 13
29 14
28 15
27 16
26 17
25 24 23 22 21 20 19 18

Well it would actually be number 1 -36, but it is good enough to show
what I want to accomplish. Basically I would like to have brackets []
spin around the numbers 3 or 4 times and then finally stop on a random
number. I dont have access to the C graphics library, its not a school
assignment, but actually a work assignment, we are in training. I would
appreciate any help in any form.

Such type of random console access is not supported by standard C. You
*might* be able to hack something with the carriage return (\r),
backspace(\b) and form feed (\f) escape sequences with printf(), but in
this case I doubt it's doable.

Your simplest course is to research the non-standard extensions
provided with your standard C library, (most of the popular hosted ones
do). Functions like clrscr(), gotoxy() etc. can help you do this. If
not, the API of your OS should also have console control routines that
will do the job.

It's best to ask in a newsgroup specific to the OS under which your
developing this program. In comp.lang.c, we only discuss standard C.
 
O

osmium

osmium said:
Look at the clock() function to control the repainting process, rand()
to get the chosen number, and the DOS function cls to clear the screen.

DOS *command* for the green eyeshade set ....
 
J

Jordan Abel

Hi,

I am new to the C programming language and programming in general. I am
writing a simple roulette program. I have everything working so far but
it seems a little plain. What I would like to do, but I have no idea
how to do, would be to create a simple animation each time the roulette
wheel is spun. Something like this.


1 2 3 4 5 6 7 8 9 10 11
31 12
30 13
29 14
28 15
27 16
26 17
25 24 23 22 21 20 19 18

Well it would actually be number 1 -36, but it is good enough to show
what I want to accomplish. Basically I would like to have brackets []
spin around the numbers 3 or 4 times and then finally stop on a random
number. I dont have access to the C graphics library, its not a school
assignment, but actually a work assignment, we are in training. I would
appreciate any help in any form.

Such type of random console access is not supported by standard C. You
*might* be able to hack something with the carriage return (\r),
backspace(\b) and form feed (\f) escape sequences with printf(), but in
this case I doubt it's doable.

Especially given that \f rarely actually does anything.
 
R

Richard G. Riley

Hi,

I am new to the C programming language and programming in general. I am
writing a simple roulette program. I have everything working so far but
it seems a little plain. What I would like to do, but I have no idea
how to do, would be to create a simple animation each time the roulette
wheel is spun. Something like this.


1 2 3 4 5 6 7 8 9 10 11
31 12
30 13
29 14
28 15
27 16
26 17
25 24 23 22 21 20 19 18

Well it would actually be number 1 -36, but it is good enough to
show

0, 00 --> 36 :-; 38 numbers.
what I want to accomplish. Basically I would like to have brackets []
spin around the numbers 3 or 4 times and then finally stop on a random
number. I dont have access to the C graphics library, its not a school
assignment, but actually a work assignment, we are in training. I would
appreciate any help in any form.

Thanks

If you're not using windows you might consider ncurses : although this
is not standard c library.

http://invisible-island.net/ncurses/ncurses.faq.html#what_platforms

Alternatively you could put a seperate line out on each "tick" with your
"number window" moving along the line e.g

--*----------------------------------
---*---------------------------------
----*--------------------------------

etc and back again : possible subsititing "*" for the real number it
represents : not forgetting your newline to flush the output stream.

--*23*----------------------------------
---*04*---------------------------------

etc


Good luck!
 
R

Rod Pemberton

Hi,

I am new to the C programming language and programming in general. I am
writing a simple roulette program. I have everything working so far but
it seems a little plain. What I would like to do, but I have no idea
how to do, would be to create a simple animation each time the roulette
wheel is spun. Something like this.


1 2 3 4 5 6 7 8 9 10 11
31 12
30 13
29 14
28 15
27 16
26 17
25 24 23 22 21 20 19 18

Well it would actually be number 1 -36, but it is good enough to show
what I want to accomplish. Basically I would like to have brackets []
spin around the numbers 3 or 4 times and then finally stop on a random
number. I dont have access to the C graphics library, its not a school
assignment, but actually a work assignment, we are in training. I would
appreciate any help in any form.

You really only need one environment specific function to do this: a way to
move the cursor back to the same upper left corner of the box (look for
gotoxy()). Otherwise, this can be done in K&R, ANSI, ISO C. This is a
rough _outline_ partially in C.

int main(void)
{

unsigned char l[37],r[37]; /* using 1-36, plus one */
int paren; /* number to wrap paren's around */

/* loop or loops for "ball" rotation */
{
/* non-standard function, like gotoxy(), to set upper left of box */
memset(l,0x20,36); /* set l and r to spaces */
memset(r,0x20,36);

paren=2; /* number 2 gets the "ball" paren's */
l[paren]='[';
r[paren]=']';

/* a bunch of more complete printf's in the format of the box */
/* %c format specifier for spaces or brackets */
printf(" %c%1%c %c%2%c\n", l[1],r[1], l[2],r[2]);
}
}


Rod Pemberton
 
O

osmium

Rod Pemberton said:
You really only need one environment specific function to do this: a way
to
move the cursor back to the same upper left corner of the box (look for
gotoxy()). Otherwise, this can be done in K&R, ANSI, ISO C. This is a
rough _outline_ partially in C.

I wrote and tested enough of what I proposed earlier to check it out. Works
fine, no sign of blinking or other ugly side effects. I cheated on the
timing and computed 1e6 sines instead of using some clock function. This
should work in any OS with minimal effort, only have to figure out how to
clear the screen.
 

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

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top