Last active
April 22, 2025 20:30
-
-
Save wojpawlik/ab51d51a81bd0d351efb06f614eb73f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%!PS-Adobe-3.0 | |
%%Creator: (Wojciech Pawlik) | |
%%BoundingBox: 0 0 600 600 | |
%%EndComments | |
%%BeginProlog | |
<< /PageSize [600 600] >> setpagedevice | |
/Helvetica-Bold findfont 20 scalefont setfont | |
300 300 translate | |
1 1 1 setrgbcolor | |
realtime srand | |
/circle { 0 360 arc } def | |
/brick {.87 .36 .15} def | |
/desert {.83 .80 .56} def | |
/grain {.96 .74 .15} def | |
/ore {.62 .62 .62} def | |
/sheep {.60 .72 .02} def | |
/water {.04 .40 .65} def | |
/wood {.07 .59 .22} def | |
/hexsize 50 .75 sqrt div def | |
/terrains [ | |
(desert) | |
(ore) dup dup | |
(brick) dup dup | |
(wood) dup dup dup | |
(grain) dup dup dup | |
(sheep) dup dup dup | |
] def | |
/fromhexpolar { | |
gsave | |
[100 0 0 100 0 0] setmatrix | |
36 add % avoids negative remainder | |
1 index 2 copy | |
idiv 60 mul rotate | |
mod exch | |
0 translate | |
120 rotate | |
0 transform | |
grestore | |
} bind def | |
/position { | |
% https://en.wikipedia.org/wiki/Centered_hexagonal_number | |
dup 3 div sqrt .5 add cvi % distance from center | |
dup 0 ne { | |
dup dup mul 3 mul | |
3 -1 roll sub | |
fromhexpolar | |
} if | |
} bind def | |
/hex { | |
1 dict begin | |
/a exch def | |
0 a moveto | |
6 { | |
60 rotate | |
0 a lineto | |
} repeat | |
closepath | |
end | |
} def | |
/number { | |
0 0 20 circle fill | |
% probability dots -- count | |
dup 7 sub abs | |
6 exch sub | |
% appearance | |
dup 5 ge {1 0 0} {0 0 0} ifelse setrgbcolor | |
[3 3] 0 setdash 3 setlinewidth | |
% probability dots -- position | |
6 mul 3 sub | |
dup -2 div -10 moveto | |
0 rlineto stroke | |
% text | |
2 string cvs | |
dup stringwidth pop -2 div | |
-3 moveto show | |
} def | |
/ppmsize { | |
dup 3 setfileposition | |
dup token pop exch | |
dup token pop exch | |
token pop pop | |
} def | |
% `--permit-file-read=sprites.ppm` | |
{ (sprites.ppm) dup (r) file def } | |
stopped {{pop}} {{ | |
1 dict begin | |
0 get 95 sub 4 idiv % hash | |
/size [ sprites.ppm ppmsize 8 idiv ] cvx def | |
size 3 mul mul mul sprites.ppm fileposition add | |
sprites.ppm exch setfileposition | |
size 8 [1.25 0 0 -1.25 0 0] sprites.ppm false 3 colorimage | |
end | |
}} ifelse | |
/sprite exch def clear | |
/port { | |
gsave | |
3 1 roll | |
position translate | |
90 add rotate | |
-11 -60 translate | |
gsave | |
dup load exec setrgbcolor | |
[1 -20 20 20] | |
dup rectfill | |
dup rectclip | |
.5 .5 scale | |
exch sprite | |
grestore rectstroke | |
grestore | |
} def | |
/swap { | |
3 dict begin | |
/i exch def | |
/j exch def | |
/array exch def | |
array i get | |
array j get | |
array exch i exch put | |
array exch j exch put | |
end | |
} def | |
% shuffle | |
terrains length -1 1 { | |
/i exch def | |
terrains i 1 sub rand i mod swap | |
} for | |
%%EndProlog | |
% border | |
gsave | |
90 rotate 300 hex | |
water setrgbcolor fill | |
grestore | |
5 2 6 3 8 10 9 12 11 4 8 10 9 4 5 6 3 11 | |
0 1 18 { | |
gsave | |
dup position translate | |
hexsize hex gsave | |
terrains exch get | |
dup load exec | |
setrgbcolor clip fill | |
-22 40 translate | |
dup sprite | |
grestore stroke | |
/sprites.ppm where { | |
0 -.375 hexsize mul translate pop | |
} if | |
(desert) ne {number} if | |
grestore | |
} for | |
% ports | |
60 rand mul rotate | |
/~3:1~ {1 1 1} def | |
180 17 (brick) port | |
240 16 (~3:1~) port | |
300 15 (~3:1~) port | |
300 13 (sheep) port | |
0 12 (~3:1~) port | |
60 11 (ore) port | |
60 9 (grain) port | |
120 8 (~3:1~) port | |
180 7 (wood) port |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%!PS-Adobe-3.0 | |
%%Creator: (Wojciech Pawlik) | |
%%BoundingBox: 0 0 595 842 | |
%%EndComments | |
<< /PageSize [595 842] >> setpagedevice % A4 | |
72 300 div setlinewidth % 300 DPI | |
% https://en.wikibooks.org/wiki/PostScript_FAQ/Programming_PostScript#How_to_concatenate_strings? | |
/flatten % [(a) (b) ... (z)] --> (ab...z) | |
{ 0 1 index { length add } forall array | |
0 3 2 roll | |
{ 3 copy putinterval | |
length add | |
} forall pop | |
} bind def | |
% https://en.wikipedia.org/wiki/Sierpiński_curve#Arrowhead_curve | |
<< | |
/A { B - A - B } | |
/B { A + B + A } | |
/- { - } | |
/+ { + } | |
>> begin | |
[ /B ] | |
{ dup length 1 sub -1 0 | |
{ 1 index exch 2 copy | |
get load put | |
} for flatten | |
} 11 exch repeat | |
end | |
<< | |
/A { currentlinewidth 0 rlineto } | |
/B { currentlinewidth 0 rlineto } | |
/- { -60 rotate } | |
/+ { 60 rotate } | |
>> begin | |
cvx dup | |
16 16 moveto exec | |
initmatrix | |
595 842 translate | |
180 rotate | |
16 16 moveto exec | |
stroke | |
end |
8 8 1 matrix (\125\252) image
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you ever feel useless, remember the desert port:
