-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathself-driving-cars.html
202 lines (166 loc) · 5.71 KB
/
self-driving-cars.html
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
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/components/icon.min.css" type="text/css">
<link rel="stylesheet" href="css/semantic.css" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css">
</head>
<style>
canvas {
margin: 0 auto;
border: 2px solid black;
transform: scale(1);
}
.canvas-container {
display: flex;
align-items: center;
justify-content: center;
}
input[type=range] {
float: left;
width: 15em;
height: 2em;
}
label {
float: left;
width: 12em;
display: inline-block;
clear: both;
height: 2em;
}
label:hover {
background-color: #eaeaea;
cursor: pointer;
}
.range-value {
display: table-cell;
height: 2em;
vertical-align: middle;
padding: 0.2em;
}
.tooltip {
position: relative;
/* making the .tooltip span a container for the tooltip text */
color: blue;
}
.tooltip:before {
content: attr(data-text);
/* here's the magic */
position: absolute;
/* vertically center */
top: 50%;
transform: translateY(-50%);
/* move to right */
left: 100%;
margin-left: 15px;
/* and add a small left margin */
/* basic styles */
width: 200px;
padding: 10px;
border-radius: 10px;
background: #000;
color: #fff;
text-align: center;
display: none;
/* hide by default */
}
.tooltip:hover:before {
display: block;
}
.custom-msg {
border: none;
border-left: #27AE60 5px solid;
border-radius: 0;
background-color: #D5F5E3;
padding: 1em;
margin: 1em;
}
.custom-msg .header {
font-weight: 900;
font-size: 1.5em;
padding-bottom: 1em;
}
</style>
<body>
<div class="ui menu">
<a class="item" href="mywork.html">
<i class="left arrow icon"></i>
Back to my projects
</a>
</div>
<div class="ui container">
<div class="ui green custom-msg big">
<div class="header">How to use?</div>
If the simulation is stuck, click <b>New Population</b> button to start a new generation. Increase the simulation speed if you don't like waiting. Cars take roughly 1-3 minutes to learn how to drive around the map (on speed x10).
<br><br>
If you're lazy just use a preset which has a pre-trained car.
<br>
Left Click to build a block.<br>
Right Click to delete a block.
</div>
</div>
<div class="ui container">
<div class="canvas-container">
<canvas id="canvas" width=800 height=400 oncontextmenu="return false;"></canvas>
</div>
<div style="text-align: center;">
<a href="#" onclick="canvas.requestFullscreen();">Click me enter fullscreen mode.</a>
</div>
</div>
<img src="images/car.png" id="car" style="display: none;">
<div class="ui custom-msg green">
Click on a label to reset the setting.
</div>
<form onsubmit="return false;">
<fieldset>
<legend>Settings</legend>
<label for="simRunning">Run Simulation</label>
<input type="checkbox" id=simRunning checked><br><br>
<label for="simSpeed">Simulation Speed</label>
<input type="range" min=1 max=100 value=1 id="simSpeed">
<br>
<button class="ui button red" onclick="NewPopulation();">New Population</button>
</fieldset>
</form>
<form onsubmit="return false;">
<fieldset>
<legend>Physics Settings</legend>
<label for="friction_val" class="tooltip" data-text="Percentage of the counter movement force every physics step.">Friction</label>
<input type="range" value=0.95 min=0 max=1 step=0.01 id=friction_val class="range">
<label for="acceleration_val" class="tooltip" data-text="How quickly we can increase our velocity.">Acceleration</label>
<input type="range" id=acceleration_val value=0.3 min=0.1 max=2 step=0.1>
</fieldset>
</form>
<form onsubmit="return false;">
<fieldset>
<legend>Presets</legend>
<button class="ui button tooltip" onclick="LoadPreset();" data-text="Model trained on: friction=0.95, acceleration=0.3. Use these settings for best results.">Trained Model</button>
</fieldset>
</form>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$('input[type=range]').each(function() {
var id = $(this).attr('id');
$("<div class=range-value data-id=" + id + ">" + $(this).val() + "</div>").insertAfter(this);
var defaultVal = $(this).val();
$(`label[for=${id}]`).click(function() {
$('#' + id).val(defaultVal);
UpdateSliderTooltip(id);
})
})
$('input[type=range]').on("input", function(event) {
UpdateSliderTooltip($(this).attr('id'));
})
function UpdateSliderTooltip(id) {
var val = $('#' + id).val();
$('div[data-id=' + id + ']').html(val);
}
</script>
<script src="Vector.js"></script>
<script src="Matrix.js"></script>
<script src="NeuralNetwork.js"></script>
<script src="self-driving-cars.js"></script>