

渦巻きにも色々な種類がありますが、巻幅が一定なアルキメデスの渦巻きを描いてみましょう。数式は以下です。
x=sin(r*th)*th/2
y=cos(r*th)*th/2
前置記法にするために少し順番や( )を付けて整形しないとうまくいきません。
x=(r*th)sin*(th/2)
y=(r*th)cos*(th/2)
この数式をPostScriptで書くとこうなります。
/x r th mul sin th 2 div mul def
/y r th mul cos th 2 div mul def
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:Archimedes' spiral(アルキメデスの渦巻き)を描く /r 15 def % 図を納めるための数値 /sw 0 def % 始点を置くためのスイッチ 0 0 240 240 rectfill % 背景を黒四角形にする 120 120 translate % 座標の原点を中央に移動 newpath % パスの初期化 0 .5 220 { % 0から初めて0.5増分し、220まで { }内を繰り返す /th exch def % 制御変数をth(角度)に入れる /x r th mul sin th 2 div mul def % 渦巻きの数式 /y r th mul cos th 2 div mul def % swが0なら始点をさもなくば線を引く sw 0 eq { x y moveto /sw 1 def }{ x y lineto } ifelse } for .7 .4 .8 sethsbcolor % 色設定 3 setlinewidth % 線幅3ポイント stroke % 描画 |

scaleで水平と垂直方向の値を別々にすると立体的な効果が表現できます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 240 240 %%Title:Archimedes' spiral(アルキメデスの渦巻き)を描く /r 15 def % 図を納めるための数値 /sw 0 def % 始点を置くためのスイッチ 0 0 240 240 rectfill % 背景を黒四角形にする 120 120 translate % 座標の原点を中央に移動 newpath % パスの初期化 0 .5 220 { % 0から初めて0.5増分し、220まで { }内を繰り返す /th exch def % 制御変数をth(角度)に入れる /x r th mul sin th 2 div mul def % 渦巻きの数式 /y r th mul cos th 2 div mul def % swが0なら始点をさもなくば線を引く sw 0 eq { x y moveto /sw 1 def }{ x y lineto } ifelse } for .7 .4 .8 sethsbcolor % 色設定 30 rotate 7 1 scale % 30度座標を回転させ、x軸方向を伸ばす stroke % 描画 |
コメント