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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bfowlkes@gmail.com

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

    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

  • osmium

    #2
    Re: [New to C] Creating a simple animation using C.

    <bfowlkes@gmail .com> wrote:
    [color=blue]
    > 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.[/color]

    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.


    Comment

    • santosh

      #3
      Re: Creating a simple animation using C.

      bfowlkes@gmail. com wrote:[color=blue]
      > 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.[/color]

      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.

      Comment

      • osmium

        #4
        Re: [New to C] Creating a simple animation using C.

        "osmium" wrote:
        [color=blue]
        > 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.[/color]

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


        Comment

        • Jordan Abel

          #5
          Re: Creating a simple animation using C.

          On 2006-03-25, santosh <santosh.k83@gm ail.com> wrote:[color=blue]
          > bfowlkes@gmail. com wrote:[color=green]
          >> 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.[/color]
          >
          > 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.[/color]

          Especially given that \f rarely actually does anything.

          Comment

          • Richard G. Riley

            #6
            Re: [New to C] Creating a simple animation using C.

            On 2006-03-25, bfowlkes@gmail. com <bfowlkes@gmail .com> wrote:[color=blue]
            > 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[/color]
            show

            0, 00 --> 36 :-; 38 numbers.
            [color=blue]
            > 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
            >[/color]

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

            This FAQ gives some background and discussion for frequently encountered problems with the ncurses library, the terminal database and applications.


            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!

            Comment

            • Rod Pemberton

              #7
              Re: [New to C] Creating a simple animation using C.


              <bfowlkes@gmail .com> wrote in message
              news:1143312277 .323568.66010@i 39g2000cwa.goog legroups.com...[color=blue]
              > 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.
              >[/color]

              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,3 6); /* set l and r to spaces */
              memset(r,0x20,3 6);

              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


              Comment

              • osmium

                #8
                Re: [New to C] Creating a simple animation using C.

                "Rod Pemberton" writes:
                [color=blue]
                > 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.[/color]

                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.


                Comment

                Working...