Skip to content

Instantly share code, notes, and snippets.

@Ninja-Koala
Ninja-Koala / bezier-circle.sage
Created August 16, 2022 23:31
Compute quadratic bezier approximation to a circle
var('a t')
# number of curves we want to approximate the circle with
for n_curves in range(3,11):
# startpoint of quadratic bezier curve
x0=cos(0)
y0=sin(0)
# control point of quadratic bezier curve
@Ninja-Koala
Ninja-Koala / svg-to-shadertoy.py
Last active May 6, 2024 14:53
Convert a svg path to a shadertoy shader
#!/usr/bin/python3
import os
import sys
import numpy as np
def read_value(string, index):
#go to the beginning of the value
while svg_content[index] not in numerals:
index+=1
#read in the value
@Ninja-Koala
Ninja-Koala / implicit_curve.frm
Last active August 29, 2019 17:03
Compute implicit cartesian equation for curves given by a parametric equation including trigonometric functions (sage script and form script for output optimization)
#-
Symbol x,y,u;
Format float;
*Example curve, just paste the output of the sage script in here
Local F=x^24 - 13*x^22*y^2 - 9*x^20*y^4 + 285*x^18*y^6 + 970*x^16*y^8 + 1246*x^14*y^10 + 462*x^12*y^12 - 454*x^10*y^14 - 475*x^8*y^16 - 65*x^6*y^18 + 75*x^4*y^20 + 25*x^2*y^22 - 42*x^22 - 637*x^20*y^2 - 2660*x^18*y^4 - 6125*x^16*y^6 - 11340*x^14*y^8 - 18746*x^12*y^10 - 23296*x^10*y^12 - 18690*x^8*y^14 - 8890*x^6*y^16 - 2345*x^4*y^18 - 364*x^2*y^20 - 49*y^22 + 511*x^20 + 4585*x^18*y^2 + 22470*x^16*y^4 + 64260*x^14*y^6 + 111930*x^12*y^8 + 126126*x^10*y^10 + 98280*x^8*y^12 + 55860*x^6*y^14 + 22575*x^4*y^16 + 5425*x^2*y^18 + 490*y^20 - 1484*x^18 - 14231*x^16*y^2 - 53424*x^14*y^4 - 119756*x^12*y^6 - 184184*x^10*y^8 - 194194*x^8*y^10 - 132496*x^6*y^12 - 54684*x^4*y^14 - 12796*x^2*y^16 - 1519*y^18 + 1519*x^16 + 11277*x^14*y^2 + 43407*x^12*y^4 + 89089*x^10*y^6 + 105105*x^8*y^8 + 79079*x^6*y^10 + 40677*x^4*y^12 + 12747*x^2*y^14 + 1484*y^16 - 490*x^14 - 3955*x^12*y^2 - 9240*x^10*y^4 - 15785*x^8*y^6 - 19250*x^6*y^8 - 11781*x^