ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Troy Henderson <thenders@gmail.com>
To: Hans Hagen <pragma@wxs.nl>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Numerical Calculations
Date: Wed, 19 Dec 2012 14:54:58 -0600	[thread overview]
Message-ID: <CAFP+xFLGixp0huhC5ngBp1mos7eWZ9sgid9_VmodnJHKLv_-Jw@mail.gmail.com> (raw)
In-Reply-To: <50D223FF.7090301@wxs.nl>


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

In case anyone cares, here is the "finished" product which is a
frame-by-frame animation of a hypocycloid.  The following code will produce
a 190 page PDF where each page is an individual frame of the animation.

Troy

\edef\r{\luaexpr{1/3.8}} % Radius of smaller circle (larger circle has
radius 1)
\edef\N{10} % Number of frames in animation per hypocycloid "branch"

\edef\K{1}\doloop{\ctxlua{commands.doifelse(math.abs(\K*\r -
math.floor(\K*\r+0.5))<0.000001)}{\exitloop}{\edef\K{\luaexpr{\K+1}}}}
\startMPinclusions[+]
    r:=\r; % Radius of smaller circle (larger circle has radius 1)
    u:=70; % Scaling factor for the graphics
    K:=\K; % Number of "branches" per period (computed automatically)
    M:=8; % Number of points in the Bezier curve for each "branch"
    N:=\N; % Number of frames in animation per hypocycloid "bran
    path p; % p is the "first branch" of the hypocycloid
    p:=(1,0) for m=1 upto (M-1): ..
(r*cosd(360*(r-1)/(M-1)*m)-(r-1)*cosd(360*r/(M-1)*m),r*sind(360*(r-1)/(M-1)*m)-(r-1)*sind(360*r/(M-1)*m))
endfor;
    W:=ceiling(u/32*65); % Width of each figure's bounding box
    H:=W; % Height of each figure's bounding box
    path q;
\stopMPinclusions
\starttext
    \dorecurse{\luaexpr{\K*\N}}{
        \startMPpage
            m:=floor((\recurselevel-1)/N);
            n:=\recurselevel-m*N-1;
            numeric s[];
            t:=n/N;

q:=(((1-r)*cosd(360*r*t),(1-r)*sind(360*r*t))--((1+r)*cosd(360*(r-1)*t)-(r-1)*cosd(360*r*t),(1+r)*sind(360*(r-1)*t)-(r-1)*sind(360*r*t)));
            (s1,s2) = p intersectiontimes reverse q;
            for j=0 upto (m-1): draw p scaled u rotated (360*r*j) withcolor
red; endfor;
            draw subpath (0,s1) of p scaled u rotated (360*r*m) withcolor
red;
            draw fullcircle scaled (2*u);
            draw fullcircle scaled (2*r*u) shifted
((1-r)*u*cosd(360*r*t),(1-r)*u*sind(360*r*t)) rotated (360*r*m);
            draw subpath (s2,length q) of (reverse q) scaled u rotated
(360*r*m);
            setbounds currentpicture to
(-W/2,-H/2)--(W/2,-H/2)--(W/2,H/2)--(-W/2,H/2)--cycle;
        \stopMPpage
    }
\stoptext

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

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

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2012-12-19 20:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-19 18:09 Troy Henderson
2012-12-19 18:16 ` Thomas A. Schmitz
2012-12-19 18:18 ` Hans Hagen
2012-12-19 18:19 ` Hans Hagen
2012-12-19 18:43   ` Troy Henderson
2012-12-19 19:19     ` Roland Thiers
2012-12-19 19:26       ` Hans Hagen
2012-12-19 19:25     ` Hans Hagen
     [not found]       ` <CAFP+xFK89EWiM7SbhVvZKPe1Hv2UKNGAgo6B8kaJNaE363dWpA@mail.gmail.com>
     [not found]         ` <CAFP+xFJqt=j-3B1y2LpYj6Xuu19viGScjEea=rN5FtVsotd3yw@mail.gmail.com>
2012-12-19 20:30           ` Hans Hagen
2012-12-19 20:54             ` Troy Henderson [this message]
2012-12-19 22:05               ` Marco Patzer
2012-12-19 22:10                 ` Troy Henderson
2012-12-19 23:03                   ` Troy Henderson
2012-12-21 12:22                     ` Andre Caldas
2012-12-21 12:56                       ` Troy Henderson
2012-12-19 23:20                   ` Marco Patzer
2012-12-19 19:32     ` Philipp Gesang

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=CAFP+xFLGixp0huhC5ngBp1mos7eWZ9sgid9_VmodnJHKLv_-Jw@mail.gmail.com \
    --to=thenders@gmail.com \
    --cc=ntg-context@ntg.nl \
    --cc=pragma@wxs.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).