【曲線-13】バタフライカーブを描いてみよう

具象的な曲線の5回目はバタフライ曲線を描きます。
バタフライ曲線は、Temple H.Fayによって発見された超越平面曲線ということです。

式は非常に複雑で、PostScriptにすると長くなります。

x=sin(th)*(ecos(th)-2*cos(4*th)-sin(th/12)5)
y=cos(th)*(ecos(th)-2*cos(4*th)-sin(th/12)5)

wikipedia Butterfly curve (transcendental)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 240 240
%%Title:バタフライ曲線を描く
0 0 240 240 rectfill % 黒背景
120 100 translate   % 図形が中央にくるよう座標を移動
/p 360 def % 360を一単位にする
/e 2.718281828 def % 自然対数の底

newpath % パスの初期化
0 1 p { % 0から初めてpまで1づつ増分し{ }内を繰り返す
    /th exch def % 制御変数をth(角度)に入れる
    % バタフライ曲線の数式
    /x th sin e th cos exp 2 4 th mul cos mul sub th 12 div sin 5 exp sub mul def
    /y th cos e th cos exp 2 4 th mul cos mul sub th 12 div sin 5 exp sub mul def
    % 図形を拡大する
    /x x 40 mul def /y y 40 mul def
    % thが0なら始点を置き、さもなくば線を引く
    th 0 eq { x y moveto } { x y lineto } ifelse
} for
closepath % 線を繋ぐ
1 1 1 setrgbcolor % 白色
stroke % 線を描画

線を重ねてネオンのような効果を表現してみました。
今回はグラフィックス状態をグラフィックス状態スタックに同じものを2回保存して、線を描画した後に2回復元しています。


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
32
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 240 240
%%Title:バタフライ曲線を描く
0 0 240 240 rectfill % 黒背景
120 100 translate % 図形が中央にくるよう座標を移動
/p 360 def % 360を一単位にする
/e 2.718281828 def % 自然対数の底

newpath % パスの初期化
0 1 p 11 mul { % 0から初めてp*11まで1づつ増分し{ }内を繰り返す
    /th exch def % 制御変数をth(角度)に入れる
    % バタフライ曲線の数式
    /x th sin e th cos exp 2 4 th mul cos mul sub th 12 div sin 5 exp sub mul def
    /y th cos e th cos exp 2 4 th mul cos mul sub th 12 div sin 5 exp sub mul def
    % 図形を拡大する
    /x x 30 mul def /y y 30 mul def
    % thが0なら始点を置き、さもなくば線を引く
    th 0 eq { x y moveto } { x y lineto } ifelse
} for
closepath % 線を繋ぐ
gsave gsave % グラフィックス状態を2回保存
.5 0 .5 setrgbcolor % 暗いピンク
5 setlinewidth % 線幅5ポイント
stroke % 線を描画
grestore % グラフィックス状態を1回目復元
1 0 1 setrgbcolor % 以下同様
2 setlinewidth
stroke
grestore % グラフィックス状態を2回目復元
1 1 1 setrgbcolor
.5 setlinewidth
stroke

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

コメント

コメントする

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

目次