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
<!DOCTYPE html>
<html>
<head>
<title>Julia Fractals</title>
</head>
<style>
body {
background: black;
color: white;
}
canvas {
border: 1px solid white;
}
</style>
<body>
<h2></h2>
<canvas></canvas>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.6.0/math.min.js"></script>
<script>
var header = document.querySelector('h2')
var canvas = document.querySelector('canvas')
var ctx = canvas.getContext('2d')
var width = 200
var height = 200
canvas.width = width
canvas.height = height
var mouseX = 0
var mouseY = 0
var constant = math.complex(0.28, 0.01)
function pixelToPoint(x, y) {
var zx = (x/width)*2-1
var zy = 1-(y/height)*2
return math.complex(zx, zy)
}
function update() {
header.innerHTML = constant.toString()
}
function move(event) {
mouseX = event.clientX-canvas.offsetLeft
mouseY = event.clientY-canvas.offsetTop
constant = pixelToPoint(mouseX, mouseY)
constant.re = math.round(constant.re*100)/100
constant.im = math.round(constant.im*100)/100
update()
}
canvas.addEventListener('pointermove', move)
</script>
</html>