Making Fractal brushes

To talk about brush creation and controllers
texez
 
Posts: 3
Joined: 20 Dec 2013, 02:11

Making Fractal brushes

Postby texez » 10 Mar 2020, 23:42

Is this even possible? :desire:

mrange
 
Posts: 7
Joined: 06 Mar 2020, 22:22
Location: Oslo

Re: Making Fractal brushes

Postby mrange » 11 Mar 2020, 20:35

Hi.

Yes, this is possible in the brush language. A simple example would be a mandelbrot fractal brush. I replace voronoi brush shader code with this and click and drag to render a mandelbrot fractal

$this->bbcode_second_pass_code('', '
// License: CC BY-SA 4.0
// Same license as Stackoverflow uses for code and content

cfg{
name="Mandelbrot fractal";
renderingTime = 30 ;
}

float3 mandelbrot(in float2 p) {
float zoo = 1.0;
float2 xy = float2(p.x, p.y);
float2 c = float2(-0.5, 0.0) + xy*zoo;

float B = 10.0;
float C = 256;
int l = 0;
float2 z = float2(0.0, 0.0);
for(int i = 0; i < C; ++i) {
float re2 = z.x*z.x;
float im2 = z.y*z.y;
float reim= z.x*z.y;

if(re2 + im2 > (B*B)) break;

z = float2(re2 - im2, 2.0*reim) + c;

++l;
}

if (l >= C) return float3(0.0, 0.0, 0.0);

float sl = l - pow(dot(z,z), 0.15) + 4.0;
float3 gc = 0.5 + 0.5*cos(3.0 + sl*0.15 + float3(0.1,0.5,0.9));

return gc;
}


float4 main(idatas i) {
box2 b = box2FromCenterAxe( i.strokeStartPos, max( length(i.strokePos-i.strokeStartPos), 2 ), normalizeSafe(i.strokePos-i.strokeStartPos) );
float2 p = 4*b.toCenter(i.pos) / b.size ;
float3 col = mandelbrot(0.25*p);

return float4(col, 1.0);
}
')
--
mrange


Return to Brush Making