terrain-map
ARCHIVED - repo for blog post http://www.vogt.world/writing/procedural-terrain-generation/
git clone https://git.vogt.world/terrain-map.git
Log | Files | README.md
← Commit log
commit
message
drying code, web workers fully implemented
author
Ben Vogt <[email protected]>
date
2016-05-14 05:12:31
stats
3 file(s) changed, 10 insertions(+), 57 deletions(-)
files
index.html
main.js
worker.js
  1diff --git a/index.html b/index.html
  2index 3c9e61b..275edfe 100644
  3--- a/index.html
  4+++ b/index.html
  5@@ -29,7 +29,7 @@
  6           <button class="run button-primary" id="standard">GENERATE</button>
  7         </p>
  8       </div>
  9-      <div class="set-of" id="container-1"></div>
 10+      <div class="set-of" id="container-standard"></div>
 11       <hr>
 12     </div>
 13     <!-- container-2 -->
 14@@ -48,7 +48,7 @@
 15           <button class="run button-primary" id="combined">GENERATE</button>
 16         </p>
 17       </div>
 18-      <div class="set-of" id="container-2"></div>
 19+      <div class="set-of" id="container-combined"></div>
 20       <hr>
 21     </div>
 22     <!-- container-3 -->
 23@@ -60,7 +60,7 @@
 24           <button class="run button-primary" id="grd">GENERATE</button>
 25         </p>
 26       </div>
 27-      <div class="set-of" id="container-3"></div>
 28+      <div class="set-of" id="container-grd"></div>
 29       <hr>
 30     </div>
 31     <!-- container-4 -->
 32@@ -73,7 +73,7 @@
 33           <button class="run button-primary" id="simpleErosion">GENERATE</button>
 34         </p>
 35       </div>
 36-      <div class="set-of" id="container-4"></div>
 37+      <div class="set-of" id="container-simpleErosion"></div>
 38       <hr>
 39     </div>
 40     <!-- container-5 -->
 41@@ -85,7 +85,7 @@
 42           <button class="run button-primary" id="complexErosion">GENERATE</button>
 43         </p>
 44       </div>
 45-      <div class="set-of" id="container-5"></div>
 46+      <div class="set-of" id="container-complexErosion"></div>
 47       <hr>
 48     </div>
 49     <!-- hidden canvas for rendering-->
 50diff --git a/main.js b/main.js
 51index ccd8e92..38a770b 100644
 52--- a/main.js
 53+++ b/main.js
 54@@ -1,56 +1,14 @@
 55 var worker;
 56 $(document).ready(function() {
 57-
 58   function spinner(id) {
 59     var spinner = '<img class="spinner" width="24" height="24" src="data:image/gif;base64,R0lGODlhGAAYAKUAAAwODJSSlMzKzExOTKyurOTm5GxubCwuLLy+vKSipNza3GRmZPT29Dw+PFRWVLS2tHx+fDQ2NCQmJJyanNTW1Ozu7MTGxKyqrOTi5Pz+/BwaHMzOzFRSVLSytHx6fDQyNMTCxKSmpNze3GxqbPz6/ExKTFxaXLy6vISGhDw6PJyenPTy9P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJBQAsACwAAAAAGAAYAAAG/kCWcEjMeCDEpJK1Oq2EDIeDJKwknkshYjERkjhToedzyVZHCwUrGt58GhWz8LFAkb7TjOmjWjIEWAweCxYkIwYkBB8DVCwFKnEsIBAoIFQCHhtEJwMgawESGl1rFxAQARQZDEoMJA8RGhoLkUIiE6erSysfGiUWSyQCFHIdIY1DGSQZyXJQJK2rHSrTKgTNLAcA2gAl0gkqCWXN2dslLHd3GdfPJCvHQxgFchgYWRUgBAjvRCQIHSC0zgno0AGBvH3nHJ0guKGRiA4PFKgrYJAIxYMUHnQQAUVELhILMWQAgSADhoKNGIhAyELBv3MPHlAB0UGNHAYa47g6QaUCHQGZch5qYpEhpjoWGzbKIaGgkasHR5myNGNBQLMgACH5BAkFADAALAAAAAAYABgAhQQCBISChMTCxERCROTi5KSipGRmZNTS1PTy9LSytCQiJJSSlFRWVDQyNIyKjMzKzOzq7KyqrHx+fNza3Pz6/Ly6vExKTGxubJyanFxeXDw+PAwODISGhMTGxOTm5KSmpGxqbNTW1PT29LS2tCQmJFxaXDQ2NIyOjMzOzOzu7KyurNze3Pz+/Ly+vExOTJyenP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAb+QJhwSGSdFsSkEibqiIQUEIgiTKkQy2EnEBGKQBcqzOFKZI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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAb+QJhwSGyBQMSkEpZYJYSjU2YihJRUy+Gqc4FKqTCD5ZUVqh4dESw6hQksIUhZGOkwJqPMadIaWBZLCS5PTAYdFBMPDxMFFg0jQh4LWDAUBiAkVAIGHEQkDRRrARoAXUwlBgYmKHhKCS0RIQAAKXJDEgGqkIEWAA0uSxMCKHMRLy1JE8p8c0J8zzAFARvTJc1uJNkkDi/U1NbNAiQUCtsweMrIzcstYEMtIixzBARZHhEVH+7JLgoClFBcVCjxgUU7JVQ89FPASgiCEi8QJKTggYjCihNEkFAgbw0CQhPIEWghwEULAgpcgBnBYt+tlDBaZNOkQEKzERuxTBhHBcIdikxzWDAUIhMoDBQc50yQAGYnImcSdl0TwqHTnCAAOw==" />';
 60     this.document.getElementById(id).innerHTML = spinner;
 61   }
 62 
 63-  $("#standard").click(function() {
 64-    spinner("container-1");
 65-    var worker = new Worker('worker.js');
 66-    worker.postMessage("standard");
 67-    worker.addEventListener('message', function(e) {
 68-      var terrain = new LandMap(e.data);
 69-      terrain.draw();
 70-    }, false);
 71-  });
 72-
 73-  $("#combined").click(function() {
 74-    spinner("container-2");
 75-    var worker = new Worker('worker.js');
 76-    worker.postMessage("combined");
 77-    worker.addEventListener('message', function(e) {
 78-      var terrain = new LandMap(e.data);
 79-      terrain.draw();
 80-    }, false);
 81-  });
 82-
 83-  $("#grd").click(function() {
 84-    spinner("container-3");
 85-    var worker = new Worker('worker.js');
 86-    worker.postMessage("grd");
 87-    worker.addEventListener('message', function(e) {
 88-      var terrain = new LandMap(e.data);
 89-      terrain.draw();
 90-    }, false);
 91-  });
 92-
 93-
 94-  $("#simpleErosion").click(function() {
 95-    spinner("container-4");
 96-    var worker = new Worker('worker.js');
 97-    worker.postMessage("simpleErosion");
 98-    worker.addEventListener('message', function(e) {
 99-      var terrain = new LandMap(e.data);
100-      terrain.draw();
101-    }, false);
102-  });
103-
104-  $("#complexErosion").click(function() {
105-    spinner("container-5");
106+  $("button").click(function(event) {
107+    spinner("container-" + event.target.id);
108     var worker = new Worker('worker.js');
109-    worker.postMessage("complexErosion");
110+    worker.postMessage(event.target.id);
111     worker.addEventListener('message', function(e) {
112       var terrain = new LandMap(e.data);
113       terrain.draw();
114diff --git a/worker.js b/worker.js
115index 03a6a1b..324d85a 100644
116--- a/worker.js
117+++ b/worker.js
118@@ -5,7 +5,7 @@ self.addEventListener('message', function(e) {
119   switch (data) {
120     case 'complexErosion':
121       terrain = new LandMap({
122-        containerId: "container-5"
123+        containerId: "container-complexErosion"
124       });
125       terrain.generate(0.75, "standard");
126       terrain.complexErosion({
127@@ -19,7 +19,7 @@ self.addEventListener('message', function(e) {
128       break;
129     case 'simpleErosion':
130       terrain = new LandMap({
131-        containerId: "container-4"
132+        containerId: "container-simpleErosion"
133       });
134       terrain.generate(0.75, "standard");
135       terrain.simpleErosion({
136@@ -33,7 +33,7 @@ self.addEventListener('message', function(e) {
137       break;
138     case 'grd':
139       terrain = new LandMap({
140-        containerId: "container-3"
141+        containerId: "container-grd"
142       });
143       terrain.generate(0.75, "standard");
144       terrain.grd(22, 0.01, "standard", "grd-22-0.01");
145@@ -42,7 +42,7 @@ self.addEventListener('message', function(e) {
146       break;
147     case 'combined':
148       terrain = new LandMap({
149-        containerId: "container-2"
150+        containerId: "container-combined"
151       });
152       terrain.generate(0.75, "standard");
153       terrain.generate(0.75, "standard-two", "DS with 0.75");
154@@ -53,13 +53,12 @@ self.addEventListener('message', function(e) {
155       break;
156     case 'standard':
157       terrain = new LandMap({
158-        containerId: "container-1"
159+        containerId: "container-standard"
160       });
161       terrain.generate(0.75, "standard");
162       terrain.smooth(10, "standard", "smoothed-10");
163       terrain.smooth(20, "standard", "smoothed-20");
164       break;
165   };
166-  console.log(terrain)
167   self.postMessage(terrain);
168 }, false);