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
137
138
139
140
141
142
143
144
145
146
147
| #include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <iomanip.h>
#include <math.h>
class TShape {
protected: int x, y, color;
public:
TShape(int ix, int iy, int icolor);
~TShape();
virtual void Draw(int c)= 0;
void Show();void Hide();
};
class TPoint : public TShape {
public:
TPoint(int ix, int iy, int icolor);
void Draw(int c);
};
class Ellipse : public TPoint {
protected: int sang, endang, xrad, yrad;
public:
Ellipse(int ix, int iy, int ixrad, int iyrad, int icolor);
void Draw(int c);
};
class Ring : public Ellipse {
protected: int r;
public:
Ring(int ix, int iy, int ir, int icolor);
void Draw(int c);
};
class Sector : public Ellipse {
protected: int sang, eang, xrad, yrad;
public:
Sector(int ix, int iy, int isang, int ieang, int ixrad, int iyrad, int icolor);
void Draw(int c);
};
TShape::TShape(int ix, int iy, int icolor) {
x=ix; y=iy;
color=icolor;
}
TShape::~TShape() {
}
void TShape::Show() {
Draw(color);
}
void TShape::Hide() {
Draw(BLACK);
}
TPoint::TPoint(int ix, int iy, int icolor): TShape(ix, iy, icolor){
}
void TPoint::Draw(int c) {
putpixel(x, y, c);
}
Ellipse::Ellipse(int ix, int iy, int ixrad, int iyrad, int icolor) :
TPoint(ix, iy, icolor){
xrad=ixrad; yrad=iyrad;
}
void Ellipse::Draw(int c) {
setcolor(c);
ellipse(x, y, 0, 360, xrad, yrad);
line(x-xrad,y-yrad,x+xrad,y+yrad);
}
Ring::Ring(int ix, int iy, int ir, int icolor) :
Ellipse (ix, iy, ir, ir, icolor ) {
r=ir;
}
void Ring::Draw(int c) {
setcolor(c);
circle(x, y, r);
}
Sector::Sector(int ix, int iy, int isang, int ieang, int ixrad, int iyrad, int icolor):
Ellipse(ix, iy, ixrad, iyrad, icolor) {
sang=isang; eang=ieang;
xrad=ixrad; yrad=iyrad;
}
void Sector::Draw(int c) {
setcolor(c);
sector(x, y, sang, eang, xrad, yrad);
}
main() {
cout<<"color";
int i,var,j;
TShape *A[64];
int graphdriver = DETECT, graphmode, errorcode;
initgraph(&graphdriver, &graphmode, "C:\\Borlandc\\BGI");
randomize();
setfillstyle(1,0);
cout<<"<---CHOSE_YOUR_DESTINY---> \n";
cout<<"1) Ellipse \n";
cout<<"2) Ring \n"; cout<<"3) Sector \n";
cout<<"4) 2 Dots \n"; cin>>var;
if (var==1){
for (i=0; i<64; i++) {
A[i] = new Ellipse(i*10, 240, random(100), random(80), random(14)+1);
}
while (!kbhit()) {
for (i=0; i<64; i++) {
A[i]->Show();
delay(50);
A[i]->Hide();
}
}
}
if (var==2){
for (i=0; i<64; i++) {
A[i] = new Ring(i*10, 240, random(100), random(14)+1);
}
while (!kbhit()) {
for (i=0; i<64; i++) {
A[i]->Show();
delay(50);
A[i]->Hide();
}
}
}
if (var==3){
for (i=0; i<64; i++) { j=random(45);
A[i] = new Sector(i*10, 240, 315+j, 45-j, 60+i, 60+i, random(14)+1);
}
while (!kbhit()) {
for (i=0; i<64; i++) {
A[i]->Show();
delay(50);
A[i]->Hide();
}
}
}
if (var==4){
for (i=0; i<64; i++) {
A[i] = new TPoint(100+random(500), 100+random(300), random(14)+1);
}
while (!kbhit()) {
for (i=0; i<2; i++) {
A[i]->Show();
delay(500);
}
}
}
getch();
closegraph();
return 0;
} |