Geometric Art Brush

To talk about brush creation and controllers
mrange
 
Posts: 7
Joined: 06 Mar 2020, 22:22
Location: Oslo

Geometric Art Brush

Postby mrange » 07 Mar 2020, 11:52

Was messing around brushes to generate geometric art. Thought it was good enough to share:

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

cfg{
name="Geo Art";
renderingTime = 20 ;
}

perPrim {
float size = 400.0;
{
id = 2 ;
uiMin = 0.0 ;
uiTab = "shape" ;
uiFormat = pixel ;
uiName = "size" ;
}
float offc = 1.0;
{
id = 3 ;
uiMin = 0.0 ;
uiMax = 2.0 ;
uiTab = "shape" ;
uiFormat = percent ;
uiName = "offset from center" ;
}
float off = 0.15;
{
id = 3 ;
uiMin = 0.0 ;
uiMax = 1.0 ;
uiTab = "shape" ;
uiFormat = percent ;
uiName = "height offset" ;
}
float width = 1.0;
{
id = 4 ;
uiMin = 0.0 ;
uiMax = 100.0 ;
uiTab = "shape" ;
uiFormat = pixel ;
uiName = "stroke width" ;
}
float reps = 11;
{
id = 5 ;
uiMin = 0 ;
uiMax = 20 ;
uiTab = "shape" ;
uiFormat = integer ;
uiName = "repetitions" ;
}
float fuzzy = 1.0;
{
id = 6 ;
uiMin = -100.0 ;
uiMax = 100.0 ;
uiTab = "shape" ;
uiFormat = pixel ;
uiName = "fuzziness" ;
}
}

float dodec(idatas i, float3 z) {
float phi = 0.5*(1.+sqrt(5.0));
float3 plnormal = normalize(float3(1, 1, -1));
float3 n1 = normalize(float3(-phi,phi-1.0,1.0));
float3 n2 = normalize(float3(1.0,-phi,phi+1.0));
float3 n3 = normalize(float3(0.0,0.0,-1.0));

float t;
z = abs(z);
t=dot(z,n1); if (t>0.0) { z-=2.0*t*n1; }
t=dot(z,n2); if (t>0.0) { z-=2.0*t*n2; }
z = abs(z);
t=dot(z,n1); if (t>0.0) { z-=2.0*t*n1; }
t=dot(z,n2); if (t>0.0) { z-=2.0*t*n2; }
z = abs(z);

float dmin=dot(z-float3(i.size,0.,0.),plnormal);

dmin = abs(dmin) - i.width;
// dmin = abs(dmin) - i.width*0.5;

return dmin;
}

void rot(inout float2 p, float a) {
float c = cos(a);
float s = sin(a);
p = float2(c*p.x + s*p.y, -s*p.x + c*p.y);
}

float df_(idatas i, float2 p) {
return length(p) - 100.0;
}

float df(idatas i, float2 p) {
float pi = 3.141592654;
float tau = 2.0*pi;

float d = 100000.0;
int rep = min(20, floor(i.reps));
float ratio = tau/float(rep);
for (int j = 0; j < rep; ++j) {
float2 ip = p;
rot(ip, j*ratio);
ip -= float2(i.offc*i.size, 0.0);
float id = dodec(i, float3(ip, i.off*i.size));
d = min(d, id);
}
return d;
}

float4 main(idatas i)
{
float2 p = i.pos - i.strokePos;
float4 f = i.color;
float4 b = float4(0.0, 0.0, 0.0, 0.0);

float d = df(i, p);

float4 col = lerp(f, b, smoothstep(-i.fuzzy, i.fuzzy, d));

return col;
}
')
--
mrange

User avatar
u2bleank
 
Posts: 1186
Joined: 11 Jun 2012, 10:41

Re: Geometric Art Brush

Postby u2bleank » 22 Mar 2020, 12:21

This one produce something ( excellent ).
My advise for the futur is to take into account the unit size of the Shape. Then the result will ne be dependent of the current zoom when drawing..

Image


Return to Brush Making

cron