| 1 |
.PS |
| 2 |
# EscherDPV.m4 |
| 3 |
# https://tex.stackexchange.com/questions/129274/showcase-of-optical-illusions-made-with-tex-latex-luatex-context |
| 4 |
threeD_init |
| 5 |
[] |
| 6 |
ifelse(1,1,` |
| 7 |
[ |
| 8 |
u=1/2.54 # unit size; could use scale for this |
| 9 |
|
| 10 |
define(`treadcolor',`0.8,0.75,0.7') |
| 11 |
define(`darkgrn',`.1,.1,0') |
| 12 |
define(`lightgrn',`.7,.7,.6') |
| 13 |
|
| 14 |
define(`northsteps',3) |
| 15 |
define(`eaststeps',8) |
| 16 |
define(`southsteps',7) |
| 17 |
define(`weststeps',4) |
| 18 |
define(`baselayers',10) |
| 19 |
define(`eb',eval(baselayers+eaststeps)) |
| 20 |
define(`ebs',eval(eb+southsteps)) |
| 21 |
define(`under',7) |
| 22 |
|
| 23 |
azimuth = -45 # view angles |
| 24 |
elevation = 25 |
| 25 |
setview(azimuth,elevation,0) |
| 26 |
# projected unit vectors |
| 27 |
UX: Project(u,0,0) |
| 28 |
UY: Project(0,-u,0) |
| 29 |
UZ: Project(0,0,u) |
| 30 |
# layer thickness in units of u |
| 31 |
f= -(eaststeps*UX.y + southsteps*UY.y - weststeps*UX.y - northsteps*UY.y)/dnl |
| 32 |
((eaststeps+southsteps+weststeps+northsteps)*UZ.y) |
| 33 |
# XY projection of 3D coords in units of u |
| 34 |
define proj {UX*($1)+UY*($2)+UZ*($3)} |
| 35 |
|
| 36 |
define tread {line from UY/2 \ |
| 37 |
to UY then to UY+UX then to UX then to (0,0) \ |
| 38 |
then to UY/2 shaded rgbstring(treadcolor) \ |
| 39 |
with .start at proj($1,$2,$3)+UY/2 } |
| 40 |
|
| 41 |
define wrect {line invis from (0,0) to UX*($4) \ |
| 42 |
then to UX*($4)+UZ*($5) \ |
| 43 |
then to UZ*($5) then to (0,0) with .start at proj($1,$2,$3) \ |
| 44 |
shaded rgbstring(r,g,b)} |
| 45 |
|
| 46 |
define srect {line invis from (0,0) to UY*($4) then to UY*($4)+UZ*($5) \ |
| 47 |
then to UZ*($5) then to (0,0) with .start at proj($1,$2,$3) \ |
| 48 |
shaded rgbstring(r,g,b) } |
| 49 |
# color blending |
| 50 |
define(`blendwht',`between3D(`$1',`$2',`$3',`$4',1,1,1)') |
| 51 |
define makergb { r = $1; g = $2; b = $3 } |
| 52 |
define dorgb { gg = $2 |
| 53 |
if $1==0 then { makergb(blendwht(gg,lightgrn)) } \ |
| 54 |
else { makergb(blendwht(gg,darkgrn)) } } |
| 55 |
|
| 56 |
# East |
| 57 |
for i=-under to baselayers do { |
| 58 |
dorgb((i%2),0.2) |
| 59 |
wrect(1,1,i*f,eaststeps-2,-f) } |
| 60 |
for i=0 to eaststeps do { |
| 61 |
dorgb((i%2),0.2) |
| 62 |
wrect(i,1,(baselayers+i)*f,(eaststeps+1-i),-f) |
| 63 |
tread(i,0,(baselayers+i)*f) |
| 64 |
line from proj(i,1,(baselayers+i)*f) \ |
| 65 |
to proj(i,1,(baselayers-1+i)*f) } |
| 66 |
# South |
| 67 |
for i=0 to eb do { |
| 68 |
dorgb((i%2),0.4) |
| 69 |
srect(eaststeps+1,0,i*f,southsteps+1,-f) } |
| 70 |
for i=1 to southsteps do { |
| 71 |
dorgb((i%2),0.4) |
| 72 |
srect(eaststeps+1,i,(eb+i)*f,(southsteps+1-i),-f) |
| 73 |
tread(eaststeps,i,(eb+i)*f) |
| 74 |
line from proj(eaststeps+1,i,(eb+i)*f) \ |
| 75 |
to proj(eaststeps+1,i,(eb+i-1)*f) } |
| 76 |
# North |
| 77 |
for i=-under to baselayers-northsteps-1 do { |
| 78 |
dorgb((i%2),0.1) |
| 79 |
srect(1,1,i*f,northsteps-1,-f) } |
| 80 |
for i=1 to northsteps do { |
| 81 |
dorgb((i%2),0.1) |
| 82 |
srect(1,1,(baselayers-i)*f,i,-f) |
| 83 |
wrect(0,1+i,(baselayers-i)*f,1,-f) |
| 84 |
line from proj(0,1+i,(baselayers-i)*f) \ |
| 85 |
to proj(0,1+i,(baselayers-i-1)*f) |
| 86 |
line from proj(1,1+i,(baselayers-i)*f) \ |
| 87 |
to proj(1,1+i,(baselayers-i-1)*f) |
| 88 |
tread(0,i,(baselayers-i)*f) } |
| 89 |
# West |
| 90 |
for i=0 to ebs do { |
| 91 |
dorgb((i%2),0.4) |
| 92 |
wrect(eaststeps+1,southsteps+1,i*f,-(weststeps+1),-f) } |
| 93 |
for i=0 to weststeps-1 do { |
| 94 |
dorgb((i%2),0.4) |
| 95 |
wrect(eaststeps-i,southsteps+1,(ebs+i+1)*f,-(weststeps-i),-f,) |
| 96 |
srect(eaststeps-i,southsteps,(ebs+i+1)*f,1,-f) |
| 97 |
if i!=weststeps-1 then { |
| 98 |
line from proj(eaststeps-i,southsteps,(ebs+i+1)*f) \ |
| 99 |
to proj(eaststeps-i,southsteps,(ebs+i)*f) } |
| 100 |
line from proj(eaststeps-i,southsteps+1,(ebs+i+1)*f) \ |
| 101 |
to proj(eaststeps-i,southsteps+1,(ebs+i)*f) |
| 102 |
tread(eaststeps-(i+1),southsteps,(ebs+i+1)*f) } |
| 103 |
# Corner lines |
| 104 |
define(`dgreen',`outlined rgbstring(blendwht(0.2,darkgrn))') |
| 105 |
line dgreen from proj(1,1,(baselayers-1)*f) to proj(1,1,-under*f) |
| 106 |
line dgreen from proj(eaststeps+1,southsteps+1,ebs*f) \ |
| 107 |
to proj(eaststeps+1,southsteps+1,-f) |
| 108 |
line dgreen from proj(0,northsteps+1,(baselayers-northsteps)*f) \ |
| 109 |
to last line.end-UX*(weststeps+1) then to last line.end \ |
| 110 |
then to proj(eaststeps+1,0,-f) then to proj(eaststeps+1,0,eb*f) |
| 111 |
] |
| 112 |
') |
| 113 |
|
| 114 |
ifelse(1,1,` |
| 115 |
define(`DPL',`(project(`$1',`$2',`$3'))') |
| 116 |
define(`ISL',` |
| 117 |
S1: `$2'; E1: `$2' + `$3' |
| 118 |
S2: `$4'; E2: `$4' + `$5' |
| 119 |
`$1': line from S2 to intersect_(S1,E1,S2,E2) ') |
| 120 |
|
| 121 |
[ |
| 122 |
bdp = 1.8 |
| 123 |
bwd = 2.8 |
| 124 |
bht = 1.5 |
| 125 |
bth = bwd/10 |
| 126 |
setview(-45,20,0) |
| 127 |
|
| 128 |
L1: line from DPL(0,0,0) to DPL(0,0,bht) \ |
| 129 |
then to DPL(0,bwd,bht) \ |
| 130 |
then to DPL(bdp,bwd,bht) \ |
| 131 |
then to DPL(bdp,bwd,0) \ |
| 132 |
then to DPL(bdp,0,0) \ |
| 133 |
then to DPL(0,0,0) |
| 134 |
L2: line from DPL(bth,bth,bht) to DPL(bth,bwd-bth,bht) \ |
| 135 |
then to DPL(bdp-bth,bwd-bth,bht) \ |
| 136 |
then to DPL(bdp-bth,bth,bht) \ |
| 137 |
then to DPL(bth,bth,bht) |
| 138 |
L3: line from DPL(bth,bth,0) to DPL(bth,bwd-bth,0) \ |
| 139 |
then to DPL(bdp-bth,bwd-bth,0) \ |
| 140 |
then to DPL(bdp-bth,bth,0) \ |
| 141 |
then to DPL(bth,bth,0) |
| 142 |
L4: line from DPL(bdp,bth,bht-bth) to DPL(bdp,bwd-bth,bht-bth) \ |
| 143 |
then to DPL(bdp,bwd-bth,bth) \ |
| 144 |
then to DPL(bth+bth,bwd-bth,bth) |
| 145 |
L5: line from DPL(bdp-bth,0,bht-bth) to DPL(bth,0,bht-bth) \ |
| 146 |
then to DPL(bth,0,bth) \ |
| 147 |
then to DPL(bth,bwd-bth-bth,bth) |
| 148 |
L6: line from DPL(0,0,bht) to DPL(bdp,0,bht) \ |
| 149 |
then to DPL(bdp,bwd,bht) |
| 150 |
L7: line from DPL(0,0,0) to DPL(0,bwd,0) \ |
| 151 |
then to DPL(bdp,bwd,0) |
| 152 |
ISL(L8,L4.start,UPy_,L4.end,UPz_) |
| 153 |
ISL(L9,L4.start,UPy_,DPL(0,bwd,0),UPz_) |
| 154 |
ISL(L10,L4.start,UPy_,L5.end,UPz_) |
| 155 |
ISL(L11,L5.end,UPy_,L4.start,UPz_) |
| 156 |
ISL(L12,L5.end,UPy_,DPL(bdp,0,bht),UPz_) |
| 157 |
ISL(L13,L5.end,UPy_,L5.start,UPz_) |
| 158 |
ISL(L14,DPL(bdp-bth,bth,bht),UPy_,DPL(bth,bwd-bth-bth,bht-bth),UPz_) |
| 159 |
ISL(L15,L2.start,UPx_,DPL(bth,bwd-bth-bth,bht-bth),UPy_) |
| 160 |
ISL(L16,DPL(bdp-bth,bth,bht),UPy_,DPL(bth,bwd-bth,bht),UPz_) |
| 161 |
ISL(L17,DPL(bdp-bth,bth,bht),UPy_,DPL(bth+bth,bwd-bth,bht-bth),UPz_) |
| 162 |
ISL(L18,DPL(bdp-bth,bth,bht),UPy_,DPL(bth+bth,bwd-bth,bht-bth),UPx_) |
| 163 |
ISL(L19,L3.start,UPy_,L5.start+DPL(0,0,-bht+bth+bth),UPx_) |
| 164 |
ISL(L20,L3.start,UPy_,L5.start+DPL(0,0,-bht+bth+bth),UPz_) |
| 165 |
ISL(L21,L3.start,UPy_,DPL(bdp-bth,bth,0),UPz_) |
| 166 |
ISL(L22,L3.start,UPy_,L4.start+DPL(0,0,-bht+bth+bth),UPz_) |
| 167 |
ISL(L23,DPL(bth,bwd-bth,0),UPx_,L4.start+DPL(0,0,-bht+bth+bth),UPy_) |
| 168 |
ISL(L24,L5.start,UPx_,DPL(bth,bth,bth),UPz_) |
| 169 |
ISL(L25,L4.start,UPy_,DPL(bdp-bth,bwd-bth,bth),UPz_) |
| 170 |
|
| 171 |
ifelse(0,1,`for i=1 to 7 do { exec sprintf("\"L%g.s\" at L%g.start",i,i) } |
| 172 |
for i=8 to 10 do { exec sprintf("\"L%g\" at L%g",i,i) }') |
| 173 |
] with .sw at last [].se+(0.2,0) |
| 174 |
') |
| 175 |
.PE |