A categorical programming language
Revision | a61be0ee5cb44a56b79e7beed0ea5cd734a1fa18 (tree) |
---|---|
Time | 2022-10-18 10:31:27 |
Author | Corbin <cds@corb...> |
Commiter | Corbin |
Many animations work in Honey!
deco-circles, red-ellipse, and max-headroom all work! jupiter-storm is
still giving a blank screen, but it seems like the fundamentals are
finally there.
We are currently pegging the CPU at 5 frames/s. I would like to
eventually get to about 20 frames/s.
@@ -37,9 +37,10 @@ class Extractor { | ||
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | -function fixNaN(x) { return isNaN(x) ? [false, null] : [true, x]; } | |
40 | +function fixNaN(x) { | |
41 | + return isNaN(x) ? Cammy.right(Cammy.ignore(null)) : Cammy.left(x); | |
42 | +} | |
41 | 43 | function rescueNaN(f) { return x => fixNaN(f(x)); } |
42 | -function rescueNaN2(f) { return xy => fixNaN(f(Cammy.fst(xy), Cammy.snd(xy))); } | |
43 | 44 | |
44 | 45 | const prims = { |
45 | 46 | "id": Cammy.id, |
@@ -54,8 +55,8 @@ const prims = { | ||
54 | 55 | "f": _ => false, |
55 | 56 | "not": b => !b, |
56 | 57 | "either": Cammy.either, |
57 | - "disj": ([b, c]) => b || c, | |
58 | - "conj": ([b, c]) => b && c, | |
58 | + "disj": bc => Cammy.fst(bc) || Cammy.snd(bc), | |
59 | + "conj": bc => Cammy.fst(bc) && Cammy.snd(bc), | |
59 | 60 | "zero": _ => 0, |
60 | 61 | "succ": n => n + 1, |
61 | 62 | "n-add": xy => Cammy.natAdd(Cammy.fst(xy))(Cammy.snd(xy)), |
@@ -68,13 +69,13 @@ const prims = { | ||
68 | 69 | "f-add": xy => Cammy.fst(xy) + Cammy.snd(xy), |
69 | 70 | "f-mul": xy => Cammy.fst(xy) * Cammy.snd(xy), |
70 | 71 | "f-negate": x => -x, |
71 | - "f-recip": rescueNaN(x => 1 / x), | |
72 | + "f-recip": x => 1 / x, | |
72 | 73 | "f-sign": x => x <= -0.0, |
73 | 74 | "f-floor": rescueNaN(Math.floor), |
74 | 75 | "f-sqrt": rescueNaN(Math.sqrt), |
75 | 76 | "f-lt": xy => Cammy.fst(xy) < Cammy.snd(xy), |
76 | - "f-sin": rescueNaN(Math.sin), | |
77 | - "f-cos": rescueNaN(Math.cos), | |
77 | + "f-sin": x => Number.isFinite(x) ? Math.sin(x) : 0.0, | |
78 | + "f-cos": x => Number.isFinite(x) ? Math.cos(x) : 0.0, | |
78 | 79 | "f-atan2": yx => Math.atan2(Cammy.fst(yx), Cammy.snd(yx)), |
79 | 80 | }; |
80 | 81 | function compile(expr) { |
@@ -196,7 +197,6 @@ function tileForIndex(extractor, index, title, trail) { | ||
196 | 197 | const canvas = document.createElement("canvas"); |
197 | 198 | canvas.width = 100; canvas.height = 100; |
198 | 199 | div.appendChild(canvas); |
199 | - Cammy.runTrampoline(compiled(Cammy.makePair(0)(0))); | |
200 | 200 | drawFrame(canvas, (x, y) => Cammy.runTrampoline(compiled(Cammy.makePair(x)(y))), getChannels); |
201 | 201 | } else { |
202 | 202 | div.innerHTML += "Not sure how to display this image yet."; |
@@ -208,6 +208,8 @@ function tileForIndex(extractor, index, title, trail) { | ||
208 | 208 | const canvas = document.createElement("canvas"); |
209 | 209 | canvas.width = 100; canvas.height = 100; |
210 | 210 | div.appendChild(canvas); |
211 | + console.log("test run", | |
212 | + Cammy.runTrampoline(compiled(Cammy.makePair(Cammy.makePair(0)(0))(0)))); | |
211 | 213 | let start; |
212 | 214 | function stepFrame(timestamp) { |
213 | 215 | if (start === undefined) { start = timestamp; } |
@@ -215,7 +217,7 @@ function tileForIndex(extractor, index, title, trail) { | ||
215 | 217 | drawFrame(canvas, (x, y) => { |
216 | 218 | return Cammy.runTrampoline(compiled(Cammy.makePair(Cammy.makePair(x)(y))(t))); |
217 | 219 | }, getChannels); |
218 | - setTimeout(() => window.requestAnimationFrame(stepFrame), 1000); | |
220 | + setTimeout(() => window.requestAnimationFrame(stepFrame), 200); | |
219 | 221 | } |
220 | 222 | window.requestAnimationFrame(stepFrame); |
221 | 223 | } else { |