-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
146 lines (142 loc) · 3.31 KB
/
Copy pathSource.cpp
File metadata and controls
146 lines (142 loc) · 3.31 KB
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
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include <cmath>
using namespace sf;
using namespace std;
#define PI 3.14159265359
#define COLORS_CHANGING
Vector2f coords(double angle)
{
angle = (angle / 180.0) * PI;
Vector2f coord;
coord.x = 300.0 * cos(angle);
coord.y = 300.0 * sin(angle);
return coord;
}
unsigned char& getCol(Color& col, int i)
{
while (i < 0)i += 3;
if (i % 3 == 0) return col.r;
if (i % 3 == 1) return col.g;
if (i % 3 == 2) return col.b;
}
void coladd(Color& col)
{
int i;
for (i = 2; !(i < 0 || (getCol(col, i) == 0 && getCol(col, i + 1) != 0)); i--);
if (getCol(col, i + 1) > getCol(col, i + 2)) getCol(col, i + 2)++;
else getCol(col, i + 1)--;
}
void colminus(Color& col)
{
int i;
for (i = 0; !(i >= 3 || (getCol(col, i) == 0 && getCol(col, i - 1) != 0)); i++);
if (getCol(col, i + 1) < getCol(col, i + 2)) getCol(col, i + 1)++;
else getCol(col, i + 2)--;
}
VertexArray line(Lines, 2);
#ifdef COLORS_CHANGING
vector<Color> allcolors(1530, Color::Black);
#endif
int main()
{
#ifdef COLORS_CHANGING
Color c = Color::Red;
for (int i = 0; i < 1530; i++)
{
allcolors[i] = c;
coladd(c);
}
int opacity = 128;
int colshift = 0;
#endif
RenderWindow window(VideoMode(700, 700), "SFML works!");
window.setFramerateLimit(60);
CircleShape shape(299);
shape.setFillColor(Color(255, 255, 255, 255));
shape.setOutlineColor(Color(0, 0, 0, 255));
shape.setOutlineThickness(2);
shape.setPosition(50, 50);
shape.setPointCount(100);
Color col = Color(255, 0, 0, 100);
double n = 0;
int nop;
double dn = 0.0002;
bool pause = 0;
cin >> nop;
while (window.isOpen())
{
n += dn * (!pause);
if (int(n) == nop) n = 0.0;
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
if (event.type == Event::KeyPressed)
if (event.key.code == Keyboard::P)
pause = !pause;
if (event.type = Event::Resized)
{
View v(FloatRect(0, 0, window.getSize().x, window.getSize().y));
window.setView(v);
}
}
if (Keyboard::isKeyPressed(Keyboard::W))
#ifndef COLORS_CHANGING
col.a += (col.a < 255);
#else
opacity += (opacity < 255);
#endif
if (Keyboard::isKeyPressed(Keyboard::S))
#ifndef COLORS_CHANGING
col.a -= (col.a > 0);
#else
opacity -= (opacity > 0);
#endif
if (Keyboard::isKeyPressed(Keyboard::Q))
#ifndef COLORS_CHANGING
colminus(col);
colminus(col);
#else
colshift -= 2;
colshift += 1530;
colshift %= 1530;
#endif
if (Keyboard::isKeyPressed(Keyboard::E))
#ifndef COLORS_CHANGING
coladd(col);
coladd(col);
#else
colshift += 2;
colshift %= 1530;
#endif
if (Keyboard::isKeyPressed(Keyboard::D))
{
if (dn > 0)dn *= 1.01;
else if (dn < 0)dn /= 1.01;
if (dn > -0.0001 && dn < 0)dn = 0.0001;
}
else if (Keyboard::isKeyPressed(Keyboard::A))
{
if (dn > 0)dn /= 1.01;
else if (dn < 0)dn *= 1.01;
if (dn < 0.0001 && dn > 0)dn = -0.0001;
}
window.clear(Color::White);
window.draw(shape);
for (int i = 0; i < nop; i++)
{
#ifdef COLORS_CHANGING
Color col = allcolors[((i * 1530 / nop) + colshift) % 1530];
col.a = opacity;
#endif
line[0] = Vertex(coords(double(i) * 360.0 / double(nop)) + Vector2f(350, 350), col);
line[1] = Vertex(coords(n * double(i) * 360.0 / double(nop)) + Vector2f(350, 350), col);
window.draw(line);
}
window.display();
}
return 0;
}