-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdla.cpp
More file actions
119 lines (86 loc) · 3.47 KB
/
Copy pathdla.cpp
File metadata and controls
119 lines (86 loc) · 3.47 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
//
// Created by ivan- on 03.05.2020.
//
#include <SFML/Graphics.hpp>
#include <iostream>
#include <chrono>
#include "vemath.h"
using namespace std;
using namespace vemath;
[[nodiscard]] Point2D randomVelocity2D(double abs) {
Point2D randomDir;
double angle = 2*PI*(double)rand()/RAND_MAX;
randomDir.x = abs*cos(angle);
randomDir.y = abs*sin(angle);
return randomDir;
}
int main() {
srand(126);
sf::ContextSettings settings;
settings.antialiasingLevel = 4;
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "turtles", sf::Style::Default, settings);
window.clear(sf::Color(255, 255, 255, 0));
auto startTime = chrono::system_clock::now();
auto tp1 = chrono::system_clock::now();
auto tp2 = chrono::system_clock::now();
unsigned long long N = 1;
double R = 500*100;
double velocity = 500;
double acceleration = 1.f;
int i_totalTime = 0;
double totalTime = 0;
int steps = 0;
double scale = 0.01;
vector<Point2D> turtles{N, {0,0}};
turtles[0].x = 0;
turtles[0].y = 0;
vector<Point2D> history;
while (window.isOpen())
{
vector<Point2D> lastPositions = turtles;
tp2 = chrono::system_clock::now();
chrono::duration <double> elapsedTime = tp2 - tp1;
tp1 = tp2;
double d_elapsedTime = elapsedTime.count();
std::string title = "turtles " + std::to_string((double)1/elapsedTime.count());
window.setTitle(title);
sf::Event event{};
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//cout << totalTime << endl;
//window.clear(); // отчистка
window.clear(sf::Color(255, 255, 255, 0));
sf::RectangleShape rectangle(sf::Vector2f(2*R*SCALE, 2*R*SCALE));
rectangle.move(SCREEN_WIDTH/2 - R*SCALE, SCREEN_HEIGHT/2 - R*SCALE);
rectangle.setFillColor(sf::Color(255, 255, 255));
rectangle.setOutlineThickness(10.f); // устанавливаем толщину контура круга
rectangle.setOutlineColor(sf::Color(80,220,50)); // устанавливаем цвет контура
//window.draw(rectangle);
for(int i = 0; i < turtles.size(); i++) {
int circleRadius = 1;
sf::CircleShape circle(circleRadius);
circle.setFillColor(sf::Color(255, 255, 255, 50));
circle.setPosition(SCREEN_WIDTH/2 + (int)turtles[i].x*SCALE - circleRadius/2, SCREEN_HEIGHT/2 + (int)turtles[i].y*SCALE - circleRadius/2);
//window.draw(circle);
for(int s = steps; s < history.size()-1; s++) {
sf::Vertex line[] =
{
sf::Vertex(sf::Vector2f(SCREEN_WIDTH / 2 + (int) history[s].x * scale,
SCREEN_HEIGHT / 2 + (int) history[s].y * scale)),
sf::Vertex(sf::Vector2f(SCREEN_WIDTH / 2 + (int) history[s+1].x * scale,
SCREEN_HEIGHT / 2 + (int) history[s+1].y * scale))
};
line->color = sf::Color{0, 0, 0, 50};
window.draw(line, 2, sf::Lines);
}
//steps = history.size()-1;
}
i_totalTime = (int) totalTime;
window.display(); // отображение
}
system("pause");
return 0;
}