Вы находитесь на странице: 1из 10

NAME: Komal V

ROLL NO:3658

// C program to draw pixel on the screen

Input: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{ int x,y,gd,gm; gd=2,gm=3;

printf("enter the value of x and y:");

scanf("%d%d",&x,&y);

initgraph(&gd,&gm,"C:\\turboC3\\bgi");

putpixel(x,y,15);

outtextxy(100,100,"welcome to graphics");

getch();closegraph(); }

Output:

1
NAME: Komal V
ROLL NO:3658

// C program to draw line on the screen

Input: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{ int x,y,gd,gm;

clrscr();

printf("enter the x and y:");

scanf("%d%d",&x,&y);

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"C:\\turboC3\\bgi");

putpixel(x,y,15);

outtextxy(50,50,"welcome to graphics");

line(60,60,100,100);

getch();

closegraph();}

Output:

2
NAME: Komal V
ROLL NO:3658

//C program to draw a line using DDA method

Input: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

#include<dos.h>

void main()

{ float x1,x2,y1,y2,gd,gm,i,dx,dy,x,y,length;

printf("Enter (x1,y1) value");

scanf("%f%f",&x1,&y1);

printf("Enter (x2,y2) value");

scanf("%f%f",&x2,&y2);

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

dx=abs(x2-x1);

dy=abs(y2-y1);

if(dx>=dy)

length=dx;

else

length=dy;

dx=(x2-x1)/length;

dy=(y2-y1)/length;

x=x1+0.5;

y=y1+0.5;

i=1;

while(i<=length)

{ putpixel(x,y,15);

3
NAME: Komal V
ROLL NO:3658

x=x+dx;

y=y+dy;

i=i+1;

delay(100);}

getch(); closegraph();}

Output:

4
NAME: Komal V
ROLL NO:3658

// C program to draw a line using Bresenham’s Line drawing Algo

Input: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

#include<dos.h>

void main()

{ float x1,x2,y1,y2,e,i,dx,dy,x,y,length;

int gd,gm;

printf("Enter (x1,y1) value");

scanf("%f%f",&x1,&y1);

printf("Enter (x2,y2) value");

scanf("%f%f",&x2,&y2);

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

dx=abs(x2-x1);

dy=abs(y2-y1);

e=2*dy-dx;

i=1;

x=x1;

y=y1;

do

{putpixel(x,y,15);

while(e>0){

y=y+1;

e=e-2*dx; }

x=x+1;

5
NAME: Komal V
ROLL NO:3658

e=e+2*dy;

i=i+1;

}while(i<=dx);

getch();

closegraph();}

Output:

6
NAME: Komal V
ROLL NO:3658

//C program to draw a circle using Bresenham’s method

Input: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

#include<dos.h>

void main()

{ int i,gd,gm;

int r,x,y;

int d;

printf("Enter radius of circle:");

scanf("%d",&r);

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

x=0;

y=r;

d=3-2*r;

do{ putpixel(200+x,200+y,5);

putpixel(200+y,200+x,15);

putpixel(200-x,200-y,12);

putpixel(200-y,200-x,2);

putpixel(200-x,200+y,9);

putpixel(200+x,200-y,11);

putpixel(200-y,200+x,6);

putpixel(200+y,200-x,14);

if(d<0)

d=d+4*x+6;

7
NAME: Komal V
ROLL NO:3658

else

{ d=d+4*x-4*y+6;

y=y-1;}

x=x+1;

delay(100);

}while(x<y);

setfillstyle(4,9);

\\ floodfill(200,200,15);

getch();

closegraph();}

Output:

8
NAME: Komal V
ROLL NO:3658

// C program to draw a circle using midpoint program

Input: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

#include<dos.h>

void main()

{ int i,gd,gm;

int r,x,y;

float d;

printf("Enter radius of circle:");

scanf("%d",&r);

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

x=0;

y=r;

d=1.25-r;

do

{ putpixel(200+x,200+y,5);

putpixel(200+y,200+x,15);

putpixel(200-x,200-y,12);

putpixel(200-y,200-x,2);

putpixel(200-x,200+y,9);

putpixel(200+x,200-y,11);

putpixel(200-y,200+x,6);

putpixel(200+y,200-x,14);

if(d<0) { x=x+1;

9
NAME: Komal V
ROLL NO:3658

y=y-1;

d=d+2*x+3; }

else{

y=y-1;

x=x+1;

d=d+2*x-2*y+1; }delay(100);

}while(x<y);

getch();

closegraph();}

Output:

10

Вам также может понравиться