aboutsummaryrefslogtreecommitdiff
path: root/src/p.bqn
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-04-12 21:49:10 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-04-12 21:52:36 -0400
commit1fffae50b765419864451975ef1049aa4a6ec08a (patch)
treea78e3da59f07135e1867782b5e9910d892e443f6 /src/p.bqn
parentd23e345e929f6eb62cb12b72b07079b1efe5cfc6 (diff)
Add very basic SVG •Plot to the REPL
Diffstat (limited to 'src/p.bqn')
-rw-r--r--src/p.bqn19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/p.bqn b/src/p.bqn
new file mode 100644
index 00000000..bbff5417
--- /dev/null
+++ b/src/p.bqn
@@ -0,0 +1,19 @@
+# Plot
+
+dim← 2⥊384
+pad← 2⥊10
+
+ps ← At "class=red|style=fill:none|stroke-width=1"
+rc ← At "class=code|stroke-width=1|rx=5"
+gr ← "g" At "font-family=BQN,monospace|font-size=18px"
+
+Plot ← {
+ "•Plot: 𝕨 and 𝕩 must be lists of numbers" ! 𝕨 ⊢⊘∧○((1==)◶⟨0,∧´@⊸>⟩) 𝕩
+ "•Plot: 𝕨 and 𝕩 must have the same length" ! 𝕨 1⊘≡○≠ 𝕩
+ Norm ← ÷⟜(⌈´)·-⟜(⌊´)1e300(⊣-⊸⌈⌊)⊢
+ path ← 'M'⌾⊑ ∾⥊⍉ "L " ∾¨ FmtNum dim × (𝕨 ↕∘≠⊘⊣ 𝕩) ≍⟜¬○Norm 𝕩
+ ((-pad)∾dim+2×pad) SVG gr Enc ⟨
+ "rect" Elt rc∾(Pos-pad÷2)∾"width"‿"height"≍˘FmtNum dim+pad
+ ("path" Elt ps∾"d"≍○<⊢) path
+ ⟩
+}