From ce60972fcb333adfaa20aa2e21a78e60f665db77 Mon Sep 17 00:00:00 2001 From: FintasticMan <52415484+FintasticMan@users.noreply.github.com> Date: Tue, 19 Jan 2021 08:48:34 +0100 Subject: [PATCH] Add an interactive UI This brings an interactive UI with the options to pause the sim, hide individual elements or the whole thing, and change the speed at which it runs. This also adds a system where if the only car that's left is the best one from last time, it will just kill that car. This saves a bunch of time while training because whenever there are no improvements in a generation, you don't have to wait for the car to die to go to the next gen. --- car.js | 11 ++++- index.html | 20 +++++++- sketch.js | 137 ++++++++++++++++++++++++++++++++++++++++------------- style.css | 4 ++ 4 files changed, 136 insertions(+), 36 deletions(-) create mode 100644 style.css diff --git a/car.js b/car.js index 150882d..c12e8ee 100644 --- a/car.js +++ b/car.js @@ -58,6 +58,15 @@ class Car { rect(0, 0, this.l, this.w); pop(); + + if (showFitness) { + push(); + textFont("monospace"); + textSize(16); + fill(0, 255, 0); + text(this.score, this.pos.x + 5, this.pos.y - 5); + pop(); + } } isColliding(track) { @@ -184,7 +193,7 @@ class Car { for (let i = 0; i < casts.length; i++) { push(); stroke(255); - strokeWeight(2); + strokeWeight(1); line(this.pos.x, this.pos.y, casts[i].x, casts[i].y); pop(); } diff --git a/index.html b/index.html index 07db8bc..a26d103 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,24 @@ + -
+ + + +
+ FPS: 0
+
CPS: 0 (calculations per second)
+
cars: 0
+
generation: 0
+
+
+
+
+
+
speed: 1 116
+