aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2018-03-12 16:36:26 +0100
committerRahiel Kasim <rahielkasim@gmail.com>2018-03-12 16:36:26 +0100
commitff46b01e3493eff93e7fb1cc8db5289753970698 (patch)
tree95998504ba63477ca22910a586ddf9c5bc74ade5
parent39d5f761555950bb5ff347ca6f70e5d4e1dc379e (diff)
implement sticking probabilityHEADmaster
-rw-r--r--index.html22
-rw-r--r--renderer.ts3
-rw-r--r--worker.ts5
3 files changed, 22 insertions, 8 deletions
diff --git a/index.html b/index.html
index 1cd7b80..eb50e79 100644
--- a/index.html
+++ b/index.html
@@ -4,11 +4,16 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <style>
+ .margin-b {
+ margin-bottom: 10px;
+ }
+ </style>
</head>
<body>
<div id="demo">
<label for="config">Configuration:</label>
- <select id="config">
+ <select class="margin-b" id="config">
<option value="middle" selected>Seed in the middle</option>
<option value="bottom">Seed at bottom</option>
</select>
@@ -16,16 +21,21 @@
<br>
<label for="latticeSize">Lattice size:</label>
- <input id="latticeSize" value="400">
+ <input class="margin-b" id="latticeSize" type="number" value="400" step="5" min="10">
<label for="clusterSize">Cluster size:</label>
- <input id="clusterSize" value="6000">
+ <input class="margin-b" id="clusterSize" type="number" value="6000" step="50" min="1">
- <br><br>
+ <br>
+
+ <label for="stickingProbability">Sticking Probability:</label>
+ <input class="margin-b" id="stickingProbability" type="number" value="1.0" step="0.05" min="0.0" max="1.0">
- <button type="button" id="start">Start</button>
+ <br>
- <br><br>
+ <button class="margin-b" type="button" id="start">Start</button>
+
+ <br>
<div id="model"></div>
<span id="workerPath" style="display:none">worker.js</span>
diff --git a/renderer.ts b/renderer.ts
index f675010..ee22a50 100644
--- a/renderer.ts
+++ b/renderer.ts
@@ -20,6 +20,7 @@ function start() {
let config = (<HTMLInputElement>document.getElementById("config")).value;
let latticeSize = parseInt((<HTMLInputElement>document.getElementById("latticeSize")).value);
let clusterSize = parseInt((<HTMLInputElement>document.getElementById("clusterSize")).value);
+ let stickingProbability = parseFloat((<HTMLInputElement>document.getElementById("stickingProbability")).value);
let scale = 2;
let [width, height] = [latticeSize * scale, latticeSize * scale];
@@ -38,7 +39,7 @@ function start() {
render();
}
- worker.postMessage([latticeSize, clusterSize, config]);
+ worker.postMessage([latticeSize, clusterSize, stickingProbability, config]);
}
diff --git a/worker.ts b/worker.ts
index bf30f72..3a3f0dc 100644
--- a/worker.ts
+++ b/worker.ts
@@ -2,7 +2,7 @@ import { choice, randrange, zeros } from "./utils";
onmessage = function (e) {
- let [lattice_size, cluster_size, config] = e.data;
+ let [lattice_size, cluster_size, sticking_probability, config] = e.data;
let padding = 2;
let lattice = zeros(lattice_size + padding, lattice_size + padding);
@@ -72,6 +72,9 @@ onmessage = function (e) {
walking = false;
} else if (lattice[x+1][y] == 1 || lattice[x-1][y] == 1 ||
lattice[x][y+1] == 1 || lattice[x][y-1] == 1) {
+ if (Math.random() > sticking_probability) {
+ continue;
+ }
lattice[x][y] = 1;
num_particles++;
walking = false;