my teacher has told me to make a flag(India's national flag) in C using lines, bar and all. then fill colors. i have done this thing when i am writing this thread. now, he also told me now that the flag should look like as if it waving in the air means i have to do animation now according to him. will any one please tell me the basic idea that how to approach this ? means i am just a beginner in graphics.h lib. so just give me a way ho to proceed. i am not asking for ANY CODE FROM YOUR SIDE, I AM TELLING AT THIS TIME ONLY. help!!

You won't need animation -- just curved lines.
Check out this picture of a wavy flag.
...or this other picture

no, but he has said us to use the animation in that. ok! assume that he hasn't said animation. but i am asking that how to make effect that it will look that the flag is waving in air ?

Let's start with the basics.

You're going to print out a set of characters in an array on a screen.
You're going to jiggle the characters by a wavy function, let's say the sine function.
You're going to output in color. Each character in the array has a color assigned to it.
You will have to clear the screen or erase or write over every character so you don't have garbage left over when you do a drawing pass.
You're going to want to use a while loop that breaks on key press, but also increments a value that controls what vertical offset will be used.


Let's say we have a character array:

11111111
22222222
33333333
44444444
55555555

and we want it to look like

11   
 1221  
123321
23443211
34554322
45  5433
5    544
      55

(to be continued...)

Let's view this a little differently with the offsets at the top:

2|1|0|0|1|2|3|3
===============
 | |1|1| | | | 
 |1|2|2|1| | | 
1|2|3|3|2|1| | 
2|3|4|4|3|2|1|1
3|4|5|5|4|3|2|2
4|5| | |5|4|3|3
5| | | | |5|4|4
 | | | | | |5|5

So for this particular array, we would use an offset array of 2,1,0,0,1,2,3,3. The array has a length of 8.
The offset array repeats smoothly. That means we can leave the end of the offset array and start back from the beginning.
Your main loop could take the following form:

WHILE NOT KEYPRESS
    ClearScreen
    FOR I EQUALS 0 TO NumberOfColumns
       PrintColumn I with Offset = I + OffsetArray[OffsetIndex]
    Increment OffsetIndex By 1
    SET OffsetIndex = OffsetIndex MODULUS LengthOf(OffsetArray)
WEND

But all is not done. In addition to a character array, you need a color array. You can however cheat and simply use spaces instead of characters. This way, you'd only need a color array to set the background color and print a space for each "pixel" in the flag.

Let us know if you need further help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.