-
Notifications
You must be signed in to change notification settings - Fork 0
/
star.cpp
71 lines (54 loc) · 1.24 KB
/
star.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
#include "star.h"
star::star(int number) :sum(number)//, shape(InvalidColor)
{
for (int i = 0; i < sum; i++)
{
stars.push_back(shapes{});
stars[i].x = 5 + rand() % 990;
stars[i].y = 5+rand()%710;
stars[i].angle = rand()%72;
stars[i].r =2 + rand()%20;
}
}
star::~star()
{
}
void star::update(int time)
{
int colorChange3;
int colorChange2;
int angleChange;
for (int i = 0; i < sum; i++)
{
if (time % 3 == 0)
{
angleChange = rand() % 100;
if (time % 100 == 0)
{
stars[i].x = 5 + rand() % 890;
stars[i].y = 5 + rand() % 510;
}
double a = pi / 2 + stars[i].angle + angleChange;
if (time % 2)
stars[i].r++;
else stars[i].r--;
for (int t = 0; t < 5; t++)
{
stars[i].place[t].x = int(stars[i].x + cos(a) * stars[i].r);
stars[i].place[t].y = int(stars[i].y - sin(a) * stars[i].r);
a += pi * 4 / 5;
}
colorChange3 = rand() % 255;
colorChange2 = 200 + rand() % 55;
stars[i].color = RGB(static_cast<BYTE>(colorChange2), static_cast<BYTE>(colorChange2), static_cast<BYTE>(colorChange3));
}
draw(i);
}
}
void star::draw(int i)
{
setpolyfillmode(WINDING);
setfillcolor(stars[i].color);
// »æÖÆÎå½ÇÐÇ(Îޱ߿ò)
solidpolygon(stars[i].place, 5);
}