Classic fractals

  • 4 Replies
  • 424 Views

0 Members and 1 Guest are viewing this topic.

Offline utak3r

  • *
  • Fractal Phenom
  • ****
  • Posts: 58
« on: February 22, 2018, 08:00:52 PM »
Ok, let's start sharing some code here  8)

I'll start from the classic Julia. It's coloured with orbit traps. There're quite a number of controls inside for the colouring. See also some sample images from this.

Code: [Select]
/*!
 * <info>
 * Julia set exploration.
 * 2018 utak3r
 *
 * Note:
 * It does contain few variations and also few colouring algorithms.
 * This makes the shader working much slower than it should.
 * For best results, any unused code combinations should be commented out,
 * leaving only what you need now.
 *
 * Complex functions are by Indigo Quilez, of course.
 * </info>
 */

#define GAMMA_CORRECTION
#include <Fragmentarium/2D.frag>

uniform float iGlobalTime;

//! <group name="Julia"/>
uniform float Cr; //! slider[-2., .28, 2.]
uniform float Ci; //! slider[-2., .008, 2.]
uniform float Bailout; //! slider[1, 4, 16]
// variations
uniform int variation; //! combobox[0,square,third,sqrsinhsqrt,expthird,power]
uniform float power; //! slider[-16, 2, 16]
uniform bool animate; //! checkbox[false]
uniform int maxIter; //! slider[16, 1024, 4096]
// colouring styles
uniform int colouring; //! combobox[0,smooth,orbit,orbit2,orbit3]
uniform float orbitColouring; //! slider[-2, .5, 2]
uniform float intensity; //! slider[1, 2.5, 5]
uniform float smoothshift; //! slider[0, 0.2, 1]
uniform vec3 color1; //! color[0.992, 0.929, 0.675]
uniform float coeff11; //! slider[0, .2, 1]
uniform float coeff12; //! slider[0, .25, 1]
uniform vec3 color2; //! color[0.835, 0.8, 0.667]
uniform float coeff21; //! slider[0, .5, 1]
uniform float coeff22; //! slider[0, .5, 1]
uniform vec3 color3; //! color[1.00, 1.00, 1.00]
uniform float coeff31; //! slider[0, .15, 1]
uniform float coeff32; //! slider[0, 1, 1]

vec2 cMul(vec2 a, vec2 b)
{
return vec2(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x);
}

vec2 cPow(vec2 z, float n)
{
float r = length(z);
float a = atan(z.y, z.x);
return pow(r, n) * vec2(cos(a*n), sin(a*n));
}

vec2 cSqr(vec2 z)
{
return vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y);
}

vec2 cSqrt(vec2 z)
{
float m = length(z);
return sqrt(max(vec2(0.0), 0.5*vec2(m+z.x, m-z.x))) * vec2(1.0, sign(z.y));
}

vec2 cExp(vec2 z)
{
return exp(z.x) * vec2(cos(z.y), sin(z.y));
}

vec2 cSinh(vec2 z)
{
  return 0.5 * (cExp(z) - cExp(-z));
}

vec3 julia(vec2 fragCoord)
{
float time = iGlobalTime * 0.5;
float PIH = 1.570797;

vec2 z = fragCoord;
vec2 c = vec2(Cr, Ci);
if (animate)
c = 1.1*vec2( 0.5*cos(0.1*time) - 0.25*cos(0.2*time),
0.5*sin(0.1*time) - 0.25*sin(0.2*time));

vec4 orbit_dmin = vec4(1e20f);
float smoothcolor = 0.0;
vec2 dz = vec2(0.0);

for (int i = 0; i < maxIter; i++)
{
if ((colouring == 0) && (dot(z,z) > Bailout))
break;

// variations
if (variation == 0)
z = cSqr(z) + c;
if (variation == 1)
z = cPow(z, 3) + c;
if (variation == 2)
z = cSqrt(cSinh(cSqr(z))) + c;
if (variation == 3)
z = cExp(cMul(z, cSqr(z))) + c;
if (variation == 4)
z = cPow(z, power) + c;

// smooth colouring
if (colouring == 0)
smoothcolor += exp(-length(z));
// orbit colouring
if (colouring == 1)
orbit_dmin = min(orbit_dmin, vec4(
abs(0.0+z.y + 0.5*sin(z.x)),
abs(1.0+z.x + 0.5*sin(z.y)),
dot(z,z),
length(fract(z)-orbitColouring)));
if (colouring == 2)
orbit_dmin = min(orbit_dmin, vec4(
sqrt(z.x*z.y),
sqrt(z.y*z.y),
dot(z,z),
length(fract(z)-orbitColouring)));
if (colouring == 3)
orbit_dmin = min(orbit_dmin, vec4(
abs(z.y + orbitColouring*sin(z.x)),
0.5*sqrt(z.y*z.y),
0.5*(z.x*z.x + z.y*z.y),
exp(-length(z-fract(z)))));
}

vec3 color = vec3(0);
if (colouring == 0)
{
color.r = color1.r*0.6 + 0.4 * sin(smoothcolor*smoothshift);
color.g = color1.g*0.6 + 0.4 * sin(smoothcolor*smoothshift);
color.b = color1.b*0.6 + 0.4 * sin(smoothcolor*smoothshift);
color = intensity*color*color*color;
}
if ((colouring == 1) || (colouring == 2) || (colouring == 3))
{
color = vec3(orbit_dmin.w);
color = mix(color, color1, min(1.0,pow(orbit_dmin.x*coeff12, coeff11)));
color = mix(color, color2, min(1.0,pow(orbit_dmin.y*coeff22, coeff21)));
color = mix(color, color3, 1.0-min(1.0,pow(orbit_dmin.z*coeff32, coeff31)));
color = intensity*color*color*color;
}
return color;
}

vec3 color(vec2 fragCoord)
{
return julia(fragCoord);
}

//! <preset file="Julia.preset" />

and a default preset:

Code: [Select]
/*!
 * <preset name="Default" stepSize="0.1">
 *  AntiAlias = <1|1|15> 2
 *  AntiAliasScale = <0.1|0.0|2.0> 1.0
 *  Bailout = <0.75|1.0|16.0> 4.0
 *  Center = <1.0, 1.0|-1000.0, -1000.0|1000.0, 1000.0> 0.0, 0.0
 *  Ci = <0.01|-2.0|2.0> 0.2
 *  Cr = <0.01|-2.0|2.0> -0.8
 *  Zoom = <1.0|0.0|100.0> 0.9999999
 *  animate = false
 *  coeff11 = <0.05|0.0|1.0> 0.333333
 *  coeff12 = <0.05|0.0|1.0> 0.083333
 *  coeff21 = <0.05|0.0|1.0> 0.805556
 *  coeff22 = <0.05|0.0|1.0> 0.0
 *  coeff31 = <0.05|0.0|1.0> 0.194444
 *  coeff32 = <0.05|0.0|1.0> 1.0
 *  color1 = <0.004, 0.004, 0.004> 0.72156864, 0.69803923, 1.0
 *  color2 = <0.004, 0.004, 0.004> 0.52156866, 0.6627451, 1.0
 *  color3 = <0.004, 0.004, 0.004> 1.0, 0.91764706, 0.93333334
 *  colouring = 3
 *  intensity = <0.2|1.0|5.0> 3.5
 *  maxIter = <1|16|4096> 1024
 *  orbitColouring = <0.01|-2.0|2.0> 0.0
 *  power = <0.8|-16.0|16.0> -2.0
 *  smoothshift = <0.05|0.0|1.0> 0.2
 *  variation = 0
 * </preset>
 */


Linkback: https://fractalforums.org/synthclipse/60/classic-fractals/910/
« Last Edit: March 06, 2018, 11:13:14 PM by utak3r »

Offline 3DickUlus

  • *
  • 3f
  • ******
  • Posts: 1460
    • Digilantism
« Reply #1 on: February 23, 2018, 04:51:33 AM »
that looks really good! I liked it the first time around and now seeing it again it seems even better.  :thumbs:
Fragmentarium is not a toy, it is a very versatile tool that can be used to make toys ;)

https://en.wikibooks.org/wiki/Fractals/fragmentarium

Offline utak3r

  • *
  • Fractal Phenom
  • ****
  • Posts: 58
« Reply #2 on: February 23, 2018, 11:27:57 AM »
Yesterday I was working with some 3D code for Synthclipse and I've noticed I was incorrectly using above 2D mode  :embarrass: I will fix the code later, this will make navigating the fractal much more easy.
And I discovered this while developing 3D fly  ;D  it was one of those "aaaahhhhh!!!" moments  :))

Edit:
I've fixed the code. Stupid me  :embarrass:
« Last Edit: February 23, 2018, 04:37:32 PM by utak3r »

Offline utak3r

  • *
  • Fractal Phenom
  • ****
  • Posts: 58
« Reply #3 on: March 01, 2018, 11:31:32 PM »
Ok, after @Matplotlib asked for one of the Julia variations, I modified this script to have few variations (4 of them, as of today) and 2 colouring schemas: orbit traps and smooth.
« Last Edit: March 06, 2018, 11:13:42 PM by utak3r »

Offline utak3r

  • *
  • Fractal Phenom
  • ****
  • Posts: 58
« Reply #4 on: March 06, 2018, 11:15:34 PM »
Updated the code in the first post. Few colourings and few variations.
Last two days I was playing mainly with z-2+c - if coloured with any of the orbit traps mechanism, can give nice results.


clip
Classic 3D constructions and fractals

Started by utak3r on Synthclipse

2 Replies
286 Views
Last post May 07, 2018, 05:11:37 PM
by revers
clip
Classic

Started by 3DickUlus on Fractal Image Gallery

0 Replies
189 Views
Last post February 24, 2018, 08:30:30 AM
by 3DickUlus
xx
Classic Julia Set with KF ?

Started by CFJH on Kalles Fraktaler

1 Replies
250 Views
Last post March 24, 2019, 03:36:37 PM
by claude
xx
Classic Sierpinski with a twist!

Started by fractal aesthetics on Fractal Image Gallery

1 Replies
148 Views
Last post June 17, 2018, 12:49:33 PM
by Caleidoscope
xx
Classic Mandelbrot - slow zoom

Started by svempa on Fractal movie gallery

2 Replies
142 Views
Last post February 17, 2019, 04:45:30 AM
by claude