Revision: 06.08.2023, https://compute.toys/view/398
fn sdCircle(p: vec2f, r: f32) -> f32 {
return length(p) - r;
}
Revision: 06.08.2023, https://compute.toys/view/398
fn sdCircle(p: vec2f, r: f32) -> f32 {
return length(p) - r;
}
The helper function canvas-to-svg.js
wraps a given render function (or renderer object) so that you can use Canvas2D context methods as usual, but upon single frame export (with Cmd/Ctrl + S) it will produce both a PNG and SVG file.
This uses canvas2svg which is not a perfect solution, as the Canvas2D API was never designed to be translated to SVG. Its best to stick with simple shape and path operations.
Full instructions: first install the canvas-sketch CLI if you haven't already:
npm install canvas-sketch-cli -g
// | |
// MARK: CGPoint op point/size/float | |
// | |
func -(l: CGPoint, r: CGPoint) -> CGPoint { return CGPoint(x: l.x - r.x, y: l.y - r.y) } | |
func +(l: CGPoint, r: CGPoint) -> CGPoint { return CGPoint(x: l.x + r.x, y: l.y + r.y) } | |
func *(l: CGPoint, r: CGPoint) -> CGPoint { return CGPoint(x: l.x * r.x, y: l.y * r.y) } | |
func /(l: CGPoint, r: CGPoint) -> CGPoint { return CGPoint(x: l.x / r.x, y: l.y / r.y) } | |
func -(l: CGPoint, r: CGSize) -> CGPoint { return CGPoint(x: l.x - r.width, y: l.y - r.height) } |
Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative
float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);