Last active
June 30, 2023 03:07
-
-
Save ProfLander/aa4b5d19094488603acfcae2373a30fa to your computer and use it in GitHub Desktop.
Haskell diagrams but in Rust, using Signed Distance Fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ( | |
| 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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ( | |
| 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>>>, | |
| ), | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>>>,)>, | |
| ), | |
| ), | |
| ), | |
| ) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
Distance Channel
(Lines only, as overlaying produces a solid shape)
Normal Channel

Color Channel
