ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Gavin via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Gavin <gavinpublic@icloud.com>
Subject: [NTG-context] Lua and inject.path to make a disconnected MetaPost path?
Date: Mon, 8 Jan 2024 18:19:04 -0700	[thread overview]
Message-ID: <7E5C3193-E36B-4EEC-B15F-B790282CA213@icloud.com> (raw)
In-Reply-To: <1731C940-4C5A-4BD5-B7DB-6AC3AA3B11E6@icloud.com>

Hello LuaMetaFun Fans,

Can I use mp.inject.path in Lua to create a disconnected path in MetaPost?

This is for my module that draws globes. I currently do something like this for drawing the continents. (This MWE has two triangular continents.)

\startluacode
  continents = {}
  continents[1] = {{0,0}, {-1,-1}, {-1,0}, cycle = true }
  continents[2] = {{0,1}, {1,0}, {1,-1}, cycle = true }
  function mp.getglobepath(continentnum)
    mp.inject.path(continents[continentnum])
  end
\stopluacode

\startMPpage
  path p[], q ;
  p1 = (lua.mp.getglobepath(1) scaled 1cm) ;
  p2 = (lua.mp.getglobepath(2) scaled 1cm) ;
  q = p1 && p2 && cycle ;
  draw p1 withpen pencircle scaled 2pt withcolor .7 ;
  draw p2 withpen pencircle scaled 2pt withcolor .7 ;
  fill q withcolor 0.9 ;
  draw q withcolor red ;
\stopMPpage

The path q has both of the continents, disconnected.

I’d like to produce the two continents in Lua and pass them to MetaPost as a single disconnected path, using something like this: 

\startluacode
  continents = {
    {0,0}, {-1,-1}, {-1,0}, — Change this to make a disconnected path!
    {0,1}, {1,0}, {1,-1},
    cycle = true }
  function mp.getglobepath()
    mp.inject.path(continents)
  end
\stopluacode

\startMPpage
  path p ;
  p = (lua.mp.getglobepath() scaled 1cm) ;
  fill p withcolor 0.9 ;
  draw p withcolor red ;
\stopMPpage

If I can make the path p disconnected, this would allow me to make exactly the path I want in Lua, before passing it to MetaPost, rather than passing lots of paths and connecting them in MetaPost with the mysterious (to me) && or &&&&.

Thanks!
Gavin


___________________________________________________________________________________
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
___________________________________________________________________________________

      reply	other threads:[~2024-01-09  1:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31  2:31 [NTG-context] MetaFun path joiners && and &&&& do not like single point paths Gavin via ntg-context
2023-12-31  7:06 ` [NTG-context] " Mikael Sundqvist
2023-12-31 11:14   ` Hans Hagen via ntg-context
2023-12-31 14:10     ` Gavin via ntg-context
2024-01-09  1:19       ` Gavin via ntg-context [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7E5C3193-E36B-4EEC-B15F-B790282CA213@icloud.com \
    --to=ntg-context@ntg.nl \
    --cc=gavinpublic@icloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).