Brownian motion.
This commit is contained in:
parent
91ca45c4c8
commit
4e09d193bf
2 changed files with 90 additions and 0 deletions
|
@ -36,6 +36,12 @@ var touch_identifier
|
||||||
var moving_origin = []
|
var moving_origin = []
|
||||||
var moving_epsilon = 0.04
|
var moving_epsilon = 0.04
|
||||||
|
|
||||||
|
// brownian motion constants
|
||||||
|
var brownian_callback = false
|
||||||
|
var brownian_eps = 0.1
|
||||||
|
var brownian_time = 50
|
||||||
|
var brownian_time_elapsed = 0
|
||||||
|
|
||||||
function p_to_canv_coords(x, y) {
|
function p_to_canv_coords(x, y) {
|
||||||
return [p_canvas.width * (x + p_scale) / (2 * p_scale), p_canvas.height * (-y + p_scale) / (2 * p_scale)]
|
return [p_canvas.width * (x + p_scale) / (2 * p_scale), p_canvas.height * (-y + p_scale) / (2 * p_scale)]
|
||||||
}
|
}
|
||||||
|
@ -244,7 +250,21 @@ function zoom_out_dr() {
|
||||||
update_zoom()
|
update_zoom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clear_matrix() {
|
||||||
|
brownian_time_elapsed = 0
|
||||||
|
|
||||||
|
matrix_entries = []
|
||||||
|
for (let i = 0; i < 2 * dim * dim; i++) {
|
||||||
|
matrix_entries[i] = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
p_draw()
|
||||||
|
dr_draw()
|
||||||
|
}
|
||||||
|
|
||||||
function randomize_matrix() {
|
function randomize_matrix() {
|
||||||
|
brownian_time_elapsed = 0
|
||||||
|
|
||||||
matrix_entries = []
|
matrix_entries = []
|
||||||
for (let i = 0; i < dim * dim; i++) {
|
for (let i = 0; i < dim * dim; i++) {
|
||||||
matrix_entries.push((6.0 * Math.random()) - 3.0)
|
matrix_entries.push((6.0 * Math.random()) - 3.0)
|
||||||
|
@ -302,6 +322,8 @@ function enter_matrix() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
brownian_time_elapsed = 0
|
||||||
|
|
||||||
matrix_entries = entries
|
matrix_entries = entries
|
||||||
make_grid()
|
make_grid()
|
||||||
p_draw()
|
p_draw()
|
||||||
|
@ -310,6 +332,8 @@ function enter_matrix() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dim_update() {
|
function dim_update() {
|
||||||
|
brownian_time_elapsed = 0
|
||||||
|
|
||||||
var old_dim = dim
|
var old_dim = dim
|
||||||
dim = Number(document.getElementById("dim").value)
|
dim = Number(document.getElementById("dim").value)
|
||||||
update_dr_scale()
|
update_dr_scale()
|
||||||
|
@ -356,6 +380,8 @@ function dim_update() {
|
||||||
var input_timers = {};
|
var input_timers = {};
|
||||||
|
|
||||||
function input_update(e) {
|
function input_update(e) {
|
||||||
|
brownian_time_elapsed = 0
|
||||||
|
|
||||||
const input = e.srcElement;
|
const input = e.srcElement;
|
||||||
const row = input.dataset.row;
|
const row = input.dataset.row;
|
||||||
const col = input.dataset.col;
|
const col = input.dataset.col;
|
||||||
|
@ -546,3 +572,58 @@ function mouse_up(e) {
|
||||||
mouse_moving = false
|
mouse_moving = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function brownian_checkbox() {
|
||||||
|
if (document.getElementById('brownian').checked) {
|
||||||
|
brownian_time_elapsed = 0
|
||||||
|
brownian_callback = window.setInterval(brownian_motion, brownian_time)
|
||||||
|
document.getElementById('brownian_modifiers').style.display = 'block'
|
||||||
|
} else {
|
||||||
|
window.clearInterval(brownian_callback)
|
||||||
|
document.getElementById('brownian_modifiers').style.display = 'none'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function brownian_freq_update() {
|
||||||
|
f = document.getElementById('brownian_freq').value
|
||||||
|
if (f < 10) f = 10
|
||||||
|
if (f > 10000) f = 10000
|
||||||
|
document.getElementById('brownian_freq').value = f
|
||||||
|
|
||||||
|
if (document.getElementById('brownian').checked) {
|
||||||
|
window.clearInterval(brownian_callback)
|
||||||
|
brownian_callback = window.setInterval(brownian_motion, brownian_time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function brownian_eps_update() {
|
||||||
|
e = document.getElementById('brownian_eps').value
|
||||||
|
if (e <= 0) e = 0
|
||||||
|
if (e > 6) e = 6
|
||||||
|
document.getElementById('brownian_eps').value = e
|
||||||
|
brownian_eps = e
|
||||||
|
}
|
||||||
|
|
||||||
|
function brownian_motion() {
|
||||||
|
brownian_time_elapsed += brownian_time
|
||||||
|
|
||||||
|
entries = matrix_entries
|
||||||
|
for (let i = 0; i < 2 * dim * dim; i++) {
|
||||||
|
entries[i] += brownian_eps * Math.sqrt(0.0001 * brownian_time_elapsed) * gaussian_random()
|
||||||
|
if (-3 > entries[i]) entries[i] = -3;
|
||||||
|
if (entries[i] > 3) entries[i] = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_entries = entries
|
||||||
|
make_grid()
|
||||||
|
p_draw()
|
||||||
|
dr_draw()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/36481059
|
||||||
|
function gaussian_random(mean = 0, stdev = 0.5) {
|
||||||
|
const u = 1 - Math.random();
|
||||||
|
const v = Math.random();
|
||||||
|
const z = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
|
||||||
|
return z * stdev + mean;
|
||||||
|
}
|
|
@ -48,6 +48,7 @@ canvas {
|
||||||
|
|
||||||
|
|
||||||
<button id="enhance" type="button" onclick="enhance()" disabled>enhance</button>
|
<button id="enhance" type="button" onclick="enhance()" disabled>enhance</button>
|
||||||
|
<button id="clear_button" type="button" onclick="clear_matrix()">clear</button>
|
||||||
<button id="randomize_button" type="button" onclick="randomize_matrix()">randomize</button>
|
<button id="randomize_button" type="button" onclick="randomize_matrix()">randomize</button>
|
||||||
<button id="zoom_in_button" type="button" onclick="zoom_in_dr()">+</button>
|
<button id="zoom_in_button" type="button" onclick="zoom_in_dr()">+</button>
|
||||||
<button id="zoom_out_button" type="button" onclick="zoom_out_dr()">-</button>
|
<button id="zoom_out_button" type="button" onclick="zoom_out_dr()">-</button>
|
||||||
|
@ -58,6 +59,14 @@ canvas {
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
<input type="checkbox" id="brownian" onclick="brownian_checkbox()">Brownian motion</input>
|
||||||
|
<div id="brownian_modifiers" style="display:none">
|
||||||
|
update time = <input type="number" id="brownian_freq" onChange="brownian_freq_update()" value="50" min="10" max="10000" style="width: 100px;"> ms <br>
|
||||||
|
speed = <input type="number" id="brownian_eps" onChange="brownian_eps_update()" value="0.1" min="0" max="6" style="width: 100px;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
<a href="https://arxiv.org/abs/2310.03227">paper</a> by
|
<a href="https://arxiv.org/abs/2310.03227">paper</a> by
|
||||||
<a href="https://web.math.princeton.edu/~oeh">Otte Heinävaara</a>.
|
<a href="https://web.math.princeton.edu/~oeh">Otte Heinävaara</a>.
|
||||||
<a href="https://ahti.space/git/shikhin/tjsm">source</a>.
|
<a href="https://ahti.space/git/shikhin/tjsm">source</a>.
|
||||||
|
|
Loading…
Reference in a new issue