Skip to content

Instantly share code, notes, and snippets.

@Shfty
Last active June 30, 2023 03:07
Show Gist options
  • Save Shfty/aa4b5d19094488603acfcae2373a30fa to your computer and use it in GitHub Desktop.
Save Shfty/aa4b5d19094488603acfcae2373a30fa to your computer and use it in GitHub Desktop.
Haskell diagrams but in Rust, using Signed Distance Fields
(
Infinity.color(TRANSPARENT),
circle().color(CYAN),
triangle().color(YELLOW),
(
range::<U1, U5, f32>()
.fmap(Div(10.0_f32))
.fmap(MakeRing.suffix2(inner_line))
.fold_combine(union()),
triangle().isomanifold(mid_line),
ring().width(outer_line),
)
.fold_combine(union())
.color(BLACK),
)
.fold_combine((
smooth_overlay().k(frag_recip),
polynomial_smooth_overlay::<Gradient<Vec2>>(frag_recip),
polynomial_smooth_overlay::<Color<Vec4>>(frag_recip),
))
.scale(0.9_f32)
.into_tuple()
.rasterize::<ShapeCtxFrom>(frag_size as usize, frag_size as usize)
.to_image::<ShapeCtxTo>(ColorToRgba)
.mappend((ImageWriter(
"image.png".into(),
PhantomData::<ImageBuffer<Rgba<f32>, Vec<f32>>>,
),))
.evaluate::<DistGrad<f32, Vec2>>(RasterCtx::default());
(
Rasterizer {
width: 128,
height: 128,
shape: (
Scaler(
0.9,
(
Combine(
(
Combine(
(
Combine(
(
Infinity,
SetS(
Color(
Vec4(
0.0,
0.0,
0.0,
0.0,
),
),
),
),
(
Circle(
1.0,
),
SetS(
Color(
Vec4(
0.0,
1.0,
1.0,
1.0,
),
),
),
),
(
SmoothOverlay(
0.0078125,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
),
),
),
(
Triangle(
1.0,
),
SetS(
Color(
Vec4(
1.0,
1.0,
0.0,
1.0,
),
),
),
),
(
SmoothOverlay(
0.0078125,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
),
),
),
(
Combine(
(
Combine(
(
Combine(
(
Combine(
(
Combine(
(
Combine(
(
Ring(
0.1,
0.01171875,
),
),
(
Ring(
0.2,
0.01171875,
),
),
(
Union,
),
),
),
(
Ring(
0.3,
0.01171875,
),
),
(
Union,
),
),
),
(
Ring(
0.4,
0.01171875,
),
),
(
Union,
),
),
),
(
Ring(
0.5,
0.01171875,
),
),
(
Union,
),
),
),
(
Triangle(
1.0,
),
IsomanifoldS(
0.015625,
),
),
(
Union,
),
),
),
(
Ring(
1.0,
0.01953125,
),
),
(
Union,
),
),
SetS(
Color(
Vec4(
0.0,
0.0,
0.0,
1.0,
),
),
),
),
(
SmoothOverlay(
0.0078125,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
),
),
),
),
),
context: PhantomData<elysian::context::pos_dist_grad_color::PosDistGradColor<elysian::domain::position::Position<glam::f32::vec2::Vec2>, (), (), elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>>,
},
RasterToImage(
ColorToRgba,
PhantomData<elysian::context::pos_dist_grad_color::PosDistGradColor<(), elysian::domain::distance::Distance<f32>, elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>, elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>>,
),
ImageWriter(
"image.png",
PhantomData<image::buffer_::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>,
),
)
Composed(
Composed(
Composed(
Id,
Composed(
CallF,
Fanouted(
Composed(
Curried2(
Flipped(
InsertF,
),
),
Composed(
ImageWriter(
"image.png",
PhantomData<image::buffer_::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>>,
),
GetF(
PhantomData<(image::buffer_::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>,)>,
),
),
),
DropF(
PhantomData<(image::buffer_::ImageBuffer<image::color::Rgba<f32>, alloc::vec::Vec<f32>>,)>,
),
),
),
),
Composed(
CallF,
Fanouted(
Composed(
Curried2(
Flipped(
InsertF,
),
),
Composed(
Image(
ColorToRgba,
PhantomData<elysian::context::pos_dist_grad_color::PosDistGradColor<(), elysian::domain::distance::Distance<f32>, elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>, elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>>,
),
GetF(
PhantomData<(elysian::symbol::modify::standard::rasterizer::raster::Raster<elysian::context::pos_dist_grad_color::PosDistGradColor<(), elysian::domain::distance::Distance<f32>, elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>, elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>>,)>,
),
),
),
DropF(
PhantomData<(elysian::symbol::modify::standard::rasterizer::raster::Raster<elysian::context::pos_dist_grad_color::PosDistGradColor<(), elysian::domain::distance::Distance<f32>, elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>, elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>>,)>,
),
),
),
),
Composed(
CallF,
Fanouted(
Composed(
Curried2(
Flipped(
InsertF,
),
),
Composed(
RasterizeF {
width: 128,
height: 128,
shape: (
Scaler(
0.9,
(
Combine(
(
Combine(
(
Combine(
(
Infinity,
SetS(
Color(
Vec4(
0.0,
0.0,
0.0,
0.0,
),
),
),
),
(
Circle(
1.0,
),
SetS(
Color(
Vec4(
0.0,
1.0,
1.0,
1.0,
),
),
),
),
(
SmoothOverlay(
0.0078125,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
),
),
),
(
Triangle(
1.0,
),
SetS(
Color(
Vec4(
1.0,
1.0,
0.0,
1.0,
),
),
),
),
(
SmoothOverlay(
0.0078125,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
),
),
),
(
Combine(
(
Combine(
(
Combine(
(
Combine(
(
Combine(
(
Combine(
(
Ring(
0.1,
0.01171875,
),
),
(
Ring(
0.2,
0.01171875,
),
),
(
Union,
),
),
),
(
Ring(
0.3,
0.01171875,
),
),
(
Union,
),
),
),
(
Ring(
0.4,
0.01171875,
),
),
(
Union,
),
),
),
(
Ring(
0.5,
0.01171875,
),
),
(
Union,
),
),
),
(
Triangle(
1.0,
),
IsomanifoldS(
0.015625,
),
),
(
Union,
),
),
),
(
Ring(
1.0,
0.01953125,
),
),
(
Union,
),
),
SetS(
Color(
Vec4(
0.0,
0.0,
0.0,
1.0,
),
),
),
),
(
SmoothOverlay(
0.0078125,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
PhantomData<elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>>,
),
BlendPropertyDist(
PolynomialSmoothOverlay(
0.0078125,
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
PhantomData<elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>,
),
),
),
),
),
),
domain: PhantomData<(elysian::domain::distance::Distance<f32>, (elysian::domain::gradient::Gradient<glam::f32::vec2::Vec2>, ()))>,
},
GetF(
PhantomData<(elysian::context::context_raster::Context<elysian::context::pos_dist_grad_color::PosDistGradColor<elysian::domain::position::Position<glam::f32::vec2::Vec2>, (), (), elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>>,)>,
),
),
),
DropF(
PhantomData<(elysian::context::context_raster::Context<elysian::context::pos_dist_grad_color::PosDistGradColor<elysian::domain::position::Position<glam::f32::vec2::Vec2>, (), (), elysian::domain::color::Color<glam::f32::sse2::vec4::Vec4>>>,)>,
),
),
),
)
@Shfty
Copy link
Author

Shfty commented Jun 30, 2023

Result:

Distance Channel
(Lines only, as overlaying produces a solid shape)

distance

Normal Channel
normal

Color Channel
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment