x
56
1
2
3
4
5
6
// whether we would like a Julia set (true) or Mendelbrot set (false)
7
8
9
// the degree of the exponent of the set (2.0 is the typical Mandelbrot)
10
// multi-brot or multi-Julia can be achieved with d > 2
11
// -1.5 and 1.5 present some really awesome effects (with Julia set to true)
12
13
14
vec3 gradient(in float r) {
15
r = 4.0 * tanh(0.1 * r);
16
vec3 col = 0.5 - 0.5 * cos(r + vec3(0.087, 1.147, 3.991));
17
return col;
18
}
19
20
vec4 fractal(vec2 z, vec2 c) {
21
if (!JULIA){
22
// original point
23
c = z;
24
}
25
// Computes colouring at point z of the Julia set with parameter c.
26
for (int i = 0; i < ITER; ++i) {
27
z = vec2(
28
pow(z.x*z.x+z.y*z.y, DEGREE/2.0)*cos(DEGREE*atan(z.y,z.x)) + c.x,
29
pow(z.x*z.x+z.y*z.y, DEGREE/2.0)*sin(DEGREE*atan(z.y,z.x)) + c.y
30
);
31
float distSqr = dot(z, z);
32
if (distSqr > 16.0) {
33
return vec4(gradient(float(i) + 1.0 - log2(log(distSqr) / 2.0)), 1.);
34
}
35
}
36
// black
37
return vec4(0.0, 0.0, 0.0, 1.0);
38
}
39
40
vec2 cardioid(in float t) {
41
// Computes the path around the main cardioid of the Mandelbrot set.
42
t = TWOPI * iTime / iDuration;
43
vec2 c = vec2(-cos(t), -sin(t));
44
c *= (1. + cos(t)) / 2.;
45
c.x += 0.2499;
46
return c;
47
}
48
49
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
50
vec2 uv = fragCoord / iResolution.xy;
51
// scale * (uv - offset)
52
float scale = JULIA ? 3.5 : 4.0;
53
uv = scale * (uv - 0.5);
54
vec2 c = cardioid(iTime);
55
fragColor = fractal(uv, c);
56
}
1264×1264px
0