Skip to content

Instantly share code, notes, and snippets.

@jaredly
Last active September 5, 2021 17:48
Show Gist options
  • Save jaredly/869c956475930a2adde00735eadbd314 to your computer and use it in GitHub Desktop.
Save jaredly/869c956475930a2adde00735eadbd314 to your computer and use it in GitHub Desktop.
@ffi("Vec2") type Vec2#08f7c2ac = {
x: float#builtin,
y: float#builtin,
};
@ffi("End") type End#830ad468 = {};
@ffi("Start") type Start#098d99e8 = {};
@ffi("Center") type Center#1189540a = {};
@ffi("Right") type Right#5cfc662e = {};
@ffi("Left") type Left#43051e9e = {};
@ffi("Rgba") type Rgba#52033f94 = {
r: float#builtin,
g: float#builtin,
b: float#builtin,
a: float#builtin = 1.0,
};
@ffi("CSS") type CSS#742a31c2 = {
value: string#builtin,
};
@ffi("Square") type Square#155bb0ac = {};
@ffi("Round") type Round#51486760 = {};
@ffi("Butt") type Butt#1ac05bf8 = {};
@ffi("Path") type Path#ddadd8a8 = {
start: Vec2#08f7c2ac,
closed: bool#builtin = false,
parts: Array#builtin<PathPart#33159eb4>,
};
@ffi("Rect") type Rect#126fdf00 = {
pos: Vec2#08f7c2ac,
size: Vec2#08f7c2ac,
rotation: float#builtin = 0.0,
};
@ffi("Polygon") type Polygon#cafe28b8 = {
points: Array#builtin<Vec2#08f7c2ac>,
closed: bool#builtin = true,
};
@ffi("Line") type Line#565da092 = {
p1: Vec2#08f7c2ac,
p2: Vec2#08f7c2ac,
};
@ffi("Ellipse") type Ellipse#098fbabc = {
pos: Vec2#08f7c2ac,
radius: Vec2#08f7c2ac,
rotation: float#builtin = 0.0,
};
enum TextAlign#eaefd106 {
Left#43051e9e,
Right#5cfc662e,
Center#1189540a,
Start#098d99e8,
End#830ad468,
};
enum Color#1fe34118 {
CSS#742a31c2,
Rgba#52033f94,
};
enum LineCap#5e11f0b9 {
Butt#1ac05bf8,
Round#51486760,
Square#155bb0ac,
};
enum Geom#619d2fc4 {
Ellipse#098fbabc,
Line#565da092,
Polygon#cafe28b8,
Rect#126fdf00,
Path#ddadd8a8,
};
@ffi("Text") type Text#d86ebaa8 = {
text: string#builtin,
color: Color#1fe34118,
pos: Vec2#08f7c2ac,
stroke: float#builtin = 0.0,
font: string#builtin = "",
textAlign: TextAlign#eaefd106 = TextAlign#eaefd106:Start#098d99e8,
};
@ffi("Stroke") type Stroke#adcc8cc6 = {
geom: Geom#619d2fc4,
color: Color#1fe34118,
width: float#builtin = 1.0,
lineCaps: LineCap#5e11f0b9 = LineCap#5e11f0b9:Round#51486760,
};
@ffi("Fill") type Fill#3bd0cc4c = {
geom: Geom#619d2fc4,
color: Color#1fe34118,
};
type AddSub#3d436b7e<A#:0, B#:1, C#:2> = {
"+": (A#:0, B#:1) ={}> C#:2,
"-": (A#:0, B#:1) ={}> C#:2,
};
type None#None = {};
type As#As<T#:10000, Y#:10001> = {
as: (T#:10000) ={}> Y#:10001,
};
enum Drawable#56de3b71 {
Fill#3bd0cc4c,
Stroke#adcc8cc6,
Text#d86ebaa8,
};
@ffi("CanvasScene") type CanvasScene#1e1c730c<State#:0> = {
initial: State#:0,
update: (state: State#:0, dt: float#builtin) ={}> State#:0,
draw: (state: State#:0) ={}> Array#builtin<Drawable#56de3b71>,
clear: bool#builtin = true,
fps: float#builtin = 60.0,
size: Vec2#08f7c2ac = Vec2#08f7c2ac{x#08f7c2ac#0: 200.0, y#08f7c2ac#1: 200.0},
};
const vec2#fa534764 = (x#:0: float#builtin, y#:1: float#builtin): Vec2#08f7c2ac ={}> Vec2#08f7c2ac{
x#08f7c2ac#0: x#:0,
y#08f7c2ac#1: y#:1,
};
const closeEnough#46ea1b68 = (x#:0: float#builtin, y#:1: float#builtin): bool#builtin ={}> abs#builtin(
x#:0 -#builtin y#:1,
)
<#builtin 0.001;
const thetaPos2#b03288dc = (theta#:0: float#builtin): Vec2#08f7c2ac ={}> vec2#fa534764(
x: cos#builtin(theta#:0),
y: sin#builtin(theta#:0),
);
const Vec2float#db41487e = Mul#02cc25c4<Vec2#08f7c2ac, float#builtin, Vec2#08f7c2ac>{
"*"#02cc25c4#0: (v#:0: Vec2#08f7c2ac, scale#:1: float#builtin): Vec2#08f7c2ac ={}> Vec2#08f7c2ac{
x#08f7c2ac#0: v#:0.x#08f7c2ac#0 *#builtin scale#:1,
y#08f7c2ac#1: v#:0.y#08f7c2ac#1 *#builtin scale#:1,
},
};
const AddSubVec2#04f14e9c = AddSub#3d436b7e<Vec2#08f7c2ac, Vec2#08f7c2ac, Vec2#08f7c2ac>{
"+"#3d436b7e#0: (one#:0: Vec2#08f7c2ac, two#:1: Vec2#08f7c2ac): Vec2#08f7c2ac ={}> Vec2#08f7c2ac{
x#08f7c2ac#0: one#:0.x#08f7c2ac#0 +#builtin two#:1.x#08f7c2ac#0,
y#08f7c2ac#1: one#:0.y#08f7c2ac#1 +#builtin two#:1.y#08f7c2ac#1,
},
"-"#3d436b7e#1: (one#:2: Vec2#08f7c2ac, two#:3: Vec2#08f7c2ac): Vec2#08f7c2ac ={}> Vec2#08f7c2ac{
x#08f7c2ac#0: one#:2.x#08f7c2ac#0 -#builtin two#:3.x#08f7c2ac#0,
y#08f7c2ac#1: one#:2.y#08f7c2ac#1 -#builtin two#:3.y#08f7c2ac#1,
},
};
const IntAsFloat#6f186ad1 = As#As<int#builtin, float#builtin>{as#As#0: intToFloat#builtin};
const closeEnough#592665e2 = (a#:0: Vec2#08f7c2ac, b#:1: Vec2#08f7c2ac): bool#builtin ={}> closeEnough#46ea1b68(
x: a#:0.x#08f7c2ac#0,
y: b#:1.x#08f7c2ac#0,
)
&&#builtin closeEnough#46ea1b68(x: a#:0.y#08f7c2ac#1, y: b#:1.y#08f7c2ac#1);
const rec fullSpiral#1ca228e8 = (
at#:0: int#builtin,
by#:1: float#builtin,
length#:2: float#builtin,
theta#:3: float#builtin,
pos#:4: Vec2#08f7c2ac,
points#:5: Array#builtin<Vec2#08f7c2ac>,
initial#:6: Tuple2#builtin<float#builtin, Vec2#08f7c2ac>,
max#:7: int#builtin,
): Tuple2#builtin<Array#builtin<Vec2#08f7c2ac>, bool#builtin> ={}> {
if at#:0 >=#builtin max#:7 {
(points#:5, false);
} else if at#:0 >#builtin 0
&&#builtin closeEnough#46ea1b68(
x: mod#builtin(theta#:3, PI#builtin *#builtin 2.0),
y: initial#:6.0,
)
&&#builtin closeEnough#592665e2(a: pos#:4, b: initial#:6.1) {
(points#:5, true);
} else {
const next#:8 = theta#:3 +#builtin by#:1 *#builtin at#:0 as#6f186ad1 float#builtin;
const nextPos#:9 = pos#:4
+#04f14e9c#3d436b7e#0 thetaPos2#b03288dc(theta#:3) *#db41487e#02cc25c4#0 length#:2;
fullSpiral#self(
at#:0 +#builtin 1,
by#:1,
length#:2,
next#:8,
nextPos#:9,
<Vec2#08f7c2ac>[...points#:5, nextPos#:9],
initial#:6,
max#:7,
);
};
};
const FloatAsString#5f7b38a6 = As#As<float#builtin, string#builtin>{as#As#0: floatToString#builtin};
const IntAsString#1175499e = As#As<int#builtin, string#builtin>{as#As#0: intToString#builtin};
const AddSubVec2_#23f7c6c9 = AddSub#3d436b7e<Vec2#08f7c2ac, float#builtin, Vec2#08f7c2ac>{
"+"#3d436b7e#0: (one#:0: Vec2#08f7c2ac, two#:1: float#builtin): Vec2#08f7c2ac ={}> Vec2#08f7c2ac{
x#08f7c2ac#0: one#:0.x#08f7c2ac#0 +#builtin two#:1,
y#08f7c2ac#1: one#:0.y#08f7c2ac#1 +#builtin two#:1,
},
"-"#3d436b7e#1: (one#:2: Vec2#08f7c2ac, two#:3: float#builtin): Vec2#08f7c2ac ={}> Vec2#08f7c2ac{
x#08f7c2ac#0: one#:2.x#08f7c2ac#0 -#builtin two#:3,
y#08f7c2ac#1: one#:2.y#08f7c2ac#1 -#builtin two#:3,
},
};
const rec reduceRange#2477877c = <T0#:0>(
start#:0: int#builtin,
end#:1: int#builtin,
init#:2: T#:0,
fn#:3: (T#:0, int#builtin) ={}> T#:0,
): T#:0 ={}> {
if start#:0 >=#builtin end#:1 {
init#:2;
} else {
reduceRange#self<T#:0>(start#:0 +#builtin 1, end#:1, fn#:3(init#:2, start#:0), fn#:3);
};
};
const vec2#fd62385c = (x#:0: float#builtin): Vec2#08f7c2ac ={}> Vec2#08f7c2ac{
x#08f7c2ac#0: x#:0,
y#08f7c2ac#1: x#:0,
};
const calcSpiral#65183522 = (
by#:0: float#builtin,
length#:1: float#builtin,
pos#:2: Vec2#08f7c2ac,
max#:3: int#builtin,
): Tuple2#builtin<Array#builtin<Vec2#08f7c2ac>, bool#builtin> ={}> {
fullSpiral#1ca228e8(
at: 0,
by#:0,
length#:1,
theta: 0.0,
pos#:2,
points: <Vec2#08f7c2ac>[],
initial: (0.0, pos#:2),
max#:3,
);
};
@display("canvas")
{
const drawSpiral#:3 = (by#:0: float#builtin, pos#:1: Vec2#08f7c2ac): Drawable#56de3b71 ={}> {
const result#:2 = calcSpiral#65183522(by#:0, length: 5.0, pos#:1, max: 10040);
Drawable#56de3b71:Stroke#adcc8cc6{
geom#adcc8cc6#0: Geom#619d2fc4:Polygon#cafe28b8{
points#cafe28b8#0: result#:2.0,
closed#cafe28b8#1: false,
},
color#adcc8cc6#1: Color#1fe34118:CSS#742a31c2{value#742a31c2#0: "rgba(255,0,0,0.5)"},
};
};
const A#:4 = @slider#4e421b50(min: 1, max: 100, step: 2) @title#1b6d573e(title: "A") 41;
const base#:5 = 10.0;
const initial#:6 = A#:4 as#6f186ad1 float#builtin
*#builtin @slider#b981a438(min: 1.0, max: 100.0, step: 1.0) @title#1b6d573e(
title: "B",
) 10.0
+#builtin 1.0;
const width#:7 = 2200.0;
const row#:8 = 6;
const w#:9 = width#:7 /#builtin row#:8 as#6f186ad1 float#builtin;
const size#:10 = vec2#fa534764(
x: width#:7,
y: ceil#builtin(A#:4 as#6f186ad1 float#builtin /#builtin row#:8 as#6f186ad1 float#builtin)
*#builtin w#:9,
);
CanvasScene#1e1c730c<None#None>{
initial#1e1c730c#0: None#None,
update#1e1c730c#1: (state#:11: None#None, _#:12: float#builtin): None#None ={}> None#None,
draw#1e1c730c#2: (_#:13: None#None): Array#builtin<Drawable#56de3b71> ={}> {
<Drawable#56de3b71>[
Drawable#56de3b71:Fill#3bd0cc4c{
geom#3bd0cc4c#0: Geom#619d2fc4:Rect#126fdf00{
pos#126fdf00#0: vec2#fd62385c(x: 0.0),
size#126fdf00#1: size#:10,
},
color#3bd0cc4c#1: Color#1fe34118:CSS#742a31c2{value#742a31c2#0: "black"},
},
...reduceRange#2477877c<Array#builtin<Drawable#56de3b71>>(
start: 0,
end: A#:4 -#builtin 1,
init: <Drawable#56de3b71>[],
fn: (current#:14: Array#builtin<Drawable#56de3b71>, state#:15: int#builtin): Array#builtin<
Drawable#56de3b71,
> ={}> {
const x#:16 = modInt#builtin(state#:15, row#:8);
const y#:17 = state#:15 /#builtin row#:8;
const top#:18 = state#:15 as#6f186ad1 float#builtin;
const t2#:19 = 11.0 +#builtin x#:16 as#6f186ad1 float#builtin;
const bottom#:20 = A#:4 as#6f186ad1 float#builtin;
const b2#:21 = 21.0
+#builtin (y#:17 *#builtin 2) as#6f186ad1 float#builtin;
const pos#:22 = vec2#fa534764(
x: w#:9 *#builtin x#:16 as#6f186ad1 float#builtin,
y: w#:9 *#builtin y#:17 as#6f186ad1 float#builtin,
);
const B#:23 = initial#:6 +#builtin state#:15 as#6f186ad1 float#builtin;
<Drawable#56de3b71>[
...current#:14,
drawSpiral#:3(
A#:4 as#6f186ad1 float#builtin *#builtin PI#builtin /#builtin B#:23,
pos#:22 +#23f7c6c9#3d436b7e#0 w#:9 /#builtin 2.0,
),
Drawable#56de3b71:Text#d86ebaa8{
text#d86ebaa8#0: A#:4 as#1175499e string#builtin
+#builtin " * π / "
+#builtin B#:23 as#5f7b38a6 string#builtin,
color#d86ebaa8#1: Color#1fe34118:CSS#742a31c2{
value#742a31c2#0: "white",
},
pos#d86ebaa8#2: pos#:22
+#04f14e9c#3d436b7e#0 vec2#fa534764(x: 4.0, y: 20.0),
font#d86ebaa8#4: "200 16px system-ui",
},
];
},
),
];
},
fps#1e1c730c#4: 0.0,
size#1e1c730c#5: size#:10,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment