/
index.html
144 lines (123 loc) · 4.26 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link href="http://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet" />
<title>Web Worker Fractals</title>
<style>
body { text-align: center; background-color:#113; color:#ddd; }
a { color:#ddd; }
canvas { cursor: crosshair; }
hr { margin:2em auto; }
td:first-child { text-align:right; }
td { padding: 0.2em 0.5em; }
select { font-size:150%; }
main {
max-width: 1200px;
margin: auto;
}
</style>
<script type="text/javascript" src="oz.js"></script>
<script type="text/javascript" src="canvas.js"></script>
<script type="text/javascript" src="formula.js"></script>
<script type="text/javascript" src="fractal.js"></script>
<script type="text/javascript" src="evaluator.js"></script>
</head>
<body style="font-family: lato">
<main>
<h1>Web Worker Fractals</h1>
<div id="container"></div>
<hr/>
<p>Click to zoom in; right-click to zoom out. Computation is parallelized via Web Workers (8 threads).</p>
<hr/>
<table>
<tr>
<td>Type:</td>
<td>
<select id="mode" onchange="redraw()">
<option value="1" selected="selected">Mandelbrot set</option>
<option value="0">Julia set</option>
</select>
</td>
<td>
<span id="mode_mandelbrot">Set of complex constants for which the formula below remains bounded (after many iterations; starting from z=0)</span>
<span id="mode_julia">Set of complex numbers for which the formula below remains bounded (with a fixed c)</span>
<br/>
<p id="c">
Re(c): <input id="c_real" onchange="redraw()" type="text" size="5" value="-0.8" /><br/>
Im(c): <input id="c_imag" onchange="redraw()" type="text" size="5" value="0.156" />
</p>
</td>
</tr>
<tr>
<td>Formula:</td>
<td><select id="formula" onchange="redraw()" >
<option selected="selected" value="0">z = z^2 + c</option>
<option value="1">z = z^3 + c</option>
<option value="2">z = z^4 + c</option>
<option value="3">z = conj(z)^2 + c</option>
<option value="4">burning ship</option>
</select>
</td>
<td></td>
</tr>
<tr>
<td><label for="threads">Web Workers:</label></td>
<td><input type="checkbox" id="threads" checked="checked" onchange="redraw()" /></td>
<td></td>
</tr>
</table>
<script type="text/javascript">
const DPR = (window.devicePixelRatio || 1);
var f = null;
if (!window.Worker) {
OZ.$("threads").checked = false;
OZ.$("threads").disabled = true;
}
var options = {};
function redraw() {
var mode = parseInt(OZ.$("mode").value);
options.mode = mode;
options.c = [parseFloat(OZ.$("c_real").value), parseFloat(OZ.$("c_imag").value)];
options.formula = parseInt(OZ.$("formula").value)
OZ.$("mode_julia").style.display = (mode == Formula.JULIA ? "" : "none");
OZ.$("c").style.display = (mode == Formula.JULIA ? "" : "none");
OZ.$("mode_mandelbrot").style.display = (mode == Formula.MANDELBROT ? "" : "none");
options.threads = OZ.$("threads").checked;
let width = document.querySelector("main").offsetWidth;
let height = Math.round(width * .75);
options.width = Math.round(width * DPR);
options.height = Math.round(height * DPR);
f = new Fractal(OZ.$("container"), options);
var canvas = f.getElement();
canvas.style.width = `${width}px`;
canvas.style.height = `${height}px`;
OZ.Event.add(canvas, "contextmenu", OZ.Event.prevent);
OZ.Event.add(canvas, "mouseup", click);
}
function click(e) {
let rect = f.getElement().getBoundingClientRect();
var x = e.clientX - rect.left;
var y = e.clientY - rect.top;
var o = f.getOptions();
x /= o.width;
y /= o.height;
x *= DPR;
y *= DPR;
var dx = o.rangeX[1]-o.rangeX[0];
var dy = o.rangeY[1]-o.rangeY[0];
x = o.rangeX[0] + dx*x;
y = o.rangeY[0] + dy*y;
var multi = (e.button ? 2 : 0.5);
dx *= multi;
dy *= multi;
options.rangeX = [x-dx/2, x+dx/2];
options.rangeY = [y-dy/2, y+dy/2];
redraw();
}
redraw();
</script>
<footer style="margin-top:5em; font-size:80%">Created by <a href="http://ondras.zarovi.cz/">Ondřej Žára</a>, with a lot of hints and optimizations by <a href="http://balazs.kutilovi.cz/">Balázs Kutil</a></footer>
</div>
</body>
</html>