Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C (http://www.programmingforums.org/forum60.html)
-   -   help w/ bouncing ball and bitmaps code (http://www.programmingforums.org/showthread.php?t=11874)

josec Nov 14th, 2006 1:31 AM

help w/ bouncing ball and bitmaps code
 
Hi i need urgent help. I have to do a program of an animation of a ball bouncing against the wall and predetermined obstacles. My professor told me that i can write a program where the user can input the ball's speed from slow, medium or fast, choose which obstacles the user wants from predetermined ones and for how long the animation should go. then the program should create a series of images. then i will take these images and use a movie maker program to create the program. She told me to use a bitmap to acomplish this. however, I have no idea how to use a bitmap or how to start doing this program. can someone help out, and show me at least how to start just guide me and i'll figure out the rest. bu the way we are using unix to compile the program. and then the pics will be exported to windows to create the animation. thank you very much!!!

Game_Ender Nov 14th, 2006 1:37 AM

First you need to create some buffer that represents your screen and then some functions to draw what you want on that buffer. Then you make all your calculations and draw on buffer. After that write your buffer to file in the .bmp format. Repeat the calculate - draw - write-bmp sequence as needed.

See some information on bmp format here.

josec Nov 14th, 2006 1:42 AM

i'm sorry but what is a buffer and how do i create one? i forgot to mentioned that i am new in C, and even though i like C, my knowledge about it is very limited

DaWei Nov 14th, 2006 2:25 AM

While someone is amassing a lesson plan for you, please read the forum's rules/FAQ. Note in particular that cross-posting is not allowed.

Arevos Nov 14th, 2006 3:54 AM

A buffer is simply a temporary location in which to store data. In this case, the buffer can hold a single bitmapped frame of the bouncing ball animation. However, I honestly think you need to go over your professor's lectures, or ask for some help. It seems a tricky piece of programming for someone who's inexperienced.

sixstringartist Nov 14th, 2006 1:47 PM

From your response, you seems to be very new at C, in which this problem would be very difficult for you. Have you been attending/paying attension in class? Not trying to dog you, it just seems like you should have more tools at your disposal to solve this problem.

josec Nov 14th, 2006 2:02 PM

yeah i've payed attention in class and right now we just finished pointers. however, this porject is my final project and the professor wants us to do something that would challenge ourselves. so that's why i've been researching and looking around to ways to write this program.

Polyphemus_ Nov 14th, 2006 3:12 PM

Ok, use the buffer as told by other members to store your bitmap temporarily, and learn the structure of an image format like .bmp.

For the bouncing of the ball itself, recall your physics lessons you probably have had at school.

MBirchmeier Nov 14th, 2006 3:22 PM

Keep in mind a bitmap is a static image. Perhaps you're looking to create a bitmap, or perhaps you're looking to create an animation. If you're looking to animate you'd need a graphics library (e.g. openGL etc.) if you're just looking to take a snapshot of a scenario you could create a bitmap.

-MBirchmeier

Arevos Nov 14th, 2006 3:50 PM

Quote:

Originally Posted by MBirchmeier (Post 118915)
Keep in mind a bitmap is a static image. Perhaps you're looking to create a bitmap, or perhaps you're looking to create an animation.

It sounds like the task is to create a series of still frames that can then be compiled into an animation separately.
Quote:

Originally Posted by josec
yeah i've payed attention in class and right now we just finished pointers. however, this porject is my final project and the professor wants us to do something that would challenge ourselves. so that's why i've been researching and looking around to ways to write this program.

I'd start off simple, and build up. For instance, you could do this:

1. Create a program that reads in a text file and changes every other letter to an x. For instance, if you have a text file with "Hello World", your program would create a text file with "HxlxoxWxrxd".

2. Create a program that creates a series of text files in which an X moves horizontally across the page. e.g.
:

1.txt:
....
x...
....

2.txt:
....
.x..
....

3.txt:
....
..x.
....

4.txt:
....
...x
....


3. Expand the program in step 2 so that the ball moves diagonally around, bouncing off the edges when it reaches them.

4. Create a program that reads in a bitmap, and creates a new bitmap from it where every other pixel is set to black.

5. Create a program that reads in a bitmap, and displays a new bitmap from it with a black square in the middle.

6. Create a program that reads in a large bitmap and a small bitmap, and produces combination bitmap with the small bitmap in the centre of the large bitmap.

7. Expand exercise 6 to produce a series of bitmaps, where the smaller bitmap inches its way across the larger bitmap.

8. Create your final bouncing ball program.

Hope that helps!


All times are GMT -5. The time now is 1:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC