ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: [NTG-context] Re: Seeking advice for module that draws globes
Date: Mon, 18 Dec 2023 01:55:45 +0100	[thread overview]
Message-ID: <09bcff56-2b9c-45ec-a285-4b621c73725d@freedom.nl> (raw)
In-Reply-To: <D410D959-0030-4351-98D0-0D6CC4B0DA26@icloud.com>

On 12/17/2023 11:22 PM, Gavin via ntg-context wrote:
> Hello ConTeXters,
> 
> I wrote a little ConTeXt module for drawing globes. I would love some advice on how to improve it and share it. The code is quite short (about 250 lines). Most of the work is done by Lua, which reads the data files and calculates paths. These paths are passed to MetaFun, which draws the globe.

Just some quiks remarks ...

- you use the right strategy (tex/lua/mp)

- in mp you can do this

vardef theglobe(expr lat, lon) =
     for i = 1 upto lua.mp.makeglobe(lat, lon):
         (lua.mp.getglobepath(i)) &&&&
     endfor
     cycle
enddef ;

and then:

\startMPpage
     GlobeDiameter = 10cm ;
     fill fullcircle
         scaled GlobeDiameter
         withcolor .9white ;
     path p ; p := theglobe(23, 0)
         scaled .5GlobeDiameter
     ;
     draw p
         withpen pencircle scaled .2mm
         withcolor blue
         withtransparency (1,.5) ;
     fill p
         withcolor red
         withtransparency (1,.5) ;
     draw fullcircle
         scaled GlobeDiameter
         withcolor black ;
\stopMPpage

i use transparency to demo that a single path has advantages; you'll 
also notice that the runtime is actually at the mp end.

- in your lua code do this

local cosd = math.cosd
local sind = math.sind
local sqrt = math.sqrt

- also, use "MP.makeglobe" in the mp code and at the lua end function 
MP.makeglobe"" as that is the user namespace.

I'll mail you the lua file with some suggestions. When all is stable I 
can spend a few hours on optimizing if needed.

> I am a novice at both Lua and MetaPost. I’m also new to Git and have never shared anything of substance with the ConTeXt community. (This barely counts as substantive, but I figure it’s best to start small.) I’m sure many of you could find opportunities for improvement with even a quick glance at the code. I welcome anything, from advice on performance to suggestions about the license. My most pressing questions are these:

> 1. How do I avoid redrawing diagrams with every typeset? The globe above takes about 0.7s, which is not bad, but it adds up in a book with many diagrams.

see previous mail

> 2. How do I organize this according to TDS for sharing? I know what TDS is and why it’s important, but that’s about it!
> 
> 3. Should I be creating a namespace for this module, or launching a separate MetaFun instance? I have a general sense of what “namespace” and “instance” mean is this context, but I don’t know the consequences or the how-to.
> 
> I’d like to share this module, even though the potential demand is tiny, at best. I’m going through the Module Writing Guidelines (https://wiki.contextgarden.net/Modules#Module_writing_guidelines), but there is a lot that I don’t understand in those instructions. Questions 2 and 3 above relate to the instructions that are most mysterious to me. I think I can figure most of the others out.
> 
> I have been using ConTeXt for several years to write a high school physics textbook (along with the problem sets, tests, equations sheets, etc.). I wrote this module because I needed globes in some diagrams. I found an old MetaPost tool, mp-geo, that seemed to have the right ingredients, but I couldn’t get it to work, so I wrote my own tool using the data files from mp-geo. Hans and others on the list gave me valuable advice for these globes a couple years ago (and gave other valuable advice on all sorts of things before and since).
> 
> Many diagrams in my physics book use TikZ and pgfplots. I'd like to convert everything to MetaFun. I think the best way will be writing a few more modules for things like graphs (including polar and 3D plots), simple circuits, simple Feynman diagrams, etc. I’m hoping that these would be useful to the ConTeXt community. The luageo module has the basic design I’d like to use for the others: Lua for data handling and calculations, producing paths that are drawn by MetaFun. With some mentoring from the generous ConTeXt community, I’m hoping we can provide MetaFun alternatives to some of the TikZ libraries.

next year Mikael S and I are going to look into 3D (and projections) as 
we can only work on math when we have a parallel metafun pet project.

> I have an alpha version of luagraph by Alan Braslau, which was helpful in designing luageo. Working on luagraph is my next project.
> 
> 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
> ___________________________________________________________________________________

-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

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

  parent reply	other threads:[~2023-12-18 16:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-17 22:22 [NTG-context] " Gavin via ntg-context
2023-12-17 23:58 ` [NTG-context] " Hans Hagen via ntg-context
2023-12-18  7:12   ` Henning Hraban Ramm
2023-12-19 14:27     ` Gavin via ntg-context
2023-12-19 17:42       ` Henning Hraban Ramm
2023-12-18  0:55 ` Hans Hagen via ntg-context [this message]
2023-12-18  3:49   ` Gavin via ntg-context
2023-12-18 10:08     ` Hans Hagen via ntg-context
2023-12-18 10:12 ` Hans Hagen via ntg-context
2023-12-18 16:22   ` Gavin via ntg-context
2023-12-18 17:27     ` Hans Hagen via ntg-context

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=09bcff56-2b9c-45ec-a285-4b621c73725d@freedom.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@freedom.nl \
    /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).