luametafun-poisson.tex /size: 3729 b    last modification: 2025-02-21 11:03
1% language=us runpath=texruns:manuals/luametafun
2
3\environment luametafun-style
4
5\startcomponent luametafun-poisson
6
7\startchapter[title={Poisson}]
8
9When, after a post on the \CONTEXT\ mailing list, Aditya pointed me to an article
10on mazes I ended up at poisson distributions which to me looks nicer than what I
11normally do, fill a grid and then randomize the resulting positions. With some
12hooks this can be used for interesting patterns too. The algorithm is based on
13the discussion at:
14
15\starttyping
16http://devmag.org.za/2009/05/03/poisson-disk-sampling
17\stoptyping
18
19Other websites mention some variants on that but I saw no reason to look into
20those in detail. I can imagine more random related variants in this domain so
21consider this an appetizer. The user is rather simple because some macro is
22assumed to deal with the rendering of the distributed points. We just show some
23examples (because the interface might evolve).
24
25\startbuffer
26\startMPcode
27    draw lmt_poisson [
28        width    = 40,
29        height   = 40,
30        distance =  1,
31        count    = 20,
32        macro    = "draw"
33    ] xsized 4cm ;
34\stopMPcode
35\stopbuffer
36
37\typebuffer[option=TEX]
38
39\startlinecorrection
40    \getbuffer
41\stoplinecorrection
42
43\startbuffer
44\startMPcode
45    vardef tst (expr x, y, i, n) =
46        fill fullcircle scaled (10+10*(i/n)) shifted (10x,10y)
47            withcolor "darkblue" withtransparency (1,.5) ;
48    enddef ;
49
50    draw lmt_poisson [
51        width     = 50,
52        height    = 50,
53        distance  =  1,
54        count     = 20,
55        macro     = "tst",
56        arguments =  4
57    ] xsized 6cm ;
58\stopMPcode
59\stopbuffer
60
61\typebuffer[option=TEX]
62
63\startlinecorrection
64    \getbuffer
65\stoplinecorrection
66
67\startbuffer
68\startMPcode
69    vardef tst (expr x, y, i, n) =
70        fill fulldiamond scaled (5+5*(i/n)) randomized 2 shifted (10x,10y)
71            withcolor "darkgreen" ;
72    enddef ;
73
74    draw lmt_poisson [
75        width     = 50,
76        height    = 50,
77        distance  =  1,
78        count     = 20,
79        macro     = "tst",
80        initialx  = 10,
81        initialy  = 10,
82        arguments =  4
83    ] xsized 6cm ;
84\stopMPcode
85\stopbuffer
86
87\typebuffer[option=TEX]
88
89\startlinecorrection
90    \getbuffer
91\stoplinecorrection
92
93\startbuffer
94\startMPcode{doublefun}
95    vardef tst (expr x, y, i, n) =
96        fill fulldiamond randomized (.2*i/n) shifted (x,y);
97    enddef ;
98
99    draw lmt_poisson [
100        width     = 150,
101        height    = 150,
102        distance  =   1,
103        count     =  20,
104        macro     = "tst",
105        arguments =   4
106    ] xsized 6cm withcolor "darkmagenta" ;
107\stopMPcode
108\stopbuffer
109
110\typebuffer[option=TEX]
111
112\startlinecorrection
113    \getbuffer
114\stoplinecorrection
115
116\startbuffer
117\startMPcode
118    vardef tst (expr x, y, i, n) =
119        draw externalfigure "cow.pdf" ysized (10+5*i/n) shifted (10x,10y);
120    enddef ;
121    draw lmt_poisson [
122        width     = 20,
123        height    = 20,
124        distance  =  1,
125        count     = 20,
126        macro     = "tst"
127        arguments = 4,
128    ] xsized 6cm ;
129\stopMPcode
130\stopbuffer
131
132\typebuffer[option=TEX]
133
134\startlinecorrection
135    \getbuffer
136\stoplinecorrection
137
138The supported parameters are:
139
140\starttabulate[|T|T|T|p|]
141\FL
142\BC name      \BC type    \BC default \BC comment \NC \NR
143\ML
144\NC width     \NC numeric \NC 50      \NC \NC \NR
145\NC height    \NC numeric \NC 50      \NC \NC \NR
146\NC distance  \NC numeric \NC  1      \NC \NC \NR
147\NC count     \NC numeric \NC 20      \NC \NC \NR
148\NC macro     \NC string  \NC "draw"  \NC \NC \NR
149\NC initialx  \NC numeric \NC 10      \NC \NC \NR
150\NC initialy  \NC numeric \NC 10      \NC \NC \NR
151\NC arguments \NC numeric \NC  4      \NC \NC \NR
152\LL
153\stoptabulate
154
155\stopchapter
156
157\stopcomponent
158
159