-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.js
118 lines (107 loc) · 3.56 KB
/
Main.js
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
let Rockets = [];
let SavedRockets = [];
let PlatformX;
let PlatformScatter = 0;
let DemonstrationScatter;
let PreTrainedModel;
let PreTrainedModelBrainData;
let Mode = "Learning";
let Population = 1500;
let Groups = 10;
const RocketsPerGroup = Population / Groups;
let CurrentGroupNum = 1;
let CurrentGroup = [];
let LifeSpan = 600;
let TimeScale = 1;
let GlobalCamera;
let GlobalScale = 1;
function preload(){
PreTrainedModelBrainData = loadJSON("PreTrainedModel.json");
ThiccFont = loadFont('Fonts/Roboto-Black.ttf');
ThinFont = loadFont('Fonts/Roboto-Thin.ttf');
RegularFont = loadFont('Fonts/Roboto-Regular.ttf');
loadFont('Fonts/Roboto-Black.ttf');
loadFont('Fonts/Roboto-Thin.ttf');
loadFont('Fonts/Roboto-Regular.ttf');
}
function setup() {
DetectDevice();
PlatformX = new Platform;
LoadPretrainedModel();
for (let i = 0; i < Population; ++i){
Rockets[i] = new Rocket;
}
GlobalCamera = new Camera;
CurrentGroup = Rockets.splice(0, RocketsPerGroup);
createCanvas(window.innerWidth, window.innerHeight);
SetUpUI();
frameRate(60);
}
function draw() {
background(18);
TimeScale = TimeScaleSlider.value();
ApplyUI();
if (Mode == "Learning" && Device != "Phone"){
TestCounter = 0;
LandsCounter = 0;
Train(TimeScale);
if (ShowEveryone){
for (let i = 0; i < CurrentGroup.length; ++i){
CurrentGroup[i].Render(GlobalCamera, GlobalScale, PlatformX, "UnFollowing");
}
AdaptScale();
GlobalCamera.GoTo(PlatformX.Body.PosX - (windowWidth / 2), PlatformX.Body.PosY - (windowHeight - 100));
PlatformX.Render(GlobalScale, GlobalCamera);
DrawSpawnPoint();
}
else{
if (CurrentGroup.length > 0){
if (TimeScale < 2){
GlobalCamera.Follow(CurrentGroup[0].Body);
AdaptScale(CurrentGroup[0].Body);
CurrentGroup[0].Render(GlobalCamera, GlobalScale, PlatformX);
PlatformX.Render(GlobalScale, GlobalCamera, CurrentGroup[0]);
}
else{
GlobalCamera.GoTo(PlatformX.Body.PosX - (windowWidth / 2), PlatformX.Body.PosY - (windowHeight - 100));
AdaptScale();
CurrentGroup[0].Render(GlobalCamera, GlobalScale, PlatformX, "UnFollowing");
PlatformX.Render(GlobalScale, GlobalCamera);
DrawSpawnPoint();
}
}
}
}
else if (Mode == "Demonstration" || Device == "Phone"){
if (Device != "Phone")
DemonstrationScatter = DemonstrationScatterSlider.value();
else
DemonstrationScatter = windowHeight / 1.5;
for (let i = 0; i < TimeScale; ++i){
if (PreTrainedModel.HasCrashed){
TestCounter++;
PreTrainedModel = new Rocket(PreTrainedModel);
PlatformX = new Platform(random(windowWidth / 2 - DemonstrationScatter, windowWidth / 2 + DemonstrationScatter), random(0, DemonstrationScatter));
}
PreTrainedModel.Update(LifeSpan);
if (PreTrainedModel.Timer > LifeSpan){
if (PreTrainedModel.HasLanded)
LandsCounter++;
PreTrainedModel.HasCrashed = true;
}
}
if (TimeScale <= 1){
GlobalCamera.Follow(PreTrainedModel.Body);
AdaptScale(PreTrainedModel.Body);
PreTrainedModel.Render(GlobalCamera, GlobalScale, PlatformX);
PlatformX.Render(GlobalScale, GlobalCamera, PreTrainedModel);
}
else{
GlobalCamera.GoTo(PlatformX.Body.PosX - (windowWidth / 2), PlatformX.Body.PosY - (windowHeight - 100));
AdaptScale();
PreTrainedModel.Render(GlobalCamera, GlobalScale, PlatformX, "UnFollowing");
PlatformX.Render(GlobalScale, GlobalCamera);
DrawSpawnPoint();
}
}
}