-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (75 loc) · 2.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
<html>
<head>
<title>Mandelbrot</title>
<script src="gl-matrix.js"></script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 unitSquareVertex;
uniform mat4 projection;
varying vec2 coordinates;
uniform float time;
void main(void) {
gl_Position = projection * vec4(unitSquareVertex, 1.0);
float zoom = 2.0;
// (
// (sin(time)/2.0+0.5)
// * 2.0
// + 0.015
// );
float panX = 0.3;
coordinates = vec2(
(unitSquareVertex.x-panX)*zoom+panX,
(unitSquareVertex.y)*zoom
);
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
uniform float time;
varying vec2 coordinates;
void main(void) {
float numIterations = 0.0;
const float maxIterations = 40.0;
// A complex number z = (0 + 0i)
float zReal = 0.0;
float zImag = 0.0;
// A complex number c = (cReal + cImag * i)
float cReal = coordinates.x;
float cImag = coordinates.y;
float zNextReal = 0.0;
float zNextImag = 0.0;
float dist2 = 0.0;
for(float i = 0.0; i < maxIterations; i++)
{
// z^2 + c
zNextReal = zReal * zReal - zImag * zImag + cReal;
zNextImag = 2.0 * zReal * zImag + cImag;
dist2 = zNextReal * zNextReal + zNextImag * zNextImag;
zReal = zNextReal;
zImag = zNextImag;
numIterations++;
if(dist2 > 4.0){
break;
}
}
if(numIterations < maxIterations){
float red = (
sin(numIterations/5.0 + time)
- 1.0
+ 0.1
) / 0.1;
float green = sin(numIterations/10.0 + time/2.0);
float blue = sin(numIterations/10.0 - time/3.0);
gl_FragColor = vec4(red, green, blue, 1.0);
}
else{
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
}
</script>
<script src="requestAnimFrame.js"></script>
<script src="app.js"> </script>
</head>
<body onload="webGLStart();" style="margin:0">
<canvas id="canvas" style="border: none;" width="500" height="500"></canvas>
</body>
</html>