Jay Gumbade Report
Jay Gumbade Report
DEPARTMENT OF PHYSICS
SUBMITTED BY
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
2
Serial Page
No.
Description
No.
1 CERTIFICATE 2
2 ACKNOWLEDGEMENT 4
10 Conclusion 23
3
Acknowledgement
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.
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
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.
7
3. Initialization of graphics in C program
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
#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 :
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
12
* To display blinking characters in text mode, add BLINK to the
foreground color. (Defined in conio.h)
void main()
{
//Initialize the variables for the graphics driver and mode
int gd = DETECT, gm;
clrscr();
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
13
//Draw an object. For this example,drawing a rectangle using the
rectangle function
rectangle(50,50,100,100);
getch();
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
i++
if(i>getmaxx())
i-=670
if(m<-360),
m=90, m-=3
delay (5)
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
#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
23