| 1 |
.PS |
| 2 |
# Shaky.m4 |
| 3 |
gen_init |
| 4 |
NeedDpicTools |
| 5 |
divert(-1) |
| 6 |
`An attempt to draw shaky hand-drawn lines' |
| 7 |
|
| 8 |
`shakyline(linespec,type,shake=val,[shakevals]) |
| 9 |
Draw a line with a tremor |
| 10 |
arg3: shake parameter (default 1) |
| 11 |
arg4=normal(0,1) perturbations used if given' |
| 12 |
define(`shakyline', |
| 13 |
`rpoint_(ifelse(`$1',,`to rvec_(linewid,0)',`$1')) |
| 14 |
L_start_: last line.start |
| 15 |
L_end_: last line.end |
| 16 |
[ Start: L_start_ |
| 17 |
End: L_end_ |
| 18 |
llen = distance(Start,End) |
| 19 |
npts = round_(llen/linewid*4) |
| 20 |
pushkey_(`$3',shake,1)dnl |
| 21 |
sval = m4shake*llen/npts/8 |
| 22 |
if "$4"=="" then { randn(d,npts-1,0,sval) }\ |
| 23 |
else { for i=1 to npts-1 do { d[i] = $4[i]*sval) }} |
| 24 |
P[0]: Start |
| 25 |
for i=1 to npts-1 do { P[i]: i/npts between Start and End + vec_(0,d[i]) } |
| 26 |
P[npts]: End |
| 27 |
spline ifdpic(ifelse(`$2',,ctension_)) $2 from P[0] to P[1] |
| 28 |
for i=2 to npts do { continue to P[i] } popdef(`m4shake') |
| 29 |
] with .Start at L_start_; move to L_end_') |
| 30 |
|
| 31 |
`shakyarc(arcspec,type,shake=val,[shakevals]) |
| 32 |
Draw an arc with a tremor |
| 33 |
arg3: s=shake parameter (default 1) |
| 34 |
arg4=normal(0,1) perturbations used if given' |
| 35 |
define(`shakyarc', |
| 36 |
`arc invis $1 |
| 37 |
A_start_: last arc.start |
| 38 |
A_end_: last arc.end |
| 39 |
A_C_: last arc.c |
| 40 |
[ Start: A_start_ |
| 41 |
End: A_end_ |
| 42 |
C: A_C_ |
| 43 |
as = atan2(Start.y-C.y,Start.x-C.x) |
| 44 |
ae = atan2(End.y-C.y,End.x-C.x) |
| 45 |
ar = distance(Start,C) |
| 46 |
llen = abs(ar*(ae-as)) |
| 47 |
npts = round_(llen/linewid*4) |
| 48 |
pushkey_($3,shake,1)dnl |
| 49 |
sval = m4shake*llen/npts/8 |
| 50 |
if "$4"=="" then { randn(d,npts-1,0,sval) }\ |
| 51 |
else { for i=1 to npts-1 do { d[i] = $4[i]*sval }} |
| 52 |
P[0]: Start |
| 53 |
for i=1 to npts-1 do { P[i]: C + (rect_(ar+d[i],as+i/npts*(ae-as))) } |
| 54 |
P[npts]: End |
| 55 |
spline ifdpic(ifelse(`$2',,ctension_)) $2 from P[0] to P[1] |
| 56 |
for i=2 to npts do { continue to P[i] } popdef(`m4shake') |
| 57 |
] with .Start at last arc.start; move to last arc.end') |
| 58 |
|
| 59 |
`shakyfitcurve(V,n,linetype, |
| 60 |
m (default 0),shake=val,[shakevals]) |
| 61 |
Like fitcurve but the control points |
| 62 |
are perturbed |
| 63 |
arg5: s=shake parameter (default 1) |
| 64 |
arg6=normal(0,1) perturbations used if given' |
| 65 |
define(`shakyfitcurve',` |
| 66 |
[ m4fn = ifelse(`$2',,2,`$2'); m4fm = ifelse(`$4',,0,`$4') |
| 67 |
pushkey_($5,shake,1)dnl |
| 68 |
if "$6"=="" then { randn(d,2*(m4fn-m4fm-1),0,m4shake) }\ |
| 69 |
else { for i=1 to 2*(m4fn-m4fm-1) do { d[i] = $6[i]*m4shake }} |
| 70 |
M4PP_[0]: `$1'[m4fm] |
| 71 |
for i=m4fm+1 to m4fn-1 do { M4PP_[i-m4fm]: `$1'[i] dnl |
| 72 |
+(d[2*(i-m4fm-1)+1],d[2*(i-m4fm-1)+2])\ |
| 73 |
*distance(M4PP_[i-m4fm-1],`$1'[i])/16 } |
| 74 |
M4PP_[m4fn-m4fm]: `$1'[m4fn]; End: M4PP_[m4fn-m4fm] |
| 75 |
fitcurve(M4PP_,m4fn-m4fm) popdef(`m4shake') |
| 76 |
] with .M4PP_[0] at `$1'[ifelse(`$4',,0,`$4')]; move to last [].End ') |
| 77 |
|
| 78 |
|
| 79 |
divert(0) |
| 80 |
|
| 81 |
P1: [ |
| 82 |
linethick = 2.5 |
| 83 |
round(,,colored "gray") |
| 84 |
nl = 10 |
| 85 |
for i=0 to nl do { |
| 86 |
shakyline(right 6/nl up 2*(2*pmod(i,2)-1),,shake=2) |
| 87 |
{sprintf("%g",2-i/nl*2) at 1/2 between L_start_ and L_end_ } |
| 88 |
round(,,colored "gray") } |
| 89 |
] |
| 90 |
|
| 91 |
P2: [ |
| 92 |
linethick = 2.5 |
| 93 |
na = 3 |
| 94 |
arcrad = 1 |
| 95 |
for i=1 to na do { |
| 96 |
shakyarc(,colored "gray",shake=2) |
| 97 |
} |
| 98 |
] with .nw at last [].sw +(0,-1) |
| 99 |
|
| 100 |
P3: [ |
| 101 |
linethick = 2.5 |
| 102 |
na = 3 |
| 103 |
arcrad = 2 |
| 104 |
for i=1 to na do { |
| 105 |
shakyarc(,colored "gray",shake=2) |
| 106 |
} |
| 107 |
] with .w at last [].e +(1,0) |
| 108 |
P4: [ |
| 109 |
n = 0 |
| 110 |
for a=0 to 359 by 30 do { V[n]: (Rect_(1,a)); n+=1 } |
| 111 |
V[n]: V[0] |
| 112 |
shakyfitcurve(V,n,,,shake=1) |
| 113 |
] with .nw at P2.sw + (0,-0.5) |
| 114 |
|
| 115 |
.PE |