From 1fffae50b765419864451975ef1049aa4a6ec08a Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 12 Apr 2021 21:49:10 -0400 Subject: =?UTF-8?q?Add=20very=20basic=20SVG=20=E2=80=A2Plot=20to=20the=20R?= =?UTF-8?q?EPL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cjs.bqn | 6 ++++-- src/p.bqn | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/p.bqn (limited to 'src') diff --git a/src/cjs.bqn b/src/cjs.bqn index 30d94098..2a282b84 100755 --- a/src/cjs.bqn +++ b/src/cjs.bqn @@ -27,10 +27,12 @@ Fconst ← ≡◶⟨@⊸≤◶Num‿Char, Str, ⊑⟩ Fout ← (≠↑⟨F,Fconst,L F¨,F⟩˙) {L𝕎¨𝕩}¨ ⊢ Frun ← "provide"⊸Cat⌾(1⊸⊑) Fout Long ← ∾ (≠↑1‿3/⟨" "⊸∾⋄((@+10)∾" ,")⊸∾⟩˙) {𝕎𝕩}¨ ⊢ -•Out (⊑"r"‿"c"‿"f"‿"e"⊐⊏)◶⟨ +SVG ← {∾⟨"Modify←GetHighlights←⊢⋄"⟩∾ •FChars∘∾⟜".bqn"¨ "../svg"‿𝕩} +•Out (⊑"r"‿"c"‿"f"‿"e"‿"p"⊐⊏)◶⟨ {𝕩⋄ref‿len←•Import"pr.bqn"⋄Long Frun len⊸↓⌾(1⊸⊑)Comp ref} {𝕩⋄Long Fout Comp •FChars "c.bqn"} {𝕩⋄Long Fout Comp •FChars "f.bqn"} - {𝕩⋄Long Fout Comp ∾⟨"Modify←GetHighlights←⊢⋄"⟩∾ •FChars∘∾⟜".bqn"¨ "../svg"‿"e"} + {𝕩⋄Long Fout Comp SVG "e"} + {𝕩⋄Long Fout Comp SVG "p"} ¯1 ↓ · J L∘Fout∘Comp¨ ⟩ args 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 + ⟩ +} -- cgit v1.2.3