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] Seeking advice for module that draws globes
Date: Sun, 17 Dec 2023 15:22:34 -0700	[thread overview]
Message-ID: <D410D959-0030-4351-98D0-0D6CC4B0DA26@icloud.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 948 bytes --]

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.

Below is an example document with the output. (I attached a small .png of the output for the mailing list. The output PDF has excessive detail.) The module (code and data) is on GitHub at https://github.com/GavinPolhemus/luageo.

\usemodule [luageo]
\startMPpage
    GlobeDiameter = 10cm ;
    fill fullcircle scaled GlobeDiameter withcolor .9white ;  % Fill a circle with the water color.
    drawglobe(23, 0) scaled GlobeDiameter withcolor .75white ;% Draw the land, centered on the given latitude and longitude.
    draw fullcircle scaled GlobeDiameter withcolor black ;    % Add a border, if you want.
\stopMPpage


[-- Attachment #2: luageoTestMPpage.png --]
[-- Type: image/png, Size: 28342 bytes --]

[-- Attachment #3: Type: text/plain, Size: 2671 bytes --]



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.

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.

I have an alpha version of luagraph by Alan Braslau, which was helpful in designing luageo. Working on luagraph is my next project.

Gavin



[-- Attachment #4: 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
___________________________________________________________________________________

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

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-17 22:22 Gavin via ntg-context [this message]
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
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=D410D959-0030-4351-98D0-0D6CC4B0DA26@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).