%&plain % bake-oven.mp -- draw Bake logo % (C) 2004 Bertram Scharpf % This is free software; see the source for copying conditions. % There is NO warranty; not even for MERCHANTABILITY or FITNESS % FOR A PARTICULAR PURPOSE. % License: GPL. See for details. % Build and view example: % % mpost bake-oven.mp % gs -dNOPAUSE -sDEVICE=bmp256 -sOutputFile=bake-oven.bmp -r360x360 \ % -f bake-oven.1 -c quit % display bake-oven.bmp % % The option `-r360x360' makes one point to come out as 5x5 pixels. % That means, a vector of length 72 will be 360 pixels long and an % image of size 192x192 will have 9600x9600 pixels. % sqrf:=5**.5; phi:=(-1+sqrf)/2; % ~ 0,618 -- the golden section pair paper; paper:=(192,192); % paper size special "<< /PageSize [ " & decimal xpart paper & " " & decimal ypart paper & " ] >> setpagedevice"; % object proberties brick.w:=16; % width brick.h:=8; % height brick.d:=32; % depth brick.j:=2; % joint brick.wj=brick.w+brick.j; brick.hj=brick.h+brick.j; brick.dj=brick.d+brick.j; color brick.col, brick.jcol; brick.col:=blue; brick.jcol:=1white; inside.h:=1.5brick.hj; color inside.col, inside.gcol; inside.col:=0white; inside.gcol:=1white; path cake[]; pair cake[]dim; color cake[]col; cake1dim:=(1.1brick.w,1.4brick.h); cake1:=(-xpart cake1dim,0)---(xpart cake1dim,0).. (xpart cake1dim,ypart cake1dim)..(-xpart cake1dim,ypart cake1dim)..cycle; cake1col:=blue+green; cake2dim:=(1.1brick.w,1.6brick.h); cake2spr:=1.3; cake2dnt:=0.7; cake2:=(-xpart cake2dim,0)--(xpart cake2dim,0)-- (cake2spr * xpart cake2dim,ypart cake2dim)..(0,cake2dnt*ypart cake2dim).. (cake2spr * -xpart cake2dim,ypart cake2dim)--cycle; cake2col:=blue+red; pair base; base:=(.5 xpart paper, round( (1-phi)*ypart paper - inside.h)); % routines for drawing bricks def rect( expr w, h, ang, p) = begingroup save mhw, phw, r; mhw:=-w/2; phw:=mhw+w; path r; r:=(mhw,0)--(phw,0)--(phw,h)--(mhw,h)--cycle; r rotated ang shifted p endgroup enddef; def border( expr w, h, ang, p) = begingroup save mhw, phw, r; mhw:=-w/2; phw:=mhw+w; j:=brick.j/2; path r, ro, ri; ro:=(mhw-j,0-j)--(phw+j,-j)--(phw+j,h+j)--(mhw-j,h+j)--cycle; ri:=(mhw,0)--(phw,0)--(phw,h)--(mhw,h)--cycle; r:=ro--ri--cycle; r rotated ang shifted p endgroup enddef; def drawbrick( expr w, h, ang, p) = fill border( w, h, ang, p) withcolor brick.jcol; fill rect( w, h, ang, p) withcolor brick.col; enddef; def preveven( expr q) = begingroup save f; f = floor( q); if odd f: f - 1 else: f fi endgroup enddef; def brickarc( expr mid, rad, open) = begingroup save hst, st; hst:= angle (rad, brick.h/2 + (brick.j/2)/4.0); st:=2hst; save op, sp; op:=open+hst; sp:=180-2*op; st:= sp / preveven( sp/st); uop:=180-op+hst-epsilon; jrad.m:=rad-brick.j/2; jrad.p:=rad+brick.j/2+brick.w; fill for ang = op-st/2 step st until uop+st/2: (mid + jrad.m * dir ang)-- endfor for ang = 180-op+st/2 step -st until op-st/2-hst+epsilon: (mid + jrad.p * dir ang)-- endfor cycle withcolor brick.jcol; for ang = op step st until uop: fill rect( brick.h, brick.w, ang-90, mid + rad * dir ang) withcolor brick.col; endfor endgroup enddef; % draw the oven beginfig( 1) hwidth:=brick.hj*8-brick.wj; % half width sideh:=4brick.hj; arch:=2.5brick.hj; def switchshift = shift:=if shift <> 0: 0 else: brick.dj/2 fi; enddef; shift:=0; for i = -brick.wj-4brick.hj step brick.hj until 15brick.hj: for j = -3*brick.dj-shift step brick.dj until +4brick.dj: drawbrick( brick.d, brick.h, -180, base + (j,i)); endfor switchshift; endfor hbhj:=brick.hj/2; for i = hbhj step brick.hj until hwidth+brick.w+hbhj-epsilon: drawbrick( brick.h, brick.w, -180, base + (-i, 0)); drawbrick( brick.h, brick.w, -180, base + (+i, 0)); endfor for i = brick.h/2 +brick.j step brick.hj until sideh + 2brick.hj: drawbrick( brick.h, brick.w, +90, base + (-hwidth, i)); drawbrick( brick.h, brick.w, -90, base + (+hwidth, i)); endfor rad:=(hwidth*hwidth + arch*arch)/(2arch); pair arcmid; arcmid:=(0,sideh+arch-rad); vardef testopen(expr phi)=rad*cosd phi>hwidth enddef; tolerance:=epsilon; open:= solve testopen(0,90); brickarc( base + arcmid, rad, open); brickarc( base + arcmid, rad + brick.wj, open); fill ((-hwidth,0)--(+hwidth,0)--(+hwidth,sideh).. (0,sideh+arch)..(-hwidth,sideh)--cycle) shifted base withcolor inside.col; pickup pensquare; top ih = inside.h; lft lg = -hwidth; rt rg = +hwidth; draw ((lg,ih)--(rg,ih)) shifted base withcolor inside.gcol; fill cake1 shifted (base + (-hwidth/sqrf,inside.h)) withcolor cake1col; fill cake2 shifted (base + (+hwidth/sqrf,inside.h)) withcolor cake2col; endfig; bye;