Changes

Jump to navigation Jump to search
571 bytes added ,  21:33, 2 August 2019
better code
< [[MetaPost]] | [[Overlays]] >
 
So you’d like to have one of these nice drop shadows behind some object? Here’s a piece of code to play with:
<texcode>
\startuniqueMPgraphic{mpshadow}
% these values are good for small text boxesBodyFontSize should be the current font size of/in the framemw := BodyFontSize/3;ox := -0 .5 ; % offset xoy := -0 .5 ; % offset ybx := 10 1.5mw ; % bleed x(height of the shadow)by := 0 1.5mw ; % bleed y(width of the shadow)rx := 5 3mw ; % max. corner radius xry := 5 2mw ; % max. corner radius ysteps := 10 ; % number of shadow layers, 10 is a good valuehue := 0.015 ; % 0.02 is a good valueycorr := 1mw ; % difference between overlay height and shadow height
for dx step = 0 1 upto 10steps:   part := (step-1)/steps; xstep := bx * part ; % current part of bleed ystep := by * part ; crx := (rx + rx*part)/2; % use more iterations for bigger boxescurrent radius dy cry := dx (ry + ry*part)/2 % points of the rounded rectangle xa := dx -xstep + ox ; xb := - bx/2xstep + ox + crx; xb xc := xstep + ox - crx + \overlaywidth - dx ; xd := xstep + ox + bx/2\overlaywidth; ya := dy -ystep + ycorr + oy ; yb := - by/2ystep + ycorr + oy + cry; yb yc := ystep - ycorr + oy - cry + \overlayheight ; yd := ystep - dy ycorr + oy + by/2\overlayheight;  fill (xb, ya)--- (xc, ya)... (xd, yb)--- (xd, yc)... (xc, yd)--- (xb, yd)... (xa, yc)--- (xa, yb)...cycle withcolor transparent(1, hue, black) ;
% rounded rectangle
fill (xa, ya + ry)---
(xa, yb - ry)..
(xa + rx, yb)---
(xb - rx, yb)..
(xb, yb - ry)---
(xb, ya + ry)..
(xb - rx, ya)---
(xa + rx, ya)..cycle
withcolor transparent(1, .04, black) ;
endfor;
 
setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic

Navigation menu