Computer Graphics Programs in C - What You Will Learn?
Computer Graphics Programs in C - What You Will Learn?
Computer Graphics Programs in C - What You Will Learn?
You are the one who is interested in learning the fundamentals of the graphical
programming languages. This Page contains a list of fundamental graphics program for
various shapes. You will learn basics to draw geometrical shapes like circle, ellipse,
rectangle, etc.
We will also learn graphics programming in c to draw curves, objects with various
colors, 3d graphics programming, simple animation programs, and algorithms
programs.
When you start writing computer graphics code. The first step is to initialize
the graphics drivers using the initgraph() method given in graphics.h Library.
Instruction:
For all the Graphics Program Do this before you run the program.
1. Find initgraph(&gd, &gm, ""); in Program.
2. Write the path of BGI Folder, which there inside TC.
Like, initgraph(&gd, &gm, "C://TC//BGI");
or initgraph(&gd, &gm, "C://TurboC++//Disk//TurboC3//BGI");
3. Copy "EGAVGA.BGI" File from BGI Folder and Paste it to BIN Folder.
curve capacity is utilized to draw a circular segment with focus (x,y) and stangle
determines beginning edge, endangle details the end plot and last parameter points out
the sweep of the bend. curve capacity can additionally be utilized to draw a loop yet for
that beginning point and end edge ought to be 0 and 360 individually.
In the below program (100,100) are directions of middle of circular segment, 0 is the
beginning plot, 135 is the end edge and 50 indicates the sweep of the curve.
#include <graphics.h>
#include <conio.h>
main()
{
int gd = DETECT, gm;
getch();
closegraph();
return 0;
}
main()
{
int gd = DETECT, gm;
getch();
closegraph();
return 0;
}
Declaration :- void bar(int left, int top, int right, int base);
Circle function is used to draw a circle with center (x, y) and the third parameter is the
radius of the circle. The following code draws a circle.
In the following program (100, 100), the coordinates of the circle center and 50 is the
radius of the circle.
#include<graphics.h>
#include<conio.h>
main() {
int gd = DETECT, gm;
getch();
closegraph();
return 0;
}
Program :
#include <stdio.h>
#include <dos.h>
#include <graphics.h>
void main()
{
x1 = x1 + dx;
y1 = y1 + dy;
delay(20);
}
void main()
{
int x1, y1, xn, yn;
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
printf("Enter starting coordinates of line: ");
scanf("%d %d", &x1, &y1);
printf("Enter ending coordinates of line: ");
scanf("%d %d", &xn, &yn);
lineBres(x1, y1, xn, yn);
getch();
}
int main( )
{
int driver=VGA;
int mode=VGAHI;
int p1=0;
int q1=0;
int p2=0;
int q2=0;
do
{
show_screen( );
gotoxy(8,10);
cout<<"Coordinates of Point_I (p1,q1) :";
gotoxy(8,11);
cout<<"IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII";
gotoxy(12,13);
cout<<"Enter the value of p1 = ";
cin>>p1;
gotoxy(12,14);
cout<<"Enter the value of q1 = ";
cin>>q1;
gotoxy(8,18);
cout<<"Coordinates of Point_II (p2,q2) :";
gotoxy(8,19);
cout<<"IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII";
gotoxy(12,21);
cout<<"Enter the value of p2 = ";
cin>>p2;
gotoxy(12,22);
cout<<"Enter the value of q2 = ";
cin>>q2;
initgraph(&driver,&mode,"..\\Bgi");
setcolor(15);
slope_intercept_line(p1,q1,p2,q2);
setcolor(15);
outtextxy(110,460,"Press <Enter> to continue or any other key to exit.");
if(key!=13)
break;
}
while(1);
return 0;
}
//____ Funcion Definitions ____//
float x=p1;
float y=q1;
float dx=(p2_p1);
float dy=(q2_q1);
float m=(dy/dx);
float b=(y_(m#x));
float x_inc=((p2>=p1)?1:_1);
putpixel(x,y,color);
while((int)(x+0.5)!=p2)
{
x+=x_inc;
y=((m#x)+b);
putpixel((int)(x+0.5),(int)(y+0.5),color);
}
}
void show_screen( )
{
restorecrtmode( );
textmode(C4350);
cprintf("\n##################################################
##############################");
cprintf("####################_ _###############
#####");
cprintf("#____________________ ");
textbackground(1);
cprintf(" Cartesian Slope Intercept Equation ");
textbackground(8);
cprintf(" ____________________#");
cprintf("#_##################_ _###############
###_#");
cprintf("#_##################################################
##########################_#");
for(int count=0;count<42;count++)
cprintf("#_# #_#");
gotoxy(1,46);
cprintf("#_##################################################
##########################_#");
cprintf("#___________________________________________________
___________________________#");
cprintf("####################################################
############################");
gotoxy(8,40);
cout<<"Note :";
gotoxy(8,41);
cout<<"IIIIII";
gotoxy(10,43);
cout<<"This program is better for those lines with é<ñ45ø with x_axis.";
gotoxy(1,2);
}