-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
350 lines (278 loc) · 10.8 KB
/
Copy pathmain.c
File metadata and controls
350 lines (278 loc) · 10.8 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#include "raylib.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "time.h"
int window_width = 900;
int window_height = 450;
int std_blocksize = 10;
typedef struct Node {
int POS_X;
int POS_Y;
int SIZE;
Color COLOR;
} Node;
typedef struct Link {
int STRT_X;
int STRT_Y;
int END_X;
int END_Y;
Color COLOR;
} Link;
typedef struct Connexion {
Node NODE;
Link LINK;
} Connexion;
typedef struct Centralize {
Node Origin;
// four ordinal connections
Connexion North;
Connexion East;
Connexion South;
Connexion West;
// diagonales
Connexion North_East;
Connexion South_East;
Connexion South_West;
Connexion North_West;
// randoms
Connexion Distortion_A;
Connexion Distortion_B;
Connexion Distortion_C;
Connexion Distortion_D;
Connexion Distortions[24];
} Centralize;
Centralize centralize_structure;
// int displace_position(int min, int max){
// unsigned int seed = time(0) * rand();
// // unsigned int seed = time(0);
// return rand_r(&seed) % (max - min + 1) + min;
// }
int displace_distortion(int min, int max){
unsigned int seed = time(0) * rand();
// unsigned int seed = time(0);
return rand_r(&seed) % (max - min + 1) + min;
}
void init_connexion(Connexion* conn, int start_x, int start_y, int end_x, int end_y) {
conn->LINK.STRT_X = start_x;
conn->LINK.STRT_Y = start_y;
conn->LINK.END_X = end_x;
conn->LINK.END_Y = end_y;
conn->NODE.POS_X = end_x - std_blocksize / 2;
conn->NODE.POS_Y = end_y - std_blocksize / 2;
conn->NODE.SIZE = std_blocksize;
}
// Initialize centralize_structure global
void initCentralize(Centralize* centralize_structure, int width, int height){
// Origin
centralize_structure->Origin.POS_X = width/2-std_blocksize/2;
centralize_structure->Origin.POS_Y = height/2-std_blocksize/2;
centralize_structure->Origin.SIZE = std_blocksize;
int center_width = width/2;
int center_height = height/2;
// North
init_connexion(¢ralize_structure->North,center_width, center_height, width/2, displace_distortion(std_blocksize, height * 0.25));
// North East
init_connexion(¢ralize_structure->North_East, center_width, center_height, displace_distortion(width* 0.75, width-std_blocksize), displace_distortion(std_blocksize, height* 0.25));
// North West
init_connexion(¢ralize_structure->North_West, center_width, center_height,displace_distortion(std_blocksize, width* 0.25), std_blocksize);
// East
init_connexion(¢ralize_structure->East, center_width, center_height, displace_distortion(width* 0.75, width-std_blocksize), center_height);
// South
init_connexion(¢ralize_structure->South, center_width, center_height, width/2, displace_distortion(height* 0.75, height-std_blocksize));
// South East
init_connexion(¢ralize_structure->South_East, center_width, center_height, displace_distortion(width* 0.75, width-std_blocksize), displace_distortion(height* 0.75, height-std_blocksize));
// South West
init_connexion(¢ralize_structure->South_West, center_width, center_height, displace_distortion(std_blocksize, width*0.25), displace_distortion(height* 0.75, height-std_blocksize));
// West
init_connexion(¢ralize_structure->West, center_width, center_height, displace_distortion(std_blocksize, width* 0.25), center_height);
// Distortions
// Distortion_A
init_connexion(¢ralize_structure->Distortion_A, width/2, height/2,displace_distortion(width/2, width),displace_distortion(std_blocksize, height/2));
// Distortion_B
init_connexion(¢ralize_structure->Distortion_B, width/2, height/2, displace_distortion(width/2, width),displace_distortion(height/2, height-std_blocksize));
// Distortion_C
init_connexion(¢ralize_structure->Distortion_C, width/2, height/2,displace_distortion(std_blocksize, width/2),displace_distortion(std_blocksize, height/2));
// Distortion_D
init_connexion(¢ralize_structure->Distortion_D, width/2, height/2,displace_distortion(std_blocksize, width/2), displace_distortion(height/2, height-std_blocksize));
int length = sizeof(centralize_structure->Distortions)/ sizeof(centralize_structure->Distortions[0]);
int i;
for (i = 0 ; i < length; i ++){
init_connexion(¢ralize_structure->Distortions[i], center_width, center_height,displace_distortion(std_blocksize, width), displace_distortion(std_blocksize, height));
}
}
void draw_node_at_end_of_line(int blockSize, int posX, int posY){
DrawRectangleLines(posX-blockSize/2, posY-blockSize/2, blockSize, blockSize, RAYWHITE);
};
void draw_line_with_node(int posX, int posY, int endPosX,int EndPosY, int blockSize){
DrawLine(posX, posY, endPosX, EndPosY, RAYWHITE);
draw_node_at_end_of_line(blockSize, endPosX, EndPosY);
}
//void draw_centralized_network(int width, int height, int rd_pos_x_left_down, int rd_pos_y_left_down){
void draw_centralized_network(Centralize* centralize_structure){
// Origin
DrawRectangle(
centralize_structure->Origin.POS_X,
centralize_structure->Origin.POS_Y,
centralize_structure->Origin.SIZE,
centralize_structure->Origin.SIZE,
RAYWHITE);
// North
draw_line_with_node(
centralize_structure->North.LINK.STRT_X,
centralize_structure->North.LINK.STRT_Y,
centralize_structure->North.LINK.END_X,
centralize_structure->North.LINK.END_Y,
std_blocksize
);
// East
draw_line_with_node(
centralize_structure->East.LINK.STRT_X,
centralize_structure->East.LINK.STRT_Y,
centralize_structure->East.LINK.END_X,
centralize_structure->East.LINK.END_Y,
std_blocksize
);
// South
draw_line_with_node(
centralize_structure->South.LINK.STRT_X,
centralize_structure->South.LINK.STRT_Y,
centralize_structure->South.LINK.END_X,
centralize_structure->South.LINK.END_Y,
std_blocksize
);
// West
draw_line_with_node(
centralize_structure->West.LINK.STRT_X,
centralize_structure->West.LINK.STRT_Y,
centralize_structure->West.LINK.END_X,
centralize_structure->West.LINK.END_Y,
std_blocksize
);
// diagonales
// // North East
draw_line_with_node(
centralize_structure->North_East.LINK.STRT_X,
centralize_structure->North_East.LINK.STRT_Y,
centralize_structure->North_East.LINK.END_X,
centralize_structure->North_East.LINK.END_Y,
std_blocksize
);
// // North West
draw_line_with_node(
centralize_structure->North_West.LINK.STRT_X,
centralize_structure->North_West.LINK.STRT_Y,
centralize_structure->North_West.LINK.END_X,
centralize_structure->North_West.LINK.END_Y,
std_blocksize
);
// South East
draw_line_with_node(
centralize_structure->South_East.LINK.STRT_X,
centralize_structure->South_East.LINK.STRT_Y,
centralize_structure->South_East.LINK.END_X,
centralize_structure->South_East.LINK.END_Y,
std_blocksize
);
// South West
draw_line_with_node(
centralize_structure->South_West.LINK.STRT_X,
centralize_structure->South_West.LINK.STRT_Y,
centralize_structure->South_West.LINK.END_X,
centralize_structure->South_West.LINK.END_Y,
std_blocksize
);
// randoms
draw_line_with_node(
centralize_structure->Distortion_A.LINK.STRT_X,
centralize_structure->Distortion_A.LINK.STRT_Y,
centralize_structure->Distortion_A.LINK.END_X,
centralize_structure->Distortion_A.LINK.END_Y,
std_blocksize
);
draw_line_with_node(
centralize_structure->Distortion_B.LINK.STRT_X,
centralize_structure->Distortion_B.LINK.STRT_Y,
centralize_structure->Distortion_B.LINK.END_X,
centralize_structure->Distortion_B.LINK.END_Y,
std_blocksize
);
draw_line_with_node(
centralize_structure->Distortion_C.LINK.STRT_X,
centralize_structure->Distortion_C.LINK.STRT_Y,
centralize_structure->Distortion_C.LINK.END_X,
centralize_structure->Distortion_C.LINK.END_Y,
std_blocksize
);
draw_line_with_node(
centralize_structure->Distortion_D.LINK.STRT_X,
centralize_structure->Distortion_D.LINK.STRT_Y,
centralize_structure->Distortion_D.LINK.END_X,
centralize_structure->Distortion_D.LINK.END_Y,
std_blocksize
);
int length = sizeof(centralize_structure->Distortions)/ sizeof(centralize_structure->Distortions[0]);
int i;
for (i = 0 ; i < length; i ++){
draw_line_with_node(centralize_structure->Distortions[i].LINK.STRT_X, centralize_structure->Distortions[i].LINK.STRT_Y, centralize_structure->Distortions[i].LINK.END_X, centralize_structure->Distortions[i].LINK.END_Y, std_blocksize);
}
};
void draw_tryptique(int one_third,int two_third, int height){
// divide
DrawLine(one_third, 0, one_third, height, RAYWHITE);
DrawLine(two_third, 0, two_third, height, RAYWHITE);
// draw titles
DrawText("Centralized", 4, height-12, 12, RAYWHITE);
DrawText("Decentralized", one_third+4, height-12, 12, RAYWHITE);
DrawText("Distributed", two_third+4, height-12, 12, RAYWHITE);
}
int main(){
int centralize_x_limit = window_width/3;
int two_third = window_width/3*2;
initCentralize(¢ralize_structure,centralize_x_limit, window_height);
InitWindow(window_width, window_height,"netzork");
typedef enum NetzorkState {INTRO = 0, PARADIGMS} NetzorkState;
NetzorkState netzorkState = INTRO;
int frameCounter = 0;
SetTargetFPS(60); // sets targetFPS
while (!WindowShouldClose())
{
frameCounter ++; // Count frames
// update
switch (netzorkState)
{
case INTRO:
{
if(frameCounter > 120){
netzorkState = PARADIGMS;
}
}
break;
case PARADIGMS:
//SetTargetFPS(1);
if (IsKeyPressed(KEY_R))
{
initCentralize(¢ralize_structure, centralize_x_limit, window_height);
}
SetTargetFPS(3);
initCentralize(¢ralize_structure, centralize_x_limit, window_height);
break;
}
// draw
BeginDrawing();
ClearBackground(BLACK);
DrawText(TextFormat("FPS: %d", GetFPS()), 0, 0, 12, RAYWHITE);
switch (netzorkState)
{
case INTRO: {
DrawText("Welcome to netzork", 0, window_height-24, 24, RAYWHITE);
} break;
case PARADIGMS:{
draw_tryptique(centralize_x_limit, two_third, window_height);
draw_centralized_network(¢ralize_structure);
} break;
}
EndDrawing();
}
CloseWindow();
}