-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.cpp
169 lines (131 loc) · 5.31 KB
/
animation.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "stdSysImports.h"
#include "bresenham.h"
using namespace std;
int main () {
ofstream myfile;
myfile.open("animation.csv");
int timesteps = 5000;
pair<int,int> chaser = {2048,2048}; //chaser starts in the middle
std::pair<int,int> boatPositions[timesteps] = {};
std::pair<int,int> followingBoatPositions[timesteps] = {};
std::pair<int,int> chasingBoatPositions[timesteps] = {};
std::pair<int,int> threeFollowBoatPositions[timesteps] = {};
boatPositions[0] = chaser;
chasingBoatPositions[0] = chaser;
followingBoatPositions[0] = chaser;
threeFollowBoatPositions[0] = chaser;
int dir = rand() % 4 + 1;
dir = 1;
pair<int,int> runner = {1900,1950};
//declaring all vars for zigzag
int choice, direction, segmentLength;
pair<int, int> move1, move2, move3, curMove = { 0,0 };
int randMoveType = rand() % 3 + 1;
int m = 0;
int zzl = 15 + rand() % 10;
for (int i = 1; i<= timesteps; i++){ //looping through each time step
//zigzag block update2
if (i % zzl == 1) {
choice = rand() % 3 + 1; //choose new state every zzl time steps
direction = rand() % 4 + 1; //pick cardinal direction to zigzag in
if (direction == 1)
{
// north
move1 = { -1,1 };
move2 = { 1,1 };
}
if (direction == 2)
{
// south
move1 = { -1,-1 };
move2 = { 1,-1 };
}
if (direction == 3)
{
// east
move1 = { 1,-1 };
move2 = { 1,1 };
}
if (direction == 4)
{
// west
move1 = { -1,-1 };
move2 = { -1,1 };
}
segmentLength = zzl/5 + rand() % 3;
}
int currX3f = threeFollowBoatPositions[i-1].first;
int currY3f = threeFollowBoatPositions[i-1].second;
int currXf = followingBoatPositions[i-1].first;
int currYf = followingBoatPositions[i-1].second;
int currXc = chasingBoatPositions[i-1].first;
int currYc = chasingBoatPositions[i-1].second;
int currX = boatPositions[i-1].first;
int currY = boatPositions[i-1].second;
//movement
boatPositions[i] = randMove(currX, currY);
if ((currXc != runner.first || currYc != runner.second) && currXc != -1){ //checking for collision
chasingBoatPositions[i] = bresenhamstep(currXc,currYc,runner.first,runner.second);
}
else{
chasingBoatPositions[i] = {-1,-1};
}
if ((currXf != runner.first || currYf != runner.second) && currXf != -1){
followingBoatPositions[i] = randFollowMove(currXf,currYf,runner.first,runner.second);
}
else{
followingBoatPositions[i] = {-1,-1};
}
if (make_pair(currX3f,currY3f) != runner && currXf != -1 ) {
// control flow for 3state following
if (choice == 1) //chasing
{
threeFollowBoatPositions[i] = bresenhamstep(currX3f, currY3f, runner.first,runner.second);
}
else if (choice == 2)
{
// random walk
threeFollowBoatPositions[i] = randMove(currX3f, currY3f);
}
else //zigzag
{
if (m>segmentLength){ // if we are done with a zig prepare for zag
m = -1;
randMoveType ++;
}
if (randMoveType % 2 == 0){
curMove = move1;
}
else if (randMoveType % 2 == 1){
curMove = move2;
}
else {
curMove = move3;
}
m++;
threeFollowBoatPositions[i] = {currX3f+curMove.first,currY3f+curMove.second};
}
}
else {
threeFollowBoatPositions[i] = {-1,-1};
}
myfile << currX << "," << currY << "," << currXc << "," << currYc
<< "," << currXf << "," << currYf << "," <<runner.first << "," << runner.second << "," << currX3f << "," << currY3f << "\n";
if (i % 4 == 1){
if (dir == 1){
runner.first++;
}
else if (dir == 2) {
runner.first --;
}
else if (dir == 3) {
runner.second ++;
}
else{
runner.second--;
}
}
}
myfile.close();
return 0;
}