-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfractal.html
59 lines (51 loc) · 1.52 KB
/
fractal.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
<body style=background-color:#000;overflow:hidden;margin:0>
<canvas id=a style=display:block;width:100%;height:100%></canvas>
<script id=fragmentShader type=x-shader/x-fragment>
precision mediump float;
#define ITERS 18
uniform float time;
uniform vec2 resolution;
vec3 lighten(vec3 c, float d) {
return vec3(min(1.0, c.r + d), min(1.0, c.g + d), min(1.0, c.b + d));
}
vec3 pastel(vec3 c) {
float avg = (c.r+c.g+c.b)/3.0;
return lighten(c, avg);
}
vec2 R(vec2 p,float a) {
return vec2( p.x*cos(a) + p.y*sin(a),
-p.x*sin(a) + p.y*cos(a));
}
float julia(vec2 c,vec2 c1, float max){
float xx = c.x * c.x;
float yy = c.y * c.y;
float xy = c.x * c.y;
float s = xx + yy;
for (int i = ITERS;i>0;i--){
c=vec2(xx - yy, xy + xy) + c1;
xx = c.x * c.x;
yy = c.y * c.y;
xy = c.x * c.y;
s = xx + yy;
if(s>=max || i == 1)return float(ITERS - i)/float(ITERS);
}
return 0.0;
}
void main() {
vec2 c0 = (gl_FragCoord.xy / resolution) - vec2(0.5,0.5);
vec2 c = R(c0, time) + vec2(cos(time*2.0)*0.4,sin(time)*0.6);
float j = julia(c,c, 16.0);
float r = j * sin(time + c0.y*2000.0*sin(time))*cos((c.x+c.y)*time*2.0)*sin(c0.y*sin(time)*3.0);
float g = j * cos(time + c0.y*3000.0*cos(time))*sin(c.x*time*6.0+cos(c.x+c.y)*time*333.0);
float b = (r + g + sin(time*6.0)*c0.y)/2.0;
gl_FragColor = vec4(pastel(vec3(r, g, b)), 1.0);
}
</script>
<script id=vertexShader type=x-shader/x-vertex>
attribute vec3 pos;
void main() {
gl_Position=vec4(pos, 1.0);
}
</script>
<script src=minigl.js></script>
<script src=fractal.js></script>