Skip to content

Commit e670fd2

Browse files
authored
Add Lab 2 and 3
1 parent 2cd3cd9 commit e670fd2

3 files changed

+118
-0
lines changed

Lab 2 Bresenham Circle Algorithm.CPP

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <stdio.h>
2+
#include <conio.h>
3+
#include <graphics.h>
4+
#include <math.h>
5+
6+
void main()
7+
{
8+
int gd = DETECT, gm = DETECT;
9+
int x, y, p, q, d, r;
10+
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
11+
printf("Enter Center of Circle(h,k): ");
12+
scanf("%d %d", &p, &q);
13+
printf("Enter radius of Circle(r): ");
14+
scanf("%d", &r);
15+
d = 3 - 2*r;
16+
x = 0; // Initial point
17+
y = r; // define gareko
18+
while(x <= y){
19+
putpixel(x+p, y+q, RED);
20+
putpixel(x+p,-y+q, RED);
21+
putpixel(-x+p,-y+q, RED);
22+
putpixel(-x+p, y+q, RED);
23+
putpixel(y+p, x+q, RED);
24+
putpixel(y+p,-x+q, RED);
25+
putpixel(-y+p, -x+q, RED);
26+
putpixel(-y+p, x+q, RED);
27+
if(d<=0){
28+
x = x + 1;
29+
d = d + 4*x + 6;
30+
}
31+
else{
32+
x = x + 1;
33+
y = y - 1;
34+
d = d + 4*(x-y) + 10;
35+
}
36+
}
37+
getch();
38+
}

Lab 2 Bresenham Line Algorithm.CPP

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdio.h>
2+
#include <conio.h>
3+
#include <graphics.h>
4+
5+
void main()
6+
{
7+
int gd = DETECT, gm = DETECT;
8+
int x1, y1, x2, y2, i, dx, dy, p;
9+
int x, y;
10+
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
11+
printf("Enter Initial Point (x1, y1): ");
12+
scanf("%d %d", &x1, &y1);
13+
printf("Enter Final Point (x2, y2): ");
14+
scanf("%d %d", &x2, &y2);
15+
dx = x2 - x1;
16+
dy = y2 - y1;
17+
p = 2 * dy + dx;
18+
x = x1; // Initial point
19+
y = y1;
20+
i = 0; // define gareko
21+
22+
while (i <= dx)
23+
{
24+
putpixel(x, y, WHITE);
25+
if (p < 0)
26+
{
27+
x = x + 1;
28+
p = p + 2 * dy;
29+
}
30+
else
31+
{
32+
x = x + 1;
33+
y = y + 1;
34+
p = p + 2 * dy - 2 * dx;
35+
}
36+
i = i + 1;
37+
};
38+
getch();
39+
}

Lab 3 Midpoint Circle Algorithm.CPP

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdio.h>
2+
#include <conio.h>
3+
#include <graphics.h>
4+
#include <math.h>
5+
6+
void main()
7+
{
8+
int gd = DETECT, gm = DETECT;
9+
int xc, yc, r, p, x, y;
10+
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
11+
printf("Enter the center of circle: ");
12+
scanf("%d %d", &xc, &yc);
13+
printf("Enter the radius of circle: ");
14+
scanf("%d", &r);
15+
p = 1 - r;
16+
x = 0;
17+
y = r;
18+
while (x <= y)
19+
{
20+
putpixel(x + xc, y + yc, WHITE);
21+
putpixel(x + xc, -y + yc, WHITE);
22+
putpixel(-x + xc, -y + yc, WHITE);
23+
putpixel(-x + xc, y + yc, WHITE);
24+
putpixel(y + xc, x + yc, WHITE);
25+
putpixel(y + xc, -x + yc, WHITE);
26+
putpixel(-y + xc, -x + yc, WHITE);
27+
putpixel(-y + xc, x + yc, WHITE);
28+
if (p < 0)
29+
{
30+
x = x + 1;
31+
p = p + 2 * x + 3;
32+
}
33+
else
34+
{
35+
x = x + 1;
36+
y = y - 1;
37+
p = p + 2 * (x - y) + 5;
38+
}
39+
}
40+
getch();
41+
}

0 commit comments

Comments
 (0)