-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfitzhugh-nagumo.html
85 lines (71 loc) · 2.07 KB
/
fitzhugh-nagumo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Fitzhugh-Nagumo Experiment</title>
<style>
* { padding: 0; margin: 0; }
canvas { background: #eee; display: block; margin: 0 auto; }
</style>
</head>
<body>
<canvas id="myCanvas" width="480" height="320"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var vmin = -0.5;
var vmax = 1.5;
var wmin = 0.2;
var wmax = 0.8;
var ptRadius = 5;
var points = [];
var nPoints = 0;
function drawPoints(){
for (i=0; i<nPoints; i++){
var p = points[i];
var x = (p.v - vmin) / (vmax - vmin)*canvas.width;
var y = (1 - (p.w - wmin) / (wmax - wmin))*canvas.height;
ctx.beginPath();
ctx.arc(x, y, ptRadius, 0, Math.PI*2);
ctx.fillStyle = "#990000";
ctx.fill();
ctx.closePath();
}
}
function fhn(u) {
var alpha = 0.1;
var gamma = 0.5;
var epsilon = 0.01;
var Iapp = 0.5;
var v = u[0];
var w = u[1];
var dv = 1/epsilon*(v*(1 - v)*(v - alpha) - w + Iapp);
var dw = v - gamma*w;
return [dv, dw];
}
function draw(){
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawPoints();
var dt = 0.001;
for (i = 0; i < nPoints; i++){
var p = points[i];
var du = fhn([p.v, p.w]);
var dv = du[0];
var dw = du[1];
p.v += dv*dt;
p.w += dw*dt;
}
}
setInterval(draw, 10);
document.addEventListener("click", clickHandler, false);
function clickHandler(e) {
var relativeX = e.clientX - canvas.offsetLeft;
var relativeY = e.clientY - canvas.offsetTop;
var v = vmin + relativeX / canvas.width * (vmax - vmin);
var w = wmin + (canvas.height - relativeY)/canvas.height*(wmax -
wmin);
points[nPoints] = { v: v, w: w};
nPoints++;
}
</script>
</body>