

バラ曲線(または正葉線)を描きます。
花弁の数はnの値が奇数ならその数と同じに、偶数なら2倍になります。
花弁の数は0.1から設定できますが、値が小さいとその分pを20くらいにする必要があります。
aは図形の大きさを調整します。数式はこちらです。
r=a*sin(th*n)
x=r*cos(th)
y=r*sin(th)
または
x=a*sin(n*th)*cos(th)
y=a*sin(n*th)*sin(th)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:Rose curve(バラ曲線/正葉線)を描く /a 110 def % 図形の大きさ /n 4 def % 花弁の数 /p 4 def % 最大角度を変えるための値 /max 90 p mul def % 最大角度(90度を一単位) 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の原点を中央に移動 newpath % パスの初期化 0 1 max { % 0から1づつ増分しmaxまで{ } 内を繰り返す /th exch def % 制御変数をth(角度)に入れる % バラ曲線の数式 /r a th n mul sin mul def /x r th cos mul def /y r th sin mul def % thが0なら始点を置き、さもなくば線を引く th 0 eq { x y moveto /sw 1 def } { x y lineto } ifelse } for closepath % 線を繋ぐ 1 .5 0 setrgbcolor % 色設定 2 setlinewidth % 線幅2ポイント stroke % 線を描画 |

for文を加えて色に変化をつけました。
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 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:Rose curve(バラ曲線/正葉線)を描く /rc 1 def % R色 /bc 1 def % B色 /a 60 def % 図形の大きさ /n 4 def % 花弁の数 /p 4 def % 最大角度を変えるための値 /max 90 p mul def % 最大角度(90度を一単位) 0 0 240 240 rectfill % 黒背景 120 120 translate % 座標の原点を中央に移動 newpath % パスの初期化 110 -20 0 { % 110から20づつ減分し0まで{ } 内を繰り返す /a exch def % 制御変数をaに入れる 0 1 max { % 0から1づつ増分しmaxまで{ } 内を繰り返す /th exch def % 制御変数をth(角度)に入れる % バラ曲線の数式 /r a th n mul sin mul def /x r th cos mul def /y r th sin mul def % thが0なら始点を置き、さもなくば線を引く th 0 eq { x y moveto /sw 1 def } { x y lineto } ifelse } for closepath % 線を繋ぐ rc .5 bc setrgbcolor % 色設定 /rc rc .2 sub def % R色から0.2を引く /bc bc .05 sub def % B色から0.1を引く fill % 塗りつぶす } for |
やってみよう nの値を変えると様々な図形ができます。

コメント