
多角形に対角線を引き、頂点に円を置いた図形です。
nに3以上の角数を入れて、何角形でもできます。
1つの繰り返し構文で全てを描画しようとしましたが、うまくいきませんでした。
線と頂点の色を同じにすれば誤魔化せますが、違う色にしたため頂点の上に線が出てしまいました。
それで多角形、対角線、頂点の3パートに分けました。
角数が奇数の時は左右対称に見えないので補正しています。
失敗例
頂点の上に線が出て、左右対称になっていない

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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | %!PS-Adobe-3.0 EPSF-3.0 %%BoundingBox: 0 0 720 720 %%HiResBoundingBox: 0 0 720 720 %%CropBox: 0 0 720 720 %%Title:N角形に対角線 %%Creator:Studio Fruit Jam / Toyokazu Nishi %%Copyright:Studio Fruit Jam / Toyokazu Nishi %%CreationDate:2016年10月29日土曜日19:09:33 %%ModificationDate:2018年5月20日 日曜日17:14:19 %%ModificationDate:2018年8月7日 火曜日午後3:28:35 % ================ 座標変換 ================ 360 dup translate 1 dup scale % ================ 背景 ================= .917 .917 .863 setrgbcolor -360 360 720 -720 rectfill % ====================== 初期値 1 setlinewidth % 線幅を1ポイントにする /n 8 def % N角形 (変更可・整数3〜) /r 300 def % 大きさ(変更可) /rd 20 def % 頂点の円の半径(変更可) /tha 360 n div def % N角形の角度 % N角形が奇数の時、図形の角度を補正して左右対称になるようにする n 2 mod 0 eq { /rot 0 def } { % 偶数の時は何もしない n 4 mod 1 eq { /rot 90 n div def } % 奇数5,9,13...は倒立するため補正する { /rot 90 n div neg def } ifelse } ifelse % 奇数3,7,11...の補正 % ================================================ % メイン % ================================================ newpath % パスの初期化 % ====================== 多角形 rot rotate 0 0 0 setrgbcolor 1 1 n { /j exch def /th tha j mul def % N角形の角度計算 /x r th cos mul def % 円の公式 /y r th sin mul def % 円の公式 j 1 eq { x y moveto } { x y lineto } ifelse } for closepath stroke % ====================== 対角線 1 1 n { /j exch def /th tha j mul def /x r th cos mul def /y r th sin mul def 0 0 moveto x y lineto } for stroke % ====================== 頂点 1 0 0 setrgbcolor 1 1 n { /j exch def /th tha j mul def /x r th cos mul def /y r th sin mul def x y rd 0 360 arc j 1 eq { rd 0 moveto 0 0 rd 0 360 arc } if fill } for |
コメント
コメント一覧 (15件)