Hanging out with the Solarpunk Magic Computer Club, listening to solquemal teach us about fractals and shaders.

GLSL
vec3 cosPalette(float t){
    vec3 a = vec3(0.5,0.5,0.25);
    vec3 b = vec3(0.3,0.4,0.4);
    vec3 c = vec3(2.,1.,3.);
    vec3 d = vec3(0.,0.3,0.6);
    
    return a + b*cos( 6.28318*(c*t+d));
}
const int iterations = 120;

float mandelbrot(vec2 c) {
        vec2 z = vec2(0.);
        vec2 dz = vec2(0.); 

        float m2 = 0.;
        float dis = pow(10.,float(iterations));
    
        for( int i=0; i< iterations; i++ )
        {
            if( m2 >dis) {  break; }

            dz = 2.0*vec2(z.x*dz.x-z.y*dz.y, z.x*dz.y + z.y*dz.x) + vec2(1.);
            z = vec2( z.x*z.x - z.y*z.y, 2.0*z.x*z.y ) + c;
            m2 = dot(z,z);  
        }
        return sqrt( m2/dot(dz,dz) )*log(m2)*0.1;
    }


void main(){
    vec2 pos = uv() *1.5;
    pos -=0.025;
    vec3 color;
    
    vec2 z = pos;

   float v = 0.;//sin(time*.2)*0.2;
   vec2 c = vec2(-0.79 +v ,0.19);
   float an = atan(pos.x,pos.y);
   
  //JULIA SET 
    float t = 0.;
    for( int i = 0 ;  i < 100; i ++){
        c.x -= 0.012;
        vec2 nz = vec2(z.x*z.x - z.y*z.y, 2. * z.x *z.y ) + c;
        float m = dot(nz,nz);
        
        if (m>300.0) break;
        z = nz;
        
      t += 1./100.;
    } 
    
// t -= mandelbrot(pos);
   
    color += cosPalette(t);

    gl_FragColor = vec4(color,1.);
}

Posted

in