---------- Forwarded message ---------
De: Jairo A. del Rio
Hi Jairo,
thank you for the suggestion.
Am 11.05.2021 um 14:56 schrieb Jairo A. del Rio
For simple pens, you may define your own (section 9.7 of MetaPost manual).
Unfortunately, pens don’t work as patterns but only as outlines.
For complicated strokes, something along these lines could be useful as a starting point (I'm not taking cyclic paths in consideration, btw). I did something similar with duck footprints some weeks ago:
%Sorry for the ugly code... \starttext \startMPpage %Unit size numeric u; u := 1mm;
%In a picture you are able to include everything, kinda picture Pluma; Pluma := image( for i = 1 upto 5: for j = 1 upto 5: draw (i,j) randomized 1; endfor endfor );
Unfortunately, that’s the same pattern over and over. The randomization is only applied once. Good for footprints, bad for fuzzy patterns.
You only need to move "randomized" at the drawing stage: \starttext \startMPpage numeric u; u := 1mm; picture Pluma; Pluma := image( for i = 1 upto 5: for j = 1 upto 5: draw (i,j); endfor endfor ); path Camino; Camino := origin for i = 1 upto 30: .. (u*i, u*sind (12i mod 360)) endfor; for i = 0 step 1/2 until length Camino: draw Pluma randomized 1 rotated (90 + angle direction i of Camino) shifted point i of Camino; endfor \stopMPpage \stoptext But "randomized" will deform paths. Maybe you want something like this? \starttext \startMPpage[align=] begingroup; save Rnd; let Rnd = uniformdeviate; numeric u; u := 3mm; picture Pluma; Pluma := image( for i = 1 upto 5: for j = 1 upto 5: fill fullcircle shifted (i,j); %try fulltriangle or another shape endfor endfor ); path Camino; Camino := origin for i = 1 upto 30: .. u*i*left endfor; for i = 0 step 1/2 until length Camino: draw image( for x within Pluma: fill pathpart x %Assuming our image only contains cyclic paths scaled (1+Rnd 1) shifted (1/2dir Rnd 360) withcolor hsvtorgb(6round(Rnd 60),9/10,1); %Colors just because they look cute endfor ) rotated (90 + angle direction i of Camino) shifted point i of Camino; endfor endgroup; \stopMPpage \stoptext
%Simple curve
path Camino; Camino := origin for i = 1 upto 30: .. (u*i, u*sind (12i mod 360)) endfor;
%Strokes for i = 0 step 1/2 until length Camino: draw Pluma rotated (90 + angle direction i of Camino) shifted point i of Camino; endfor
Since I have more or less straight lines but of different length, the "one pattern per 1/n path segment" doesn’t work for me. I could try to construct my paths differently.
You only need to use fractions, i.e., "for 0 step 1/n until 1: ... endfor" if you work with straight lines defined using only two points. In the example above I made one from more than two points just for ease of manipulation. With examples and feedback from the mailing list, you might define your own function using the new Metafun interface for LMTX.
Hraban
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Jairo
Am 12.05.2021 um 23:21 schrieb Jairo A. del Rio
: Unfortunately, that’s the same pattern over and over. The randomization is only applied once. Good for footprints, bad for fuzzy patterns.
You only need to move "randomized" at the drawing stage:
\starttext \startMPpage numeric u; u := 1mm; picture Pluma; Pluma := image( for i = 1 upto 5: for j = 1 upto 5: draw (i,j); endfor endfor );
I made it into: picture NoisePattern; NoisePattern := image( pickup pencircle xyscaled 0.5bp; numeric pmax ; pmax := 7 ; for i = 1 upto pmax: for j = 1 upto pmax: draw (i - (pmax/2), j - (pmax/2)) withcolor LineColor withtransparency ("normal", (uniformdeviate 0.33)); endfor endfor ); Now the noise is randomly transparent and also on (and not over) the path.
path Camino; Camino := origin for i = 1 upto 30: .. (u*i, u*sind (12i mod 360)) endfor; for i = 0 step 1/2 until length Camino: draw Pluma randomized 1 rotated (90 + angle direction i of Camino) shifted point i of Camino; endfor
And that became: def noisify(expr p) = for i = 0 step 0.01 until length p: draw NoisePattern randomized 1 shifted point i of p ; endfor enddef; I still need to account for the length of the path in the loop step.
But "randomized" will deform paths. Maybe you want something like this?
\starttext \startMPpage[align=] begingroup; save Rnd; let Rnd = uniformdeviate;
numeric u; u := 3mm; picture Pluma; Pluma := image( for i = 1 upto 5: for j = 1 upto 5: fill fullcircle shifted (i,j); %try fulltriangle or another shape endfor endfor ); path Camino; Camino := origin for i = 1 upto 30: .. u*i*left endfor; for i = 0 step 1/2 until length Camino: draw image( for x within Pluma: fill pathpart x %Assuming our image only contains cyclic paths scaled (1+Rnd 1) shifted (1/2dir Rnd 360) withcolor hsvtorgb(6round(Rnd 60),9/10,1); %Colors just because they look cute endfor ) rotated (90 + angle direction i of Camino) shifted point i of Camino; endfor endgroup; \stopMPpage \stoptext
Since I have more or less straight lines but of different length, the "one pattern per 1/n path segment" doesn’t work for me. I could try to construct my paths differently. You only need to use fractions, i.e., "for 0 step 1/n until 1: ... endfor" if you work with straight lines defined using only two points.
Yes, I got that. But a fixed number (e.g. step 0.01 like above) doesn’t account for paths of different length. I guess I’d need an algorithm like for dashed lines to get uniform noise on paths of different length. (I also looked at dashpattern in the MP manual, but they’re not usable for patterns like this.) Hraban
participants (2)
-
Henning Hraban Ramm
-
Jairo A. del Rio