Assignment 3 - 20BCE7124

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

School: SCOPE Semester: Win Sem 2022-23

Subject: Computer Graphics (Lab) Subject Code: CSE2006


Assignment 3

NAME: Piyali Kar


Registration No: 20BCE7124

1. Write a program to implement Mid Point Circle Drawing Algorithm.


Expected Output:

Code: -
import matplotlib.pyplot as plt
def midpoint_circle(xc, yc, r):
x = 0
y = r
p = 1 - r
x_list=[]
y_list=[]
while(x <= y):
x_list.append(xc + x)
y_list.append(yc + y)
x_list.append(xc + x)
y_list.append(yc - y)
x_list.append(xc - x)
y_list.append(yc + y)
x_list.append(xc - x)
y_list.append(yc - y)
y_list.append(xc + y)
x_list.append(yc + x)
y_list.append(xc + y)
x_list.append(yc - x)
y_list.append(xc - y)
x += 1
if(p < 0):
p = p + 2*x + 3
else:
y -= 1
p = p + 2*(x-y) + 5
plt.plot(x_list,y_list,'ro')
plt.text(max(x_list)+r, max(y_list), "Piyali Kar \n20BCE7124", ha="left",
va="center")
plt.axis([min(x_list)-r-1, max(x_list)+r+1, min(y_list)-
r-1, max(y_list)+r+1])
plt.show()
xc = int(input("Enter x-coordinate of center: "))
yc = int(input("Enter y-coordinate of center: "))
r = int(input("Enter radius: "))
midpoint_circle(xc, yc, r)

Output: -

2. Write a program to implement Bresennham’s Circle Drawing Algorithm.


Expected Output:

Code: -
void setup()
{
size(400,400);
fill(200,0,10);
text("Piyali Kar",200,250);
text("20BCE7124",200,270);
}
void draw()
{
//background(225,0,0);
BreshCircle();
}
void BreshCircle()
{
int x, y, r, Xc, Yc;
Xc=100;
Yc=100;
r=40;
text("The values of Xc and Yc: 100 100", 200,150);
text("The value of r: 40", 200,170);
//Decision parameter
int D=3-(2*r);
//---
x=0;
y=r;
boolean over=false;

while(!over)
{
drawCircle(Xc,Yc,x,y);
if(D < 0)
{
D=D+4*x+6;
x=x+1;
}
if(D > 0)
{
D=D+4*(x-y)+10;
x=x+1;
y=y-1;
}
if(x >= y)
{
over=true;
}
}
}
void drawCircle(int Xc,int Yc,int x,int y)
{
point(x+Xc, y+Yc );
point(y+Xc, x+Yc);
point(-y+Xc, x+Yc);
point(-x+Xc, y+Yc);
point(-x+Xc, -y+Yc);
point(-y+Xc, -x+Yc);
point(y+Xc, -x+Yc);
point(x+Xc, -y+Yc);
}

Output: -

You might also like