30 Sep 2007CPOL
This article describes how to create a simple user-drawn form which moves over the desktop
Introduction
Oct 22, 2014 C program for animating a bouncing ball. Check this for program code: The loop control variable 'i' is used as angle. I've successfully been able to get a ball moving in a sinus-curve, and change color at different locations of the window. But I have no idea about how I can get the ball to bounce. Jul 24, 2012 This entry was posted in C# and tagged Bouncing Ball on July 24, 2012 by Renjith. Post navigation ← Bitblt and Stretchblt in MFC A simple program using pointers →.
When I first started with C#, I thought about what I could do. This simple example came to my mind, as it is done in some different places, e.g. like the Direct X Browser. I just redid that and added some gravity and transparency.
Steps
1. Creating a Way to Display the Ball
We somehow need to display the ball/box we want to bounce around. One of the easiest ways is to create a new form, set its border style to none and draw it yourself.
- I am new to Java. I started to learn by creating a bouncing ball GUI. I have managed to do all i wanted to do with it except one thing. I can't get the ball to change its color.
- Sep 12, 2015 Computer Graphics Program For Bouncing Ball in c programming. This is a computer graphics animation program for bouncing ball in c programming using graphics.h.showing the up and down movement of.
2. Making the Ball Move
For moving the ball, I used my own Application loop, but you might as well just create a timer calling an
OnTick
method.We move our ball by having two Vectors: The first one for the current position, the second one for the velocity.
3. Making the Ball Bounce
As a wall we will use the borders of the desktop; for the collision, simply check if the position of the ball exceeds them.
I decrease both movement variables to create a more realistic movement, as a ball normally wouldn't bump endless times because of the friction.
4. Making the Ball Bounce Again after Standing Still
As we added friction, the ball will stand still after some time. Therefore we just give it another kick to let it start again.
![Changing Color Of Bouncy Ball Dev C+ Reddit+ Changing Color Of Bouncy Ball Dev C+ Reddit+](/uploads/1/2/6/0/126089742/595958744.jpg)
Note: As the ball also stands still when being at the top of the screen, we check if the ball is at the bottom of the desktop before bouncing it.
Other Changes
You may get some neat results by changing the physical properties like gravity/friction/speed ...
History
- 30th September, 2007: Initial post