【パターン-2】ランダムにボックスパターンを描いてみよう

randを使って位置、大きさ、線幅をランダムな値にしてボックスを描きます。

rand 201 modで0〜200の値が返ります。
次に100 subで0-100=-100、200-100=100となり、-100から100の間のランダムな値を得ることができます。


1
2
3
4
5
6
7
8
9
10
11
12
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 240 240
%%Title:ランダムにボックスパターンを描く
newpath % パスの初期化
0 1 200 { % 0から1づつ増やし200になるまで{ }内を繰り返す
    /x rand 201 mod 100 sub def % x座標(-100〜100)
    /y rand 201 mod 100 sub def % y座標(-100〜100)
    /w rand 151 mod 70 sub def % 横幅(-70〜80)
    /h rand 151 mod 70 sub def % 縦幅(-70〜80)
    rand 11 mod .1 mul setlinewidth % 線幅(0.0〜1.0)
    x y w h rectstroke %四角形を描く
} for

次は色もランダムにします。
randam_colorプロシージャを呼び出して色を割り当てます。


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:ランダムにボックスパターンを描く
/x rand 201 mod 100 sub def % x座標(-100〜100)
/y rand 201 mod 100 sub def % y座標(-100〜100)
/w rand 151 mod 70 sub def % 横幅(-70〜80)
/h rand 151 mod 70 sub def % 縦幅(-70〜80)

/randam_color { % ランダムカラープロシージャ
    /r rand 11 mod 0.1 mul def % R色(0.1〜1)
    /g rand 5 mod 0.1 mul def % G色(0.1〜0.4)
    /b rand 11 mod 0.1 mul def % B色(0.1〜1)
    r g b setrgbcolor % RGBカラーを設定する
} def

0 1 80 { % 0から1づつ増やし80になるまで{ }内を繰り返す
     randam_color % ランダムカラープロシージャ呼び出し
     x y w h rectfill % 塗りつぶし四角形を描く
} for

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

コメント

コメントする

CAPTCHA


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

目次