Commits

Benoît Allard  committed 9106ed9

Add random fields + more examples + possibility to choose from interface

  • Participants
  • Parent commits 8569ca9

Comments (0)

Files changed (2)

   </canvas>
   <img id=map alt="Map">
  </div>
+
  <div>
   <button onclick="sim.startInterval()" id=startBtn>Start</button>
   <button onclick="sim.stopInterval()" id=pauseBtn>Pause</button>
   <button onclick="sim.reset()" id=resetBtn>Reset</button>
   <button onclick="sim.step()" id=stepBtn>Perform one Step</button>
+  <label for="speed">Speed:</label>
+  <input name="speed"
+         type="number"
+         value=".1"
+         min=".1"
+         max="2"
+         step=".1"
+         onchange="sim.harvester.fullworkingspeed=this.value" />
+ </div>
+ <div>
+  <p>Parameters below only take effect on 'Reset'.</p>
+  <label for="fields">Field:</field>
+  <select name=fields id=fields>
+  </select>
  </div>
 
  <script type="text/javascript" src="script.js" ></script>
 
 
 var fields = [
-    [{x:8, y:25}, {x:130, y:1}, {x:130, y:130}, {x:1, y:130}],
-    [{x:80, y:250}, {x:120, y:225}, {x:100, y:300}, {x:90, y:290}, {x:80, y:260}],
-    toMeters([{lon:5.8427743, lat:50.2649766}, {lon:5.8431924, lat:50.2651622},
-              {lon:5.8439405, lat:50.2653564}, {lon:5.8444906, lat:50.2654070},
-              {lon:5.8447591, lat:50.2645574}, {lon:5.8449841, lat:50.2640527},
-              {lon:5.8433728, lat:50.2637359}]) // 117739400
+    {name: 'Example 1 (square)',
+      points: [{x:8, y:25}, {x:130, y:1}, {x:130, y:130}, {x:1, y:130}],},
+    {name: 'Example 2 (triangle)',
+     points:[{x:80, y:250}, {x:120, y:225}, {x:100, y:300}, {x:90, y:290}, {x:80, y:260}],},
+    {name: 'Example 3',
+     points:[{x:79.33054908644408,y:1.942973889269548e-14},{x:56.79970569758984,y:19.341928588815637},{x:-52.00030767309893,y:-38.03876438035298},{x:0.3320064831197373,y:-71.49606060408045},{x:48.857938837285104,y:-52.349085357792795}]},
+    {name: 'Example 4', points:[{"x":77.2677519521676,"y":1.8924515997239168e-14},{"x":22.145847935089837,"y":70.99739373003555},{"x":-39.00922121656229,"y":63.41442774542689},{"x":22.305967055182684,"y":-72.31080229409193}]},
+    {name: 'Example 5', points: [{"x":61.977320404257625,"y":1.517956407198783e-14},{"x":17.50011034157625,"y":76.35434721445728},{"x":-71.57081269026901,"y":12.163722542150296},{"x":-24.846350851342986,"y":-70.52182892372107},{"x":-9.424086448965982,"y":-76.65545258735527},{"x":10.247250217904533,"y":-67.31722592444896}]},
+    {name: 'Example 6', points:[{"x":59.50104014482349,"y":1.4573070364078238e-14},{"x":45.19669198569412,"y":53.23884377975345},{"x":-25.51142085507122,"y":48.17018454116998},{"x":-56.43721712870133,"y":-22.80505795733697},{"x":-17.035821485363975,"y":-58.03067279083557},{"x":66.57579329376456,"y":-27.016922832446372}]},
+    {name: 'osm-117739400 (Not working)',
+     points:toMeters([{lon:5.8427743, lat:50.2649766}, {lon:5.8431924, lat:50.2651622},
+                      {lon:5.8439405, lat:50.2653564}, {lon:5.8444906, lat:50.2654070},
+                      {lon:5.8447591, lat:50.2645574}, {lon:5.8449841, lat:50.2640527},
+                      {lon:5.8433728, lat:50.2637359}])},
 ];
 
+var initfieldslen = fields.length;
+
+function randompoints(nbpoints){
+    console.log('randomizing');
+    var pts = []
+    var a = 2*Math.PI;
+    for (var i = 0; i < nbpoints; i++){
+        var b = Math.random() * a;
+        var r = 50 + Math.random()*30;
+        pts[i] = {
+            x: r*Math.cos(-a),
+            y: r*Math.sin(-a)
+        };
+        a -= b;
+    }
+    return pts;
+}
+
+
+// Add tahe random fields
+for (var i = 4; i <= 6; i++){
+    fields[i-4+initfieldslen] = {
+        name:'Random-'+i+'points (Experimental)',
+        points: randompoints(i),
+    };
+}
+
+var fields_el = document.getElementById('fields');
+
+fields_el.options = [];
+for (var i = 0; i < fields.length; i++){
+    fields_el.options[i] = new Option(fields[i].name, i);
+}
+
+
 var sim = null;
 
 init();
 function init(){
     // init the interface
     document.getElementById("pauseBtn").disabled = true;
-    document.getElementById("resetBtn").disabled = true;
+
+    // randomize again
+    for (var i = 4; i <= 6; i++){
+        fields[i-4+initfieldslen].points = randompoints(i);
+    }
+
     // let the field grow again
-    var field = new Field(document.getElementById("field"), fields[1]);
+    var field = new Field(document.getElementById("field"), fields[fields_el.value].points);
     // reset the harvester
     var harvester = new Harvester(document.getElementById("harvester"),
                                   6, 4);