

デルトイドまたはトリカスポイドは三角形的な曲線です。
x=a*(2*cos(th)+cos(2*th))
y=a*(2*sin(th)-sin(2*th))
または
x=c*a*cos(th)+a*cos(2*th)
y=c*a*sin(th)-a*sin(2*th)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:Deltoid(デルトイド)またはTricuspoid(トリカスポイド) /a 35 def % 図形の大きさ 0 0 240 240 rectfill % 黒背景 110 120 translate % 図形を中央に移動 newpath % パスの初期化 0 1 360 { % 0から始めて360まで1づつ増分し{ }内を繰り返す /th exch def % 制御変数をth(角度)に入れる % デルトイドの数式 /x a 2 th cos mul 2 th mul cos add mul def /y a 2 th sin mul 2 th mul sin sub mul def % thが0なら始点を置き、さもなくば線を引く th 0 eq {x y moveto } { x y lineto } ifelse } for 1 1 1 setrgbcolor % 白色 2 setlinewidth % 線幅2ポイント stroke % 線を描画する |

PostScriptにはswitch文はありませんが、ifelse文を使ってswitch文もどきはできます。
0、1 、2の3個の値をランダムに生成し、switch文でそれぞれに対応したカラー値を割り振っています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:Deltoid(デルトイド)を描く /a 40 def % 図形の大きさ /c 1.5 def % パラメータ /rn 0 def % ランダムな値を入れるための変数 /c01 { 1 0 .5 setrgbcolor } def % カラー01 /c02 { .5 .2 1 setrgbcolor } def % カラー02 /c03 { 1 .6 0 setrgbcolor } def % カラー03 0 0 240 240 rectfill % 黒背景 110 120 translate % 図形を中央に移動 newpath % パスの初期化 0 .1 2 { % 0から始めて2まで0.1づつ増分し{ }内を繰り返す /c exch def % 制御変数をcに入れる 0 1 360 { % 0から始めて360まで1づつ増分し{ }内を繰り返す /th exch def % 制御変数をth(角度)に入れる % デルトイドの数式 /x c a mul th cos mul a 2 th mul cos mul add def /y c a mul th sin mul a 2 th mul sin mul sub def % thが0なら始点を置き、さもなくば線を引く th 0 eq { x y moveto } { x y lineto } ifelse } for closepath % 線を繋ぐ /rn rand 3 mod def % 0、1、2の値をランダムに生成しrnに入れる % rnが0ならカラー01、1ならカラー02、2ならカラー03にする rn 0 eq { c01 } { rn 1 eq { c02 } { c03 } ifelse } ifelse stroke % 線を描画 } for |
パラメータを色々変えてみると様々な形が現れてきます。

コメント