Professional Documents
Culture Documents
#include<stdio.h>
#include<graphics.h>
int x = radius;
int y = 0;
int err = 0;
while (x >= y)
putpixel(x0 + x, y0 + y, 7);
putpixel(x0 + y, y0 + x, 7);
putpixel(x0 - y, y0 + x, 7);
putpixel(x0 - x, y0 + y, 7);
putpixel(x0 - x, y0 - y, 7);
putpixel(x0 - y, y0 - x, 7);
putpixel(x0 + y, y0 - x, 7);
putpixel(x0 + x, y0 - y, 7);
if (err <= 0)
y += 1;
err += 2*y + 1;
if (err > 0)
x -= 1;
err -= 2*x + 1;
int main()
scanf("%d", &r);
drawcircle(x, y, r);
return 0;
}
Bresenham’s line drawing algorithm
#include<stdio.h>
#include<graphics.h>
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
if(p>=0)
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
else
putpixel(x,y,7);
p=p+2*dy;
x=x+1;
}
int main()
return 0;
}
Indian Flag
#include<graphics.h>
#include<conio.h>
void main()
int gd=DETECT,gm;
//Flag Rectangle
setfillstyle(1,LIGHTRED);
bar(200,50,450,100);
setfillstyle(1,WHITE);
bar(200,100,450,150);
setfillstyle(1,GREEN);
bar(200,150,450,200);
//Ashoka Chakra
setcolor(BLUE);
circle(320,125,25);
setfillstyle(1,BLUE);
fillellipse(320,125,15,15);
setfillstyle(1,BROWN);
bar(190,40,200,430);
//Ground Part
setfillstyle(1,BROWN);
bar(170,430,220,450);
bar(140,450,250,480);
getch();
closegraph();
}
Sierpinski triangle Fractal
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void sierpinski(void)
char d;
int i;
int x1,y1,x2,y2;
x1=x2=320;
y1=y2=0;
for(i=0;i<10000;i++)
d=random(3);
if(d==0)
x1=(x2+320)/2;
y1=(y2+0)/2;
else
if(d==1)
x1=(x2+0)/2;
y1=(y2+480)/2;
else
if(d==2)
x1=(x2+640)/2;
y1=(y2+480)/2;
}
putpixel(x1,y1,WHITE);
x2=x1;
y2=y1;
void main()
int gd=DETECT,gm;
getch();
closegraph();
}
Rotating wheel
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <time.h>
#include <graphics.h>
#include <dos.h>
void calcPoints(int radius, int midx, int midy, int x[12], int y[12]) {
y1 = (radius / 2);
x1 = radius / 2;
return;
int main() {
err = graphresult();
if (err != grOk) {
grapherrormsg(err));
return 0;
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* radius of rim */
radius = 200;
setlinestyle(SOLID_LINE, 1, 3);
while (!kbhit()) {
setcolor(WHITE);
if (i % 2 == 0) {
delay(100);
setcolor(BLACK);
if (i % 2 == 0) {
setcolor(WHITE);
}
setcolor(WHITE);
if (i % 2 != 0) {
delay(100);
setcolor(BLACK);
if (i % 2 != 0) {
setcolor(WHITE);
getch();
closegraph();
return 0;
}
SUNFLOWER
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\Turboc3\\BGI");
setfillstyle(HATCH_FILL,BROWN);
circle(300,230,100);
floodfill(300,230,WHITE);
setfillstyle(SOLID_FILL,YELLOW);
arc(455,230,215,145,80);
floodfill(445,230,WHITE);
setfillstyle(SOLID_FILL,YELLOW);
arc(300,85,313,230,80);
floodfill(300,85,WHITE);
setfillstyle(SOLID_FILL,YELLOW);
arc(150,235,40,325,80);
floodfill(150,235,WHITE);
setfillstyle(SOLID_FILL,YELLOW);
arc(295,380,125,50,80);
floodfill(295,380,WHITE);
setfillstyle(SOLID_FILL,GREEN);
arc(372,495,270,89,200);
arc(355,515,270,90,200);
floodfill(510,380,WHITE);
getch();
closegraph();
}
DDA_line Drawing
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int graphdriver, graphmode, i;
float x,y,x1,y1,x2,y2,dx,dy,delx,dely,length;
for(i=0;i<n;i++)
{
printf("\nEnter coordinate (%d)of the defining figure: ",i+1);
scanf("%f %f",&cord[i][0],&cord[i][1]);
cord[i][2]=1;
}
}
/* draw the polygon with coordinates*/
void drawPolygon(float ans[][3])
{
int i;
line(getmaxx()/2, 0, getmaxx()/2, getmaxy());
line(0,getmaxy()/2, getmaxx(), getmaxy()/2);
for(i=0;i<n-1;i++)
line(getmaxx()/2+ans[i][0],getmaxy()/2-ans[i][1],getmaxx()/2+ans[i+1][0],
getmaxy()/2-ans[i+1][1]);
line(getmaxx()/2+ans[0][0],getmaxy()/2-ans[0][1],getmaxx()/2+ans[i][0],getmaxy()/2-
ans[i][1]);
}
mul(cord,n,tMat,ans);
if(draw) drawPolygon(ans);
}
mul(cord,n,tMat,ans);
drawPolygon(ans);
}
/*Perform reflection about x-axis/ y-axis*/
void reflect(char axis)
{
if(axis=='x')
tMat[1][1]=-1;
else
tMat[0][0]=-1;
mul(cord,n,tMat,ans);
drawPolygon(ans);
}
angle*=PI/180;
tMat[0][0]=cos(angle);
tMat[0][1]=sin(angle);
tMat[1][0]=-sin(angle);
tMat[1][1]=cos(angle);
mul(cord,n,tMat,ans);
drawPolygon(ans);
}
switch(choice)
{
case 1 :
getPoints(); /* obtain coordinates for defining figure*/
printf("\nEnter the translating co-ordinates: Tx Ty");
scanf("%f %f",&tx,&ty);
cleardevice();
drawPolygon(cord);
delay(10000); /* draw the polygon*/
translate(tx,ty,1);
getch();
break;
case 2 : getPoints(); /* obtain coordinates for defining figure*/
printf("\nEnter the Scaling factors: Sx Sy");
scanf("%f %f",&sx,&sy);
cleardevice();
drawPolygon(cord); /* draw the polygon*/
delay(10000);
cleardevice();
scale(sx,sy);
getch();
break;
case 3: getPoints(); /* obtain coordinates for defining figure*/
printf("\nEnter the Rotating angle:");
scanf("%f",&r);
cleardevice();
drawPolygon(cord); /* draw the figure*/
delay(10000);
cleardevice();
rotate(r);
getch();
break;
case 4: getPoints();
cleardevice();
drawPolygon(cord); /* draw the figure */
axis='x';
delay(10000);
reflect(axis);
getch();
break;
case 5: getPoints();
cleardevice();
drawPolygon(cord); /* draw the figure*/
axis='y';
delay(10000);
reflect(axis);
getch();
break;
case 0 : exit(0);
}
}
RAINBOW
#include<stdio.h>
#include<graphics.h>;
#include<dos.h>;
void rainbow()
{
int gdriver = DETECT ,gmode;
int x,y,i;
initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
x=getmaxx()/2;
y=getmaxx()/2;
for(i=30; i<200; i++)
{
delay(100);
setcolor(i/10);
arc(x,y,0,180,i-10);
}
}
int main()
{rainbow();
return 0;
}
Institute of
Mathematics
& Application
Computer Graphic project
Submitted By-
Pritesh kumar
Roll no-2017b012