From: Andres Conrado Montoya <andresconrado@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Drawing calligraphy practice grid in metafun
Date: Tue, 21 Nov 2023 00:32:37 -0500 [thread overview]
Message-ID: <CAGhDZhAY4e4-edVap8JecnnRJ+MNhgZc+GexqK7w7HZZ=b_CgA@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 4953 bytes --]
Hello list
I've been working on a little project of mine. I give calligraphy workshops
and I have been using a nice tool created by Josselin Cuette, available at
http://ductus.josselincuette.com/ to generate practice templates for
interested people.
However, I would prefer to have an offline solution. This adventure started
with the usual insidious idea: "I could do this in ConTeXt! And this is a
great opportunity to learn metafun!"
A couple weeks later, I have an almost ready product! It compiles fine, but
I have the following issue: The template creates a Line, composed of
Sections. And uses variables to assign a measurement for the nib-width, and
an amount of ascender, x-height and descender Sections (nib-widths), to
compose a Line.
But also, I would like to, if needed, display nib-width marks on the left
side. My code so far generates marks, but only for the first Line. I think
they are generated but maybe they are placed on top of each other, maybe?
I'm not sure why my logic is not working.
Also, if I change the amount for ascenders, descenders of x-height, the
marks are not drawn correctly.
My current path for a mark is a custom path emulating two unit squares,
nib-width size, on top of each other, with the top one shifted a nib-width
to the right. A little bit like a chess board, or a scale ruler on a map.
But this would only work in Lines that have an even amount of Sections. I'm
not sure how to proceed with that... I tried using unit squares, but that
made things very complex, and after fumbling around I managed to get this
far.
If you can take a look, or have some advice, it would be greatly
appreciated. I hope it is understandable.
My code:
%%%%%%%%%%%%%%%%%%
\setuppapersize[letter,landscape][letter,landscape]
\setuplayout[backspace=15mm,width=250mm,header=0mm,footer=0mm]
\startreusableMPgraphic{pauta}
% Global variables:
% Show nib-width marks
boolean marks ; marks := true ;
% Path for nib-width
path mark ; mark := (0,0) -- (1,0) -- (1,2) -- (2,2) -- (2,1) -- (0,1) --
cycle ;
% Line width
numeric line ; line := \the\textwidth ;
% Type box
numeric box ; box := \the\textheight ;
% Nib width (distance between lines)
numeric nib ; nib := 3mm ;
% Ascenders for writing line
numeric asc ; asc := 3 ;
% x-height for writing line
numeric med ; med := 4 ;
% Descenders for writing line
numeric dsc ; dsc := 3 ;
% Total height of a writing line in mm (including asc, med, and dsc)
numeric lineHeight ;
lineHeight = (asc + med + dsc) * nib ;
% Available lines on a page
numeric availableLines ;
availableLines = round(box / lineHeight) - 1 ;
% Starting position
numeric start ; start := 0 ;
% Macros
% Draw a section of a line (ascender, x-height or descender)
vardef Section(expr lines, initial) =
draw (0, initial) -- (line, initial) withpen pencircle scaled 0.2mm ;
for i=0 step 1 until lines :
save final ; final = i*nib ;
pair a; a = (0, final + initial) ;
pair b; b = (line, final + initial) ;
draw a -- b withpen pencircle scaled 0.1mm ;
% If marks=true show nib-width marks
if marks = true:
fill mark scaled nib yshifted (final*2) ;
fi ;
endfor ;
draw (0, final + initial) -- (line, final + initial)
withpen pencircle scaled 0.2mm ;
final + initial
enddef ;
% Draw a line with the three secions (asc, med, dsc)
vardef Line(expr descender, ascender, xheight, initial) =
numeric dd, oo, aa ;
% Líneas
dd = Section(descender, initial) ;
oo = Section(xheight, dd) ;
aa = Section(ascender, oo) ;
% Devolver posicion final con espacio para siguiente renglon
aa + nib*2
enddef ;
% Llenar la página con renglones
for i=1 upto availableLines :
start := Line(dsc, asc, med, start) ;
endfor ;
\stopreusableMPgraphic
\startdocument
\startstandardmakeup
\reuseMPgraphic{pauta}
\stopstandardmakeup
\stopdocument
%%%%%%%%%%%%%%%%%%%%%%%%%%
--
Andrés Conrado Montoya
Andi Kú
andresconrado@gmail.com
http://sesentaycuatro.com
http://messier87.com
http://chiquitico.org
----------------------------------------
Los fines no justifican los medios, porque la medida verdadera de nuestro
carácter está dada por los medios que estamos dispuestos a utilizar, no por
los fines que proclamamos.
----------------------------------------
“You develop an instant global consciousness, a people orientation, an
intense dissatisfaction with the state of the world, and a compulsion to do
something about it. From out there on the moon, international politics look
so petty. You want to grab a politician by the scruff of the neck and drag
him a quarter of a million miles out and say, ‘Look at that, you son of a
bitch.’” — Apollo 14 astronaut Edgar Mitchell
[-- Attachment #1.2: Type: text/html, Size: 5973 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
___________________________________________________________________________________
reply other threads:[~2023-11-21 5:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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='CAGhDZhAY4e4-edVap8JecnnRJ+MNhgZc+GexqK7w7HZZ=b_CgA@mail.gmail.com' \
--to=andresconrado@gmail.com \
--cc=ntg-context@ntg.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).