lambdaway
::
super_ellipse
3
|
list
|
login
|
load
|
|
{{SVG 600 600} {g {AXES 600 600} {polyline {@ points="{S.map {superellipse 200 100 4} {S.serie -1 1.01 0.01}}" {stroke #f00 4}}} {polyline {@ points="{S.map {superellipse 100 200 0.5} {S.serie -1 1.01 0.01}}" {stroke #0f0 4}}} {polyline {@ points="{S.map {superellipse 200 200 1} {S.serie -1 1.01 0.01}}" {stroke #888 2}}} {polyline {@ points="{S.map {superellipse 200 200 2} {S.serie -1 1.01 0.01}}" {stroke #888 2}}} }} _h1 superellipse (x/a){sup n}+(y/b){sup n}=1 _p Following [[rosettacode.org|https://rosettacode.org/wiki/Superellipse#Lambdatalk]] draw a superellipse with n = 2.5, and a = b = 200. {pre '{def superellipse {def sgn {lambda {:n} {if {< :n 0} then - else +}}} {lambda {:a :b :n :t} {let { {:a :a} {:b :b} {:n {/ 2 :n}} {:cost {cos {* {PI} :t}}} {:sint {sin {* {PI} :t}}} } {sgn :cost}{* :a {pow {abs :cost} :n}} {sgn :sint}{* :b {pow {abs :sint} :n}} }}} -> {def superellipse {def sgn {lambda {:n} {if {< :n 0} then - else +}}} {lambda {:a :b :n :t} {let { {:a :a} {:b :b} {:n {/ 2 :n}} {:cost {cos {* {PI} :t}}} {:sint {sin {* {PI} :t}}} } {sgn :cost}{* :a {pow {abs :cost} :n}} {sgn :sint}{* :b {pow {abs :sint} :n}} }}} } _p We use {b SVG} and the [[lib_plot]] library defining the {b SVG, AXES, stroke} functions to draw 4 superellipses, a rounded rectangle, a circle and a square. {pre '{{SVG 600 600} {g {AXES 600 600} {polyline {@ points="{S.map {superellipse 200 300 2.5} {S.serie -1 1.01 0.01}}" {stroke #f00 4}}} {polyline {@ points="{S.map {superellipse 100 200 0.5} {S.serie -1 1.01 0.01}}" {stroke #0f0 4}}} {polyline {@ points="{S.map {superellipse 200 200 1.0} {S.serie -1 1.01 0.01}}" {stroke #888 2}}} {polyline {@ points="{S.map {superellipse 200 200 2.0} {S.serie -1 1.01 0.01}}" {stroke #888 2}}} }} } {{hide} {def SVG {lambda {:w :h} svg {@ width=":wpx" height=":hpx" style="background:#eee; margin-left:-10px;"} }} {def AXES {lambda {:w :h} {@ transform="translate({/ :w 2} {/ :h 2}) scale(1,-1)"} {S.map {{lambda {:w :h :i} {line {@ x1="-{/ :w 2}" y1=":i" x2="{/ :w 2}" y2=":i" {stroke #f008" 1}}} {text {@ x="0" y=":i" transform="rotate(180) scale(-1,1)"} {round {/ :i -10}}} } :w :h} {S.serie -:h :h {/ :h {/ :h 50}}}} {S.map {{lambda {:w :h :i} {line {@ x1=":i" y1="-{/ :h 2}" x2=":i" y2="{/ :h 2}" {stroke #0f08" 1}}} {text {@ x=":i" y="0" transform="rotate(0) scale(1,-1)"} {round {/ :i 10}}} } :w :h} {S.serie -:w :w {/ :w {/ :w 50}}}} {line {@ x1="-{/ :w 2}" y1="0" x2="{/ :w 2}" y2="0" {stroke #f00 3}}} {line {@ x1="0" y1="-{/ :h 2}" x2="0" y2="{/ :h 2}" {stroke #0f0 3}}} }} {def stroke {lambda {:col :w} stroke=":col" fill="transparent" stroke-width=":w" }} }
lambdaway v.20211111