Skip to content

Commit d32ff69

Browse files
committed
Basic framework ready
1 parent c6b121a commit d32ff69

File tree

3 files changed

+353
-4
lines changed

3 files changed

+353
-4
lines changed

tdp/basic.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(naviga
1212
let canvas = document.getElementById("canvas");
1313
let context = canvas.getContext("2d");
1414

15+
let pause_button = document.getElementById("pause-button");
16+
17+
let p_display = document.getElementById("p-display");
18+
let p_input = document.getElementById("p-input");
19+
let q_display = document.getElementById("q-display");
20+
let q_input = document.getElementById("q-input");
21+
let speed_display = document.getElementById("speed-display");
22+
let speed_input = document.getElementById("speed-input");
23+
let occupancy_display = document.getElementById("occupancy-display");
24+
1525
if (mobile) {
1626
canvas_width = 0.9 * screen_width;
1727
}
1828
else {
19-
canvas_width = 0.4 * screen_width;
29+
canvas_width = 0.45 * screen_width;
2030
}
2131
canvas_height = canvas_width;
2232

@@ -45,7 +55,19 @@ window.onload = function () {
4555
}
4656

4757
function defaultParams() {
48-
58+
p_input.value = 0.7;
59+
q_input.value = 0;
60+
speed_input.value = 1;
61+
}
62+
63+
function pauseToggle() {
64+
paused = !paused;
65+
if (paused) {
66+
pause_button.innerHTML = "Resume";
67+
}
68+
else {
69+
pause_button.innerHTML = "Pause";
70+
}
4971
}
5072

5173
let click_x, click_y, pressed;

tdp/simulation.html

+64-1
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,83 @@ <h1 id="main-heading">Visualize It</h1>
4949
<div class="text">
5050
<h2>Tricritical Directed Percolation</h2>
5151

52+
<center>
53+
<p>Tricritical Directed Percolation (TDP) is a DP-class model that can be used to study
54+
vegetation dynamics, not only because the processes in this model have analogies in the
55+
context of ecology, but also because it possesses both continuous and abrupt transitions.</p>
56+
</center>
57+
<br>
58+
5259
<div class="container" style="width:90%">
5360
<div class="row">
5461
<div class="col s12 l8">
5562
<canvas id="canvas"></canvas>
5663
</div>
5764
<div class="col s12 l4">
58-
65+
<hr>
66+
<center>
67+
<p>
68+
<b>Green:</b> Vegetation (Occupied)
69+
<br>
70+
<b>Black:</b> Desert (Unoccupied)
71+
</p>
72+
<p id="occupancy-display"></p>
73+
<hr>
74+
<b>Simulation controls:</b>
75+
<br> <br>
76+
<span id="p-display"></span>
77+
<input id="p-input" type="range" min="0" max="1" step="0.01" oninput="updateParams('p')"
78+
onchange="updateParams('p')">
79+
80+
<span id="q-display"></span>
81+
<input id="q-input" type="range" min="0" max="1" step="0.01" oninput="updateParams('q')"
82+
onchange="updateParams('q')">
83+
84+
<span id="speed-display"></span>
85+
<input id="speed-input" type="range" min="1" max="10" step="1" oninput="updateParams('speed')"
86+
onchange="updateParams('speed')">
87+
<br> <br>
88+
89+
<button id="pause-button" class="btn purple darken-4" onclick="pauseToggle()">Pause</button>
90+
<button class="btn purple darken-4" onclick="initParams()">Restart</button>
91+
<br> <br>
92+
<b>If the landscape has gone completely barren or become completely filled, then press 'Restart' to
93+
repopulate</b>
94+
<hr>
95+
</center>
5996
</div>
6097
</div>
6198
</div>
6299

63100
<br>
64101
<hr>
65102

103+
<h3>Working</h3>
104+
105+
The system consists of an N x N array of cells wherein each cell can be either 0 (unoccupied) or 1 (occupied). The
106+
transitions are dictated as follows:
107+
108+
<ol>
109+
<li>Step 1: Select a random cell. Call this the 'focal cell'</li>
110+
<li>Step 2: If the focal cell is unoccupied, return to step (1). Otherwise, proceed to step (3)</li>
111+
<li>Step 3: Randomly select one of its four Von-Neumann neighbours. If the selected neighbour is unoccupied, then
112+
proceed to step (d). Otherwise, proceed to step (e)</li>
113+
<li>Step 4: With probability p, update the unoccupied neighbour cell from 0 to 1. This process is
114+
reproduction. Otherwise (with probability 1 - p), update the focal cell from 1 to 0.
115+
This is stochastic death.</li>
116+
<li>Step 5: The focal cell and neighbour cell collectively have 6 Von-Neumann neighbours. Select
117+
one at random. With probability q, update the selected cell to 1 (irrespective of its initial
118+
state). This is positive-feedback birth. Otherwise (with probability 1- q), update the
119+
focal cell from 1 to 0. This is density death.</li>
120+
</ol>
121+
122+
<br>
123+
<hr>
124+
<br>
125+
126+
<br>
127+
<hr>
128+
66129
<p class="center-align">Developed by ChanRT | Fork me at <a href="https://www.github.com/chanrt">GitHub</a></p>
67130
</div>
68131
</body>

0 commit comments

Comments
 (0)