I am a beginner to computer graphics and I have to add animations to the image of my national flag which look like this.

I have designed the flag alright.But I don't know what kinds of animations are possible and how.
Could someone please guide me how to add animations like fluttering and which functions/methods I should use to achieve them.
Any help will be greatly appreciated.
Also I am not looking/asking for complete code I am looking for pointers and guidance and any specific information that could be useful to me in this task .

Dani AI

Generated

Several replies already pointed you toward using a proper graphics environment and modern toolchain; those are prerequisites. For the visible effect you want (a fluttering flag) focus first on the animation algorithm itself, then map that algorithm onto whatever graphics API you choose. The simplest, highest-yield approaches are (a) per-column or per-vertex displacement (cheap and easy to start with), (b) a low-resolution mesh with bilinear interpolation (smoother), or (c) a displacement texture / shader on the GPU (best quality and performance for larger canvases). 's column-offset idea is a great starting point for a beginner because it is straightforward to implement and tune.

A minimal, runnable plan (conceptual): keep an offscreen pixel buffer of the flag image, compute a vertical offset for each column from a time-varying function (sum of sines + small noise for realism), copy each source column into the backbuffer shifted by that offset, then present the backbuffer. Example idea in C-style pseudocode:

/* width, height, src[] (original pixels), back[] (frame buffer) */
for (int x = 0; x < width; ++x) {
  float offset = A * sinf(k * x + omega * t + phase[x]); // precompute phase[] or table
  int dy = (int)offset;
  for (int y = 0; y < height; ++y) {
    int sy = y - dy;
    back[y*width + x] = (sy >= 0 && sy < height) ? src[sy*width + x] : background;
  }
}
swap_buffers();

Practical tips and troubleshooting: always render to a backbuffer then swap to avoid flicker; use delta time for consistent speed across machines; precompute a sine lookup table if CPU is tight; use bilinear sampling when shifting non-integer offsets to avoid jagged edges; add a small Perlin/simple noise term to break up purely periodic motion. Start with small amplitude and low frequency, then tune until the motion looks natural.

Tiebacks: follow the setup advice in earlier replies about using a supported toolchain, then implement the column/mesh approach above to validate the effect quickly. Once the basic motion looks right, consider interpolation or GPU-based displacement for higher quality and performance.

Recommended Answers

All 5 Replies

the image of my national flag which look like this.

was there supposed to be a link at the 'this'? ANSI C does not support graphics, maybe use the win32 API (tutorial here) or OpenGL (tutorial ).

graphics.h is not part of c or c++ standards, so very few compilers support it. On MS-Windows the only compilers I know about that use it are Turbo C, which is ancient and obsolete. If you want graphics on modern operating systems then you need to learn modern compilers. Turbo C is nice to use for just your own programming enjoyment, but don't expect anyone else in the world to use it.

If you want to create a program in C or C++ with graphics, you should first switch to a modern IDE (like Code::Blocks or Visual C++). From there, you should learn how to a library like OpenGL, SDL, DirectX, or something similar.

This sounds suspiciously like the problem Gourav1 posted last week. I provided an answer that should satisfy.

See his post here:
http://www.daniweb.com/software-development/c/threads/407089/1737797#post1737797

See my response here:
http://www.daniweb.com/software-development/c/threads/407089/1738493#post1738493

Gourav1's question was directed at text animation. However, a graphical solution could easily be adapted.
When drawing your image, draw by columns, and offset each column by a rotating value in an array.

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.