From b2220e82c0d10e85442a53b574dc3c9f1b9ac63b Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 13 Apr 2021 10:05:01 -0400 Subject: Avoid rescaling plot if aspect ratio is small --- src/p.bqn | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/p.bqn b/src/p.bqn index bbff5417..839e3a0e 100644 --- a/src/p.bqn +++ b/src/p.bqn @@ -1,7 +1,7 @@ # Plot -dim← 2⥊384 -pad← 2⥊10 +width ← 384 +pad ← 2⥊10 ps ← At "class=red|style=fill:none|stroke-width=1" rc ← At "class=code|stroke-width=1|rx=5" @@ -10,8 +10,13 @@ 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 𝕩 + xy ← 1e300 (⊣-⊸⌈⌊) ⟨𝕨↕∘≠⊘⊣𝕩, 𝕩⟩ # default x and clip + bounds ← (-˜`⌊´≍⌈´)¨ xy # min and range + ar ← 1⍟((÷4)⊸>∨1.5⊸<) ÷˜´ 1⊑¨bounds # height÷width + dim ← width (⊣≍×) ar + scale ← {𝕩÷˜𝕨-˜⊢}´¨ bounds + p ← dim × ≍⟜¬´ scale {𝕎𝕩}¨ xy + path ← 'M'⌾⊑ ∾⥊⍉ "L " ∾¨ FmtNum p ((-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