0% found this document useful (0 votes)
17 views23 pages

Jay Gumbade Report

The document is a project report submitted by Jay Hemant Gumbade on 'Graphical Animation in C Language' for the Department of Physics at K.R.T. Arts, B.H. Commerce & A.M. Science College, Nashik. It includes an introduction to graphics programming, basic concepts, initialization of graphics in C, and examples of graphical animations such as a moving car and a pendulum. The project was completed under the guidance of Dr. N.K. Pawar and is part of the requirements for the T.Y.B.Sc degree.

Uploaded by

jaygumbade00
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
0% found this document useful (0 votes)
17 views23 pages

Jay Gumbade Report

The document is a project report submitted by Jay Hemant Gumbade on 'Graphical Animation in C Language' for the Department of Physics at K.R.T. Arts, B.H. Commerce & A.M. Science College, Nashik. It includes an introduction to graphics programming, basic concepts, initialization of graphics in C, and examples of graphical animations such as a moving car and a pendulum. The project was completed under the guidance of Dr. N.K. Pawar and is part of the requirements for the T.Y.B.Sc degree.

Uploaded by

jaygumbade00
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
You are on page 1/ 23

MARATHA VIDYA PRASARAK SAMAJ’S

K.R.T. ARTS, B.H. COMMERCE &A.M. SCIENCE (K.T.H.M)


COLLEGE
NASHIK
[2024-25]

DEPARTMENT OF PHYSICS

THE PROJECT REPORT


On
GRAPHICAL ANIMATION IN “C” LANGUAGE

SUBMITTED BY

NAME :- GUMBADE JAY HEMANT UNIVERSITY SEAT NO.: - 5572

UNDER THE GUIDANCE OF

Dr. N.K. PAWAR


Associate Professor, Dept. of Physics
NASHIK

1
MARATHA VIDYA PRASARAK SAMAJ’S
K.R.T. ARTS, B.H. COMMERCE &A.M. SCIENCE (K.T.H.M)
COLLEGE
NASHIK

DEPARTMENT OF PHYSICS

CERTIFICATE

This is hereby Certified that Mr. JAY HEMANT GUMBADE of Class


T.Y.B.Sc (PHYSICS) has successfully completed the project entitled
GRAPHICAL ANIMATION IN “C” LANGUAGE required for partial
fulfilment of T.Y.B.Sc degree. He has completed the project work successfully
under the guidance of Dr. N.K. PAWAR SIR. The report is the result of his efforts
& endeavours. The report is found worthy of acceptance as a project of
SEMESTER V.

Signature of guide Signature of HOD Signature of External Examiner


Physics

2
Serial Page
No.
Description
No.

1 CERTIFICATE 2

2 ACKNOWLEDGEMENT 4

3 Introduction to Graphics Programming in C


5
Language

4 Basic Concepts of Graphics 6

Initialization of graphics in C program


5 8
Example: - Draw a Line

6 Colors in C Graphics Programming 12

7 Graphics Example using color 13

Animation 1: Moving Car Program with Algorithm &


8 15
Flow Chart

9 Animation 2: Pendulum Program 20

10 Conclusion 23

3
Acknowledgement

I would like to express a deep sense of thanks and gratitude to my


project guide Dr. N.K. Pawar Sir for guiding me immensely through
the course of the project. He always evinced keen interest in my project.
His constructive advice & constant motivation have been responsible
for the successful completion on his project.
I also like to express a deep sense of thanks and gratitude to Dr.
S.N.Ahire, Head, Department of Physics for guiding me in my project
work.

My sincere thank goes to Dr. S.S. Kale (Principal) Sir for his co-
ordination in extending every possible support for the completion of
this project.

I must thanks to my classmates for their timely help and support for
completion of this project.

Last but not the least, I would like to thank all those who had helped
directly or indirectly towards the completion of this project.

Jay Hemant Gumbade


Class – T.Y.B.Sc (Physics)

4
1. Introduction to Graphics Programming in C-Language

Introduction
Graphics programming refers to the creation, manipulation, and
rendering of visual elements in computer applications. It allows
developers to create engaging and interactive user interfaces,
animations, games, and simulations. Graphics programming is crucial
in various domains, including gaming, multimedia, data visualization,
and computer-aided design.
Graphics programming languages provide the necessary tools and
libraries for developers to create, control, and display graphical
elements. These languages offer functionalities to draw shapes, render
images, apply transformations, and handle user input to create dynamic
and visually pleasing applications.
Graphics in C programming have played a significant role in the
development of computer applications. Graphics programming
involves creating and manipulating visual elements on a computer
screen, utilizing programming languages specifically designed for this
purpose. In this blog post, we will explore the fundamentals of graphics
programming in C, its importance in computer applications, and an
overview of graphics programming languages.

5
2. Basic Concepts in Graphics Programming

To understand graphics programming in C, it is essential to grasp the


basic concepts. Points, lines, and shapes are fundamental graphical
elements that can be created and manipulated using graphics
programming languages. The Cartesian coordinate system is often used
to represent and position these elements on a two-dimensional plane.
Color representation is another crucial aspect of graphics
programming. Most graphics programming languages utilize the RGB
(Red, Green, Blue) color model, where colors are formed by combining
different intensities of these primary colors. Manipulating individual
pixels allows developers to create images and apply visual effects.

Understanding Coordinates and Pixels


In graphics programming, understanding how coordinates map to
pixels is crucial. Graphics libraries work with pixels as the basic units
for rendering and manipulating graphical elements. Mapping
coordinates to pixels ensures accurate positioning and alignment of
shapes and lines on the screen.
Pixel manipulation techniques involve working with individual pixels
to create images or apply effects. This involves reading and modifying
RGB values of pixels to create desired visual outcomes. By
manipulating pixels, you can create simple pixel-based images or
perform image processing operations.

Concepts of Graphics
Pixel: The smallest unit of a digital image or display. Graphics are
composed of thousands or millions of pixels arranged in a grid.

6
Coordinate System: In graphics programming, the screen is
considered a coordinate plane where each pixel has a specific position
defined by x (horizontal) and y (vertical) coordinates.
Graphics Mode: A mode that allows the program to draw shapes, text,
and images on the screen. This is different from text mode, where the
screen is treated as a grid of characters.

Graphics programming in C used to drawing various geometrical


shapes(rectangle, circle eclipse etc), use of mathematical function in
drawing curves, coloring an object with different colors and patterns
and simple animation programs like jumping ball and moving cars.

7
3. Initialization of graphics in C program

Graphics Initialization and Modes


To work with graphics in C, particularly with the Borland Graphics
Interface (BGI) library in Turbo C or Turbo C++, you need to initialize
the graphics mode and set up the graphics environment.
1. Initializing Graphics
Including Graphics Library: Include the graphics library header file.
#include <graphics.h>
#include <conio.h> // For getch()
2. Setting Up Graphics Mode:
int gd: Graphics driver (e.g., DETECT to automatically detect the
appropriate driver).
int gm: Graphics mode (e.g., DETECT to automatically select the
highest resolution mode).
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
initgraph: Initializes the graphics system by loading the graphics driver.

3. Closing Graphics: Close the graphics mode and return to text mode.
closegraph(): The header file graphics.h contains closegraph() function
which closes the graphics mode, deallocates all memory allocated by
graphics system and restores the screen to the mode it was in before
you called initgraph.

8
Example 1: Line

First graphics program (Draw a line)

#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main(void) {
int gdriver = DETECT, gmode;
int x1 = 200, y1 = 200;
int x2 = 300, y2 = 300;
clrscr();
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
line(x1, y1, x2, y2);
getch();
closegraph();
}

9
2. Explanation of Code :

1. The first step in any graphics program is to


include graphics.h header file. The graphics.h header file
provides access to a simple graphics library that makes it possible
to draw lines, rectangles, ovals, arcs, polygons, images, and
strings on a graphical window.
2. The second step is initialize the graphics drivers on the computer
using initgraph method of graphics.h library.
initgraph(int *graphicsDriver, int *graphicsMode, char
*driverDirectoryPath);
It initializes the graphics system by loading the passed graphics
driver then changing the system into graphics mode. It also resets
or initializes all graphics settings like color, palette, current
position etc, to their default values. Below is the description of
input parameters of initgraph function.
3. graphicsDriver : It is a pointer to an integer specifying the
graphics driver to be used. It tells the compiler that what graphics
driver to use or to automatically detect the drive. In all our
programs we will use DETECT macro of graphics.h library that
instruct compiler for auto detection of graphics driver.
4. graphicsMode : It is a pointer to an integer that specifies the
graphics mode to be used. If *gdriver is set to DETECT,
then initgraph sets *gmode to the highest resolution available for
the detected driver.
5. driverDirectoryPath : It specifies the directory path where
graphics driver files (BGI files) are located. If directory path is
not provided, then it will search for driver files in current working
directory directory. In all our sample graphics programs, you have
to change path of BGI directory accordingly where you Turbo
C++ compiler is installed.

10
We have declared variables so that we can keep track of starting and
ending point.
int x1=200, y1=200;
int x2=300, y2=300;
No, We need to pass just 4 parameters to the line function.
line(x1,y1,x2,y2);
line Function Draws Line From (x1,y1) to (x2,y2) .
Syntax : line(x1,y1,x2,y2);
x1 - X Co-ordinate of First Point
y1 - Y Co-ordinate of First Point
x2 - X Co-ordinate of Second Point
y2 - Y Co-ordinate of Second Point
At the end of our graphics program, we have to unloads the graphics
drivers and sets the screen back to text mode by
calling closegraph function.

11
4. Colors in C Graphics Programming

There are 16 colors declared in graphics.h header file. We use colors to


set the current drawing color, change the color of background, change
the color of text, to color a closed shape etc (Foreground and
Background Color). To specify a color, we can either use color
constants like setcolor(RED), or their corresponding integer codes like
setcolor(4). Below is the color code in increasing order.
Constant Value Background? Foreground?
BLACK 0 Yes Yes
BLUE 1 Yes Yes
GREEN 2 Yes Yes
CYAN 3 Yes Yes
RED 4 Yes Yes
MAGENTA 5 Yes Yes
BROWN 6 Yes Yes
LIGHTGRAY 7 Yes Yes
DARKGRAY 8 NO Yes
LIGHTBLUE 9 NO Yes
LIGHTGREEN 10 NO Yes
LIGHTCYAN 11 NO Yes
LIGHTRED 12 NO Yes
LIGHTMAGENTA 13 NO Yes
YELLOW 14 NO Yes
WHITE 15 NO Yes
BLINK 128 NO *

12
* To display blinking characters in text mode, add BLINK to the
foreground color. (Defined in conio.h)

Example 2: Graphics example using color

//Include the graphics header file


#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{
//Initialize the variables for the graphics driver and mode
int gd = DETECT, gm;
clrscr();
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");

//Set the color of the object you want to draw.


setcolor(BLUE);

13
//Draw an object. For this example,drawing a rectangle using the
rectangle function

rectangle(50,50,100,100);

getch();

//unloads the graphics drivers


closegraph();
}

14
Algorithm of the Animation: - 1

Step I: - Start
Step II: - Define Graphics variable
Step III: - Define variables i and m
Step IV: - Draw a road of the car
Step V: - Draw a body of the car
Step VI: - Draw a car mudguard
Step VII: - Draw car wheels
Step VIII: - Draw a car wheel design
Step IX: - car wheel rotation, if(m<-360)
Step X: - m=90
Step XI: - m-=3
Step XII: - delay of 5
Step XIII: - Output of the Program
Step XIV: - Stop

15
Flow Chart of the Animation: - 1
Start

Define Graphics variable

Define variables i and m

i++

if(i>getmaxx())

i-=670

Draw a road line

Draw a body of the car

Draw a car mudguard

Draw car wheels

Draw a car wheel design

if(m<-360),
m=90, m-=3

delay (5)

Output of the Program

Stop

16
1. Animation:1
/* C program to implement Moving Car in Graphics */

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>

void main()
{
int gd=DETECT,gm;
int i=0,m=0;
initgraph(&gd,&gm,"..\\bgi");
while(!kbhit())
{
cleardevice();
i++;
if(i>getmaxx())
i-=670;

//road//
line(80,320,640,320);

17
//body of the car//
line(80+i,300,90+i,270);
line(90+i,270,120+i,270);
line(120+i,270,160+i,240);
line(160+i,240,230+i,240);
line(230+i,240,275+i,270);
line(275+i,270,310+i,270);
line(310+i,270,335+i,290);
line(335+i,290,335+i,300);
line(255+i,300,335+i,300);
line(180+i,300,210+i,300);
line(80+i,300,135+i,300);

// car mudguard //
arc(232+i,300,0,180,23);
arc(157+i,300,0,180,23);

//car wheels//
circle(232+i,300,18);
circle(157+i,300,18);
//car wheel design//
pieslice(232+i,300,0+m,90+m,18);
pieslice(232+i,300,180+m,270+m,18);
pieslice(157+i,300,0+m,90+m,18);
pieslice(157+i,300,180+m,270+m,18);

18
if(m<-360)
m=90;
m-=3;
delay(5);
}
getch();
closegraph();
}

19
2. Animation:2
Pendulum Animation

/* Jay Gumbade ok C Program to perform Pendulum in graphics */

#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
int cx=300,cy=100,r=300;
int x=0,y,p;
int path(int dtn) {
int x1,y1;
setcolor(15);
if(x>=y) {
return 0;
}
cleardevice();
if(dtn==1) {
circle(cx+x,cy+y,20);
line(cx,cy,cx+x,cy+y);
} else {
circle(cx-x,cy+y,20);
line(cx,cy,cx-x,cy+y);
20
}
delay(10);
if(kbhit())
exit(0);
x++;
if(p<0)
p+=2*x+1; else {
y--;
p+=2*(x-y)+1;
}
x1=x;
y1=y;
path(dtn);
cleardevice();
if(dtn==1) {
circle(cx+x1,cy+y1,20);
line(cx,cy,cx+x1,cy+y1);
} else {
circle(cx-x1,cy+y1,20);
line(cx,cy,cx-x1,cy+y1);
}
delay(10);
if(kbhit())
exit(0);
return(0);

21
}
void main() {
int gd=DETECT,gm=DETECT;
initgraph(&gd,&gm,"");
cleardevice();
putpixel(300,100,4);
while(1) {
x=0;
y=r;
p=1-r;
path(1);
x=0;
y=r;
p=1-r;
path(0);
}
}

22
Conclusion

In conclusion, graphics programming in C offers exciting possibilities


for creating visually appealing and interactive computer applications.
By learning the fundamentals and exploring different aspects of
graphics programming, you can unlock a multitude of opportunities.
Graphics programming skills are highly valued in various industries,
including gaming, software development, and simulation. By delving
deeper into this field, you can create your own graphical applications
and contribute to the world of computer graphics. So, go ahead, explore
further, and unleash your creativity in the realm of graphics
programming.

23

You might also like