ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Shadow around a figure
@ 2025-05-10 19:39 Jeroen
  2025-05-11 11:09 ` [NTG-context] " Keith McKay
  2025-05-11 13:13 ` Wolfgang Schuster
  0 siblings, 2 replies; 5+ messages in thread
From: Jeroen @ 2025-05-10 19:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 98 bytes --]

Is there a way with metapost to get a slightly off-centered (upper-right)
shadow around a figure?

[-- Attachment #1.2: Type: text/html, Size: 119 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Shadow around a figure
  2025-05-10 19:39 [NTG-context] Shadow around a figure Jeroen
@ 2025-05-11 11:09 ` Keith McKay
  2025-05-11 12:35   ` Jeroen
  2025-05-11 13:13 ` Wolfgang Schuster
  1 sibling, 1 reply; 5+ messages in thread
From: Keith McKay @ 2025-05-11 11:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 908 bytes --]

Have a look at this page on the wiki, and play around with it.

https://wiki.contextgarden.net/Graphics_and_media/Collections_of_tips_and_tricks/Drop_shadows_with_overlay_and_Metapost

Best Wishes
Keith

On Sat, 10 May 2025, 20:45 Jeroen, <contextntg@gmail.com> wrote:

> Is there a way with metapost to get a slightly off-centered (upper-right)
> shadow around a figure?
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 2026 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Shadow around a figure
  2025-05-11 11:09 ` [NTG-context] " Keith McKay
@ 2025-05-11 12:35   ` Jeroen
  0 siblings, 0 replies; 5+ messages in thread
From: Jeroen @ 2025-05-11 12:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 3215 bytes --]

So far I have been able to get this setup which does what I was
looking for. I just dont seem to get the "Intermezzo 1" text removed:

\useMPlibrary[dum]

\startuniqueMPgraphic{mpshadow}
% BodyFontSize should be the current font size of/in the frame
mw := BodyFontSize/3;
ox := +3.5 ; % offset x
oy := +5.5 ; % offset y
bx := 2.5mw ; % bleed x (height of the shadow)
by := 2.5mw ; % bleed y (width of the shadow)
rx := 3mw ; % max. corner radius x
ry := 2mw ; % max. corner radius y
steps := 10 ; % number of shadow layers, 10 is a good value
hue := 0.015 ; % 0.02 is a good value
ycorr := 1mw ; % difference between overlay height and shadow height

for step = 1 upto steps:

part := (step-1)/steps;
xstep := bx * part ; % current part of bleed
ystep := by * part ;
crx := (rx + rx*part)/2; % current radius
cry := (ry + ry*part)/2;

% points of the rounded rectangle
xa := -xstep + ox;
xb := -xstep + ox + crx;
xc :=  xstep + ox - crx + \overlaywidth;
xd :=  xstep + ox       + \overlaywidth;
ya := -ystep + ycorr + oy;
yb := -ystep + ycorr + oy + cry;
yc :=  ystep - ycorr + oy - cry + \overlayheight;
yd :=  ystep - ycorr + oy       + \overlayheight;

fill (xb, ya)---
(xc, ya)...
(xd, yb)---
(xd, yc)...
(xc, yd)---
(xb, yd)...
(xa, yc)---
(xa, yb)...cycle
withcolor transparent(1, hue, black) ;

endfor;

setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic

\defineoverlay[shadow][\useMPgraphic{mpshadow}]

\setupfloatframed
  [intermezzo]
  [background=shadow]

\starttext

\startplacefigure
  [title={TBA.}]
  \startplaceintermezzo
    \externalfigure
      [dummy]
      [width=.5\textwidth]
  \stopplaceintermezzo
\stopplacefigure

\stoptext

Op zo 11 mei 2025 om 13:14 schreef Keith McKay <mckaymeister@gmail.com>:

> Have a look at this page on the wiki, and play around with it.
>
>
> https://wiki.contextgarden.net/Graphics_and_media/Collections_of_tips_and_tricks/Drop_shadows_with_overlay_and_Metapost
>
> Best Wishes
> Keith
>
> On Sat, 10 May 2025, 20:45 Jeroen, <contextntg@gmail.com> wrote:
>
>> Is there a way with metapost to get a slightly off-centered (upper-right)
>> shadow around a figure?
>>
>> ___________________________________________________________________________________
>> If your question is of interest to others as well, please add an entry to
>> the Wiki!
>>
>> maillist : ntg-context@ntg.nl /
>> https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
>> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net
>> (mirror)
>> archive  : https://github.com/contextgarden/context
>> wiki     : https://wiki.contextgarden.net
>>
>> ___________________________________________________________________________________
>>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 5403 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Shadow around a figure
  2025-05-10 19:39 [NTG-context] Shadow around a figure Jeroen
  2025-05-11 11:09 ` [NTG-context] " Keith McKay
@ 2025-05-11 13:13 ` Wolfgang Schuster
  2025-05-11 14:10   ` Jeroen
  1 sibling, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2025-05-11 13:13 UTC (permalink / raw)
  To: ntg-context

Am 10.05.2025 um 21:39 schrieb Jeroen:
> Is there a way with metapost to get a slightly off-centered (upper- 
> right) shadow around a figure?

This a simple version (the \setupexternalfigures line is needed to load 
the example image because it won't wotk with dummy graphics):

\startuseMPgraphic{shadow}
   fill OverlayBox shifted (EmWidth/2,EmWidth/2) withcolor "lightgray" ;
   setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineoverlay [shadow] [\useMPgraphic{shadow}]

\setupexternalfigures[location=default]

\starttext

\externalfigure[mill]
\blank
\externalfigure[mill][background=shadow]

\stoptext

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Shadow around a figure
  2025-05-11 13:13 ` Wolfgang Schuster
@ 2025-05-11 14:10   ` Jeroen
  0 siblings, 0 replies; 5+ messages in thread
From: Jeroen @ 2025-05-11 14:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2899 bytes --]

This is the version I ended up with, seems to do exactly what I had in mind:

\startuniqueMPgraphic{mpshadow}
% BodyFontSize should be the current font size of/in the frame
mw := BodyFontSize/3;
ox := 3 ; % offset x
oy := 2 ; % offset y
bx := 1.7mw ; % bleed x (height of the shadow)
by := 3mw ; % bleed y (width of the shadow)
rx := 2mw ; % max. corner radius x
ry := 1mw ; % max. corner radius y
steps := 10 ; % number of shadow layers, 10 is a good value
hue := 0.03 ; % 0.02 is a good value
ycorr := 1mw ; % difference between overlay height and shadow height

for step = 1 upto steps:

part := (step-1)/steps;
xstep := bx * part ; % current part of bleed
ystep := by * part ;
crx := (rx + rx*part)/2; % current radius
cry := (ry + ry*part)/2;

% points of the rounded rectangle
xa := -xstep + ox;
xb := -xstep + ox + crx;
xc :=  xstep + ox - crx + \overlaywidth;
xd :=  xstep + ox       + \overlaywidth;
ya := -ystep + ycorr + oy;
yb := -ystep + ycorr + oy + cry;
yc :=  ystep - ycorr + oy - cry + \overlayheight;
yd :=  ystep - ycorr + oy       + \overlayheight;

fill (xb, ya)---
(xc, ya)...
(xd, yb)---
(xd, yc)...
(xc, yd)---
(xb, yd)...
(xa, yc)---
(xa, yb)...cycle
withcolor transparent(1, hue, black) ;

endfor;

setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic

\defineoverlay[shadow][\useMPgraphic{mpshadow}]

\setupexternalfigures[location=default]

\starttext

\startplacefigure
  [title={MyTitle.}]
  \externalfigure[mill]
\stopplacefigure

\blank[2em]

\startplacefigure
  [title={MyTitle.}]
\externalfigure[mill][background=shadow]
\stopplacefigure

\stoptext

Op zo 11 mei 2025 om 15:18 schreef Wolfgang Schuster <
wolfgang.schuster.lists@gmail.com>:

> Am 10.05.2025 um 21:39 schrieb Jeroen:
> > Is there a way with metapost to get a slightly off-centered (upper-
> > right) shadow around a figure?
>
> This a simple version (the \setupexternalfigures line is needed to load
> the example image because it won't wotk with dummy graphics):
>
> \startuseMPgraphic{shadow}
>    fill OverlayBox shifted (EmWidth/2,EmWidth/2) withcolor "lightgray" ;
>    setbounds currentpicture to OverlayBox ;
> \stopuseMPgraphic
>
> \defineoverlay [shadow] [\useMPgraphic{shadow}]
>
> \setupexternalfigures[location=default]
>
> \starttext
>
> \externalfigure[mill]
> \blank
> \externalfigure[mill][background=shadow]
>
> \stoptext
>
> Wolfgang
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 4082 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-11 14:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-10 19:39 [NTG-context] Shadow around a figure Jeroen
2025-05-11 11:09 ` [NTG-context] " Keith McKay
2025-05-11 12:35   ` Jeroen
2025-05-11 13:13 ` Wolfgang Schuster
2025-05-11 14:10   ` Jeroen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).