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

A short expert summary and practical pointers that extend the replies from , and .

graphics.h comes from the old Borland BGI system and is effectively legacy/DOS-era tooling; it is fine for learning but not for building portable, accelerated animation today. See Borland Graphics Interface (BGI). (en.wikipedia.org)
(BGI reference: Borland Graphics Interface (BGI).)

For a simple 2D waving-flag effect on modern toolchains, use a library that exposes textured vertex geometry or shaders (instead of immediate-mode pixel drawing). Libraries like SFML or SDL give easy windowing + textures and let you build a textured vertex mesh or use a shader for the deformation. The SFML vertex-array/texturing approach is a good, simple fit. (sfml-dev.org)
(SFML vertex-array tutorial: Designing your own entities with vertex arrays.)

Practical approaches (in increasing realism / complexity):

  • Fast and easy: render the flag as a textured mesh (grid of vertices) and offset vertex positions each frame with a sine function across the X axis; attenuate the offset near the flagpole so the pole area stays fixed. A tiny pseudocode example:
for each vertex at x:
  offset = A * sin(k*x + omega * time) * (1.0 - attachWeight*x)
  vertex.y += offset
draw textured triangles using the mesh

A classic OpenGL-style tutorial shows exactly this grid + sine technique for a flag wave. (nehe.gamedev.net)
(Example tutorial: NeHe — flag waving / waving texture.)

If a more physically plausible result is required, implement a mass–spring (or position-based) cloth simulator: a grid of particles connected by springs, simple integration (Verlet or semi-implicit), iterative constraint projection (to prevent over-stretch), damping, and fixed vertices at the pole. That is the standard approach used in real-time cloth systems. (en.wikipedia.org)
(Background: Soft-body dynamics / cloth simulation.)

Implementation notes / gotchas: keep a fixed timestep for simulation, run a few solver iterations per frame for stability, reduce mesh resolution for speed, and render with double buffering / vsync to avoid flicker and tearing. (en.wikipedia.org)
(Background: Multiple buffering / double buffering.)

These pointers follow /’s advice about moving off archaic headers, while giving concrete, low-effort techniques ( can start with the sine-mesh method) and a path toward a physics-based solution if higher realism is needed.

Recommended Answers

All 3 Replies

Why would you want to create an animation with graphics.h which is a very old and deprecated library?

Anyway here's a thread with a similar problem that talks about how the flag should have a wave like motion
-->link to said thread

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.

Thread closed as it is double post, please follow discussion here

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.