lygia
/sdf
/gearSDF
)Returns a gear shaped SDF Some notes about the parameters: * b determines the length and roundness of the spokes * n is the number of spokes
Dependencies:
Use:
gearSDF(<vec2> st, <vec2> center, <float> b, <int> n_spokes);
gearSDF(<vec2> st, <float> b, <int> n_spokes);
#ifndef FNC_GEARSDF
#define FNC_GEARSDF
float gearSDF( vec2 st, float b, int N) {
const float e = 2.71828182845904523536;
#ifdef CENTER_2D
st -= CENTER_2D;
#else
st -= 0.5;
#endif
st *= 3.0;
float s = map(b, 1.0, 15.0, 0.066, 0.5);
float d = length(st) - s;
float omega = b * sin(float(N) * atan(st.y, st.x));
float l = pow(e, 2.0 * omega);
float hyperTan = (l - 1.0) / (l + 1.0);
float r = (1.0/b) * hyperTan;
return (d + min(d, r));
}
#endif
Dependencies:
Use:
gearSDF(<float2> st, <float2> center, <float> b, <int> n_spokes);
gearSDF(<float2> st, <float> b, <int> n_spokes);
#ifndef FNC_GEARSDF
#define FNC_GEARSDF
float gearSDF( float2 st, float b, int N) {
const float e = 2.71828182845904523536;
#ifdef CENTER_2D
st -= CENTER_2D;
#else
st -= 0.5;
#endif
st *= 3.0;
float s = map(b, 1.0, 15.0, 0.066, 0.5);
float d = length(st) - s;
float omega = b * sin(float(N) * atan2(st.y, st.x));
float l = pow(e, 2.0 * omega);
float hyperTan = (l - 1.0) / (l + 1.0);
float r = (1.0/b) * hyperTan;
return (d + min(d, r));
}
#endif
Dependencies:
Use:
gearSDF(<float2> st, <float2> center, <float> b, <int> n_spokes);
gearSDF(<float2> st, <float> b, <int> n_spokes);
#ifndef FNC_GEARSDF
#define FNC_GEARSDF
float gearSDF( float2 st, float b, int N) {
const float e = 2.71828182845904523536;
#ifdef CENTER_2D
st -= CENTER_2D;
#else
st -= 0.5;
#endif
st *= 3.0;
float s = map(b, 1.0, 15.0, 0.066, 0.5);
float d = length(st) - s;
float omega = b * sin(float(N) * atan(st.y, st.x));
float l = pow(e, 2.0 * omega);
float hyperTan = (l - 1.0) / (l + 1.0);
float r = (1.0/b) * hyperTan;
return (d + min(d, r));
}
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository