

通常は8の字が横になっている図形なのですが、xとyを入れ替えて縦の8の字になるようにしました。
x=a*sin(th)
y=a*sin(th)*cos(th)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:eight_curve(エイトカーブ)を描く /a 100 def % 図形の大きさ 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の原点を中央に移動 newpath % パスの初期化 0 1 360 { % 0から始めて360まで1づつ増分し{ }内を繰り返す /th exch def % 制御変数をth(角度)に入れる % エイトカーブの数式(xとyを入れ替え) /y a th sin mul def /x a th sin mul th cos mul def % thが0なら始点をさもなくば線を引く th 0 eq { x y moveto } { x y lineto } ifelse } for closepath % 線を繋ぐ 1 1 1 setrgbcolor % 白色 2 setlinewidth % 線幅2ポイント stroke % 線を描画 |

座標を回転させながら拡大していきます。
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 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:eight_curve(エイトカーブ)を描く /a 100 def % 図形の大きさ 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の原点を中央に移動 newpath % パスの初期化 73 { % { }内を73回繰り返す 0 1 360 { % 0から始めて360まで1づつ増分し{ }内を繰り返す /th exch def % 制御変数をth(角度)に入れる % エイトカーブの数式 /y a th sin mul def /x a th sin mul th cos mul def % thが0なら始点をさもなくば線を引く th 0 eq { x y moveto } { x y lineto } ifelse } for closepath % 線を繋ぐ rc gc bc setrgbcolor % カラー設定 .5 setlinewidth % 線幅0.5ポイント /rc rc .03 add def % R色から0.03を足す /gc gc .01 add def % G色から0.01を足す /bc bc .01 sub def % B色から0.01を引く stroke % 線を描画 5 rotate % 座標を5度回転 1.011 dup scale % 座標を1.011拡大 } repeat |
コメント