0% found this document useful (0 votes)
21 views7 pages

Animation Techniques in Graphics Programming

Uploaded by

sayedzubia2211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Topics covered

  • User Interfaces,
  • Animation and Creativity,
  • Animation Development,
  • Computer Graphics,
  • Animation in Marketing,
  • Animation,
  • Animation and User Experience,
  • Animation Frameworks,
  • Animation Principles,
  • Animation and Software Develop…
0% found this document useful (0 votes)
21 views7 pages

Animation Techniques in Graphics Programming

Uploaded by

sayedzubia2211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Topics covered

  • User Interfaces,
  • Animation and Creativity,
  • Animation Development,
  • Computer Graphics,
  • Animation in Marketing,
  • Animation,
  • Animation and User Experience,
  • Animation Frameworks,
  • Animation Principles,
  • Animation and Software Develop…

EXPERIMENT NO.

10
AIM :- Perform Animation (such as Rising Sun, Moving
Vehicle, Smileys, Screen saver
Theory:
Graphics:
Graphics refers to visual representations such as images, drawings, or other forms of visual
art created using computers or physical mediums. A graphic is typically a still image and
does not involve motion. It is used to display information, illustrate concepts, or provide
visual appeal in digital content.

Examples of Graphics:
• A photo or digital illustration.
• A diagram or chart in a presentation.
• A logo design for a website.

Graphics are essential in designing user interfaces, websites, games, and more. However,
they do not show movement or change on their own. They are static visual elements.

Animation:
Animation, in contrast, is a sequence of images or frames that change over time to create the
illusion of movement. This sequence is played back rapidly, usually 24 to 60 frames per
second, to give the impression of continuous motion. Animation can be either 2D or 3D,
depending on how the images or frames are drawn or rendered.

Examples of Animation:

• A cartoon or animated movie (like Pixar or Disney films).


• A GIF on a website showing something moving, like a spinning wheel or a walking
character.
• An animation in a user interface, such as a button that expands or lights up when
clicked.

Difference Between Graphics and Animation:

• Graphics: Represents a single static image.


• Animation: Consists of multiple images shown in rapid succession to
create motion.
Algorithm:
• Initialize Graphics:

• Set up a graphics window with the required size.


• Initialize variables to represent the starting position of the sun
and its color.

• Draw Static Elements:

• Draw the ground using a rectangle or polygon.


• Draw other fixed objects, like clouds or mountains.

• Animate the Sun:

• Set the initial position of the sun at the horizon (bottom of the
sky).
• Use a loop to gradually move the sun upwards.
• In each iteration of the loop:
o Clear the previous frame.
o Redraw the static elements (ground, sky, etc.).
o Move the sun a few pixels higher on the y-axis.
o If the sun reaches a certain height, gradually change its
color from red to yellow.

• Update the Frame:

• After each move, refresh the screen and pause briefly to control
the speed of the animation (i.e., delay for a few milliseconds).

• Check Completion:

• If the sun reaches the top of the sky, stop the animation.

• End the Animation:

• Once the animation is complete, you may either exit the


program or leave the final frame visible.
PROGRAM:
#include <graphics.h>
#include <conio.h>
void draw_sky() {
setfillstyle(SOLID_FILL, LIGHTGRAY);
bar(0, 0, getmaxx(), getmaxy());
}
void draw_ground() {
setfillstyle(SOLID_FILL, GREEN);
bar(0, getmaxy() - 100, getmaxx(), getmaxy());
}
void draw_cloud(int x, int y) {
setcolor(BLUE);
setfillstyle(SOLID_FILL, BLUE);
fillellipse(x, y, 40, 20);
fillellipse(x + 50, y, 40, 20);
fillellipse(x + 25, y - 15, 35, 20);
}
void draw_scene(int sun_y, int sun_color) {
cleardevice(); // Clear the screen
draw_sky(); // Draw the sky
draw_ground(); // Draw the ground
setcolor(sun_color);
setfillstyle(SOLID_FILL, sun_color);
fillellipse(getmaxx() / 2, sun_y, 50, 50); // Sun at the
middle
draw_cloud(100, 100);
draw_cloud(400, 80); }
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); // Initialize graphics mode
int sun_y = getmaxy() - 150; // Start position of the sun
int sun_color = RED; // Sun starts as red
while (!kbhit()) { // Continue until a key is pressed
draw_scene(sun_y, sun_color);
sun_y -= 2;
if (sun_y < getmaxy() / 2) {
sun_color = YELLOW; // Sun turns yellow after rising
}
delay(50); // Control the speed of the sun rising
}
closegraph(); // Close the graphics mode
return 0;
}
OUTPUT:

Sun animation appears red


Sun changes colour to yellow
CONCLUSION:
Animation in computer graphics is a powerful technique that creates the
illusion of movement and change through the rapid succession of sequential
images. By utilizing basic principles of graphics programming and animation
algorithms, developers can craft engaging visual experiences that capture the
viewer's attention.

You might also like