0% found this document useful (0 votes)
12 views7 pages

Ankit CG End Term Work

The document contains multiple programming assignments by Ankit Bhatt for a Computer Graphics course, focusing on various algorithms for drawing shapes such as lines, circles, and smiley faces. Each assignment includes a problem statement, objectives, and source code implementing the respective graphics algorithms. The assignments utilize Bresenham’s line and circle algorithms, Mid-point Circle generation, and basic graphics functions to create visual outputs.

Uploaded by

anchal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Ankit CG End Term Work

The document contains multiple programming assignments by Ankit Bhatt for a Computer Graphics course, focusing on various algorithms for drawing shapes such as lines, circles, and smiley faces. Each assignment includes a problem statement, objectives, and source code implementing the respective graphics algorithms. The assignments utilize Bresenham’s line and circle algorithms, Mid-point Circle generation, and basic graphics functions to create visual outputs.

Uploaded by

anchal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

NAME : ANKIT BHATT

COURSE : BCA SEM-6TH SEC : C


ROLL NO :2121093(01)
SUBJECT : Computer Graphics
PROBLEM STATEMENT: Write a program to draw a line using Bresenham’s line
generation algorithm.
OBJECTIVE: This lab exercise implements the line drawing algorithm using decision
parameter and pixel values.
SOURCE CODE :
#include<stdio.h>
#include<graphics.h>
int main( )
{
int gd=DETECT, gm, x0, y0, x1, y1, dx, dy, p, x,
y; printf("Co-ordinates of first point: "); printf("\
nEnter the value of x1: "); scanf("%d",&x0);
printf("Enter the value of y1:
"); scanf("%d",&y0);
printf("Co-ordinates of second point: "); printf("\
nEnter the value of x2: "); scanf("%d",&x1);
printf("Enter the value of y2:
"); scanf("%d",&y1);
initgraph(&gd,&gm,"")
; dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-
dx;
while(x<x1)
{
if(p>=0)
{
putpixel(x,y,15);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,4);
p=p+2*dy;
}
x=x+1;
}
getch();
closegraph();
return 0;
}
OUTPUT :
NAME : ANKIT BHATT
COURSE : BCA SEM-6TH SEC : C
ROLL NO :2121093 (01)
SUBJECT : Computer Graphics
PROBLEM STATEMENT: Write a program to draw a Circle using Mid-point Circle
generation Algorithm.
OBJECTIVE: The lab assignment objective is to implement Mid-point Circle generation
algorithm which plots the circle using eight segment approach.
SOURCE CODE :
#include<stdio.h>
#include<graphics.h>
void drawcircle(int x0, int y0, int radius)
{
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( ){
int gdriver=DETECT, gmode, error, x, y, r; printf("Enter radius of circle: "); scanf("%d", &r);
printf("Enter co-ordinates of center(x and y): ");
scanf("%d%d", &x, &y);
initgraph(&gdriver, &gmode,
""); drawcircle(x, y, r);
delay(9999999);
return 0;}

OUTPUT :
NAME : ANKIT BHATT
COURSE : BCA SEM-6TH SEC : C
ROLL NO :2121093 (01)
SUBJECT : Computer Graphics
PROBLEM STATEMENT: Write a program to draw a Circle using Bresenham’s Circle
algorithm.
OBJECTIVE: The lab assignment objective is to implement Bresenham’s Circle generation
algorithm which plots the circle using eight segment approach.
SOURCE CODE :
#include<stdio.h>
#include<graphics.h>
int main(){
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;
printf("Enter the radius
"); scanf("%d",&r);
initgraph(&gd,&gm,"");
x=0;
y=r;
putpixel(xc+x,yc-
y,1); p=3-(2*r);
for(x=0;x<=y;x++){
if
(p<0)
y=y;
p=(p+(4*x)+6);
else
y=y-
1;
p=p+((4*(x-y)+10));
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3)
; putpixel(xc-
x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7)
; putpixel(xc-
y,yc+x,8);
}
getch();
closegraph();
}
OUTPUT :
NAME : ANKIT BHATT
COURSE : BCA SEM-6TH SEC: C
ROLL NO :2121093(01)
SUBJECT : Computer Graphics
PROBLEM STATEMENT : Write a program to draw Smiley.
OBJECTIVE: To give a understanding to students of pixel positions and drawing figures using
basic graphics objects.
SOURCE CODE :
#include <stdio.h>
#include
<graphics.h> int
main( )
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
circle(300,200,100);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(299,210,15);
circle(260,158,15);
setfillstyle(SOLID_FILL,BLUE);
floodfill(259,159,15);
circle(340,158,15);
setfillstyle(SOLID_FILL,BLUE);
floodfill(341,159,15);
ellipse(300,220,180,0,50,50);
delay(99999);
closegraph( );
}

OUTPUT :
NAME : ANKIT BHATT
COURSE : BCA SEM-6TH SEC : C
ROLL NO :2121093(01)
SUBJECT : Computer Graphics
PROBLEM STATEMENT : Write a program to Zoom-in and zoom-out a circle.
OBJECTIVE: To give a understanding to students of pixel positions and drawing figures
using basic graphics objects.
SOURCE CODE :
#include<stdio.h>
#include<graphics.h>
int main( )
{
int gd=DETECT,gm,rad=0,n=10;
printf("Enter radius : ");
scanf("%d",&rad);
initgraph(&gd,&gm,"
"); while(n)
{
setcolor(15);
circle(200,200,rad);
delay(1000); if(rad
%2 == 0)
rad = rad-
30; else
rad = rad+49;
cleardevice();
n--;
}
}

OUTPUT :

You might also like