-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCGG2.CPP
136 lines (131 loc) · 2.58 KB
/
CGG2.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//Write a code to implement:
//1. Mid Point Circle Drawing algorithm.
//2. Bresenham Circle Drawing algorithm.
//3. Create a Object using the algorithms.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<iostream.h>
//Function to put pixels.
void display(int xc,int yc,int X,int Y)
{
putpixel(xc+X,yc+Y,BROWN);
putpixel(xc-X,yc+Y,BROWN);
putpixel(xc+X,yc-Y,BROWN);
putpixel(xc-X,yc-Y,BROWN);
putpixel(xc+Y,yc+X,BROWN);
putpixel(xc-Y,yc+X,BROWN);
putpixel(xc+Y,yc-X,BROWN);
putpixel(xc-Y,yc-X,BROWN);
}
//Bresenham Circle Algorithm
void Bresenham(int xc,int yc,int r)
{
int X,Y;
X=0,Y=r;
display(xc,yc,X,Y);
int sum=3-2*r;
while(X<=Y)
{
if(sum<0)
{
sum+=4*X+6;
}
else
{
Y--;
sum+=4*X-4*Y+10;
}
X++;
display(xc,yc,X,Y);
}
}
//Mid-Point Circle Drawing Function
void midptcirc(int xc,int yc,int r)
{
int X,Y;
X=0,Y=r;
display(xc,yc,X,Y);
int p=1-r;
while(X<=Y)
{
if(p<0)
{
p+=2*X+1;
}
else
{
Y--;
p+=2*X-2*Y+1;
}
X++;
display(xc,yc,X,Y);
}
}
//OBJECT
void clock()
{
int i=1;
Bresenham(320,240,150);
while((150-i)!=110)
{
Bresenham(320,240,150-i);
midptcirc(320,240,150-i);
i++;
}
midptcirc(320,240,110);
settextstyle(6,0,3);
outtextxy(310,133,"12");
outtextxy(400,225,"3");
outtextxy(320,310,"6");
outtextxy(213,225,"9");
line(320,240,350,165);
line(320,240,260,240);
getch();
}
void main(){
clrscr();
int gd=DETECT,gm;
int opt,radius,xc,yc;
cout<<" <TEXT MODE> "<<endl;
cout<<"Enter the option number:\n1. Bresenham Cricle Algorithm\t2. Mid-Point Circle Algorithm\t3. Draw a Object\t";
cin>>opt;
if(opt==1 || opt==2)
{
cout<<"Enter the radius:\t";
cin>>radius;
cout<<"Enter Centre X co-ordinate and Centre Y co-ordinate respectively:\t";
cin>>xc>>yc;
}
else;
getch();
initgraph(&gd,&gm,"C:/TURBOC3/BGI");
cout<<" <GRAPHICS MODE> "<<endl;
switch(opt)
{
case 1:
{
Bresenham(xc,yc,radius);
break;
}
case 2:
{
midptcirc(xc,yc,radius);
break;
}
case 3:
{
clock();
break;
}
default:
{
break;
}
}
getch();
closegraph();
cout<<" <TEXT MODE> "<<endl;
cout<<"\n\n\n\t\t\tEND OF TESTING"<<endl;
getch();
}