%%%% trchd_1.ldf %%%% Created by Laurence D. Finston (LDF) Tue Jan 13 18:00:51 CET 2009 %%%% $Id: trchd_1.ldf,v 1.4 2009/01/13 18:13:04 lfinsto1 Exp $ %% * (1) Copyright and License. %%%% This file is part of GNU 3DLDF, a package for three-dimensional drawing. %%%% Copyright (C) 2009 The Free Software Foundation %%%% GNU 3DLDF is free software; you can redistribute it and/or modify %%%% it under the terms of the GNU General Public License as published by %%%% the Free Software Foundation; either version 3 of the License, or %%%% (at your option) any later version. %%%% GNU 3DLDF is distributed in the hope that it will be useful, %%%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %%%% GNU General Public License for more details. %%%% You should have received a copy of the GNU General Public License %%%% along with GNU 3DLDF; if not, write to the Free Software %%%% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA %%%% GNU 3DLDF is a GNU package. %%%% It is part of the GNU Project of the %%%% Free Software Foundation %%%% and is published under the GNU General Public License. %%%% See the website http://www.gnu.org %%%% for more information. %%%% GNU 3DLDF is available for downloading from %%%% http://www.gnu.org/software/3dldf/LDF.html. %%%% It is also available from %%%% http://www.dante.de/software/ctan/, the Dante www-server %%%% and from http://wwwuser.gwdg.de/~lfinsto1, %%%% the author's website. %%%% Please send bug reports to lfinsto1@gwdg.de %%%% The mailing list help-3dldf@gnu.org is available for people to %%%% ask other users for help. %%%% The mailing list info-3dldf@gnu.org is for sending %%%% announcements to users. To subscribe to these mailing lists, send an %%%% email with ``subscribe '' as the subject. %%%% The author can be contacted at: %%%% Laurence D. Finston %%%% c/o Free Software Foundation, Inc. %%%% 51 Franklin St, Fifth Floor %%%% Boston, MA 02110-1301 %%%% USA %%%% lfinsto1@gwdg.de %%%% s246794@stud.uni-goettingen.de %% Last updated: January 13, 2009 %% Run like this: %% 3dldf trchd_1.ldf %% mpost trchd_1.mp %% tex trchd_1.txt %% dvips -o trchd_1.ps trchd_1.dvi %% ps2pdf trchd_1.ps %% All on one line: if false: 3dldf trchd_1.ldf && mpost trchd_1.mp && tex trchd_1.txt && \ dvips -o trchd_1.ps trchd_1.dvi \ && ps2pdf trchd_1.ps fi; %% View the PostScript file using Ghostview like this: %% gv trchd_1.ps & %% or with GNU Ghostview like this: %% ggv trchd_1.ps & %% View the PDF file with Acrobat Reader like this: %% acroread trchd_1.pdf & %% Convert the final EPS image to JPEG like this: %% conveps --start=1211 --end=1211 --output-format=jpeg --border=0 trchd_1 %% Convert EPS files to JPEG like this: %% conveps --start=1 --end=1211 --output-format=jpeg --border=0 trchd_1 %% Generate animated GIF like this: %% convert -delay 15 trchd_1_*.jpg trchd_1.gif %% %% Other formats can be used; it doesn't have to be JPEG. %% The animated GIF can be viewed using the `animate' program from ImageMagick: %% animate trchd_1.gif %% * (1) Beginning of 3DLDF code. %% ** (2) Trochoid Pattern 1 m := 10; n := 10; w := 6.4cm; h := 4.8cm; w *= 4; h *= 4; w /= 1.1375; h /= 1.1375; pen_width := .5mm; frame_w := w - .5pen_width; frame_h := h - .5pen_width; path frame; frame := origin -- (frame_w, 0) -- (frame_w, 0, frame_h) -- (0, 0, frame_h) -- cycle; shift frame (-.5frame_w, 0, -.5frame_h); %% *** (3) circle c[]; rectangle r[]; point p[]; transform t[]; path q[][]; pen dot_pen; dot_pen := pencircle scaled (1mm, 1mm, 1mm); string s; boolean inner; boolean outer; boolean perimeter; perimeter := false; % true inner := true; % false outer := false; % true pickup pencircle scaled (.5mm, .5mm, .5mm); r0 := unit_rectangle scaled (12, 0, 12) shifted origin; %% *** (3) The circle. radius := 2.5; set c0 with_diameter 2*radius with_point_count 32; %% *** (3) Get points for i := 0 upto 3: p[i] := get_point (i) r0; endfor; p5 := get_center c0; for i := 6 upto 9: p[i] := get_point ((i - 6) * 8) c0; endfor; p10 := (p5 - p8) shifted by p0; t0 := identity shifted by (p10 - p9); c0 *= p5 *= p6 *= p7 *= p8 *= p9 *= t0; p15 := mediate(p5, p9, .75); for j = 6 upto 9: q[iter_ctr][j] += ..; q[iter_ctr][j] += p[j]; endfor; q[iter_ctr]15 += ..; q[iter_ctr]15 += p15; numeric ang[]; PI := 3.141592653589793; p11 := p5 shifted (0, 1); p12 := (p0 - p8) shifted by p3; p13 := (p5 - p8) shifted by p12; p14 := p13 - p5; %message "p14:"; %show p14; distance := zpart p14; message "distance:"; show distance; circumference := 2 * PI * radius; message "circumference:"; show circumference; ang0 := (360 * distance) / circumference; message "ang0:"; show ang0; step_value := 256; %% The number of iterations for each side total_iterations := 4 * 256; %% Total iterations per cycle figure_divisor := 16; %% Set to 256 for 32 images numeric curr_value; numeric curr_figure; iter_ctr := 0; color_vector cv; boolean do_colors; do_colors := true; % false if do_colors: cv += blue; cv += red; cv += green; cv += cyan; cv += magenta; cv += yellow; cv += violet; cv += orange; else: cv += black; cv += black; cv += black; cv += black; cv += black; cv += black; cv += black; cv += black; fi; %% *** (3) Figure 0 beginfig(0); %draw frame; %% **** (4) The rectangle draw r0; % dotlabel.llft("$p_0$", p0); % dotlabel.lrt("$p_1$", p1); % dotlabel.urt("$p_2$", p2); % dotlabel.ulft("$p_3$", p3); %dotlabel.lrt("$p_{10}$", p10); drawdot p5 with_pen dot_pen; %label("$p_5$", p5); draw c0; if perimeter: draw p5 -- p9; drawdot p9 with_pen dot_pen with_color cv[n]; % dotlabel.rt("$p_{9}$", p9); fi; if inner: draw p5 -- p15; drawdot p15 with_pen dot_pen with_color cv[n]; % dotlabel.rt("$p_{15}$", p15); fi; %if outer: % draw p5 -- p; %fi; % dotlabel.top("$p_7$", p7); % dotlabel.lft("$p_8$", p8); % dotlabel.llft("$p_9$", p9); endfig with_projection parallel_x_z; %% *** (3) Roll the circle. curr_value := 1; curr_figure := 1; %% *** (3) Outer loop. One iteration per complete cycle around the square. for iter_ctr := 0 upto 7: %% **** (4) Inner loop. One iteration for each step in paths. %% The number of iterations is `total_iterations'. for i = ((iter_ctr * 4 * step_value) + 1) upto ((iter_ctr * 4 * step_value) + (4 * step_value)): t1 := (identity rotated_around (p5, p11) ang0/step_value); if i <= ((iter_ctr * 4 * step_value) + step_value): %% left side shift t1 (0, 0, distance/step_value); elseif i <= ((iter_ctr * 4 * step_value) + (2 * step_value)): %% top shift t1 (distance/step_value, 0, 0); elseif i <= ((iter_ctr * 4 * step_value) + (3 * step_value)): %% right side shift t1 (0, 0, -distance/step_value); elseif i <= ((iter_ctr * 4 * step_value) + (4 * step_value)): %% bottom shift t1 (-distance/step_value, 0, 0); fi; c0 *= p5 *= p6 *= p7 *= p8 *= p9 *= p11 *= p15 *= t1; % message "ang0/step_value:"; % show ang0/step_value; %% ***** (5) Add point to the paths. for j = 6 upto 9: q[iter_ctr][j] += ..; q[iter_ctr][j] += p[j]; % draw q[iter_ctr][j]; endfor; q[iter_ctr]15 += ..; q[iter_ctr]15 += p15; q[iter_ctr]15 += ..; q[iter_ctr]15 += p15; %% ***** (5) Test whether to output a figure k := curr_value / figure_divisor; if k == floor k: s := "Figure " & decimal curr_figure; message s; %% ***** (5) Output a figure beginfig(curr_figure); %draw frame; draw r0; draw c0; drawdot p5 with_pen dot_pen; %label("$p_5$", p5); % dotlabel.rt("$p_6$", p6); % dotlabel.top("$p_7$", p7); % dotlabel.lft("$p_8$", p8); % dotlabel.llft("$p_9$", p9); % dotlabel.lft("$p_{12}$", p12); % dotlabel.lft("$p_{13}$", p13); if perimeter: %dotlabel.rt("$p_{9}$", p9); draw p5 -- p9; for n = 0 upto iter_ctr: draw q[n]9 with_color cv[n]; drawdot p9 with_pen dot_pen with_color cv[n]; endfor; fi; if inner: %dotlabel.rt("$p_{15}$", p15); draw p5 -- p15; for n = 0 upto iter_ctr: draw q[n]15 with_color cv[n]; drawdot p15 with_pen dot_pen with_color cv[n]; endfor; fi; % if outer: % fi endfig with_projection parallel_x_z; curr_figure += 1; %% ***** (5) fi; %% Output a figure %% ***** (5) curr_value += 1; endfor; %% End of inner loop %% **** (4) endfor; %% End of outer loop %% *** (3) % message "next curr_figure:"; % show curr_figure; % message "next curr_value:"; % show curr_value; %% *** (3) End of 3DLDF code verbatim_metapost "end;"; end; %% ** (2) %% * (1) Emacs-Lisp code for use in indirect buffers when using the %% GNU Emacs editor. The local variable list is not evaluated when an %% indirect buffer is visited, so it's necessary to evaluate the %% following s-expression in order to use the facilities normally %% accessed via the local variables list. %% \initials{LDF 2004.02.12}. %% (progn (metafont-mode) (outline-minor-mode t) (setq fill-column 80) (ignore '( %% )) (setq outline-regexp "%% [*\f]+")) %% * (1) Local variables for Emacs. %% Local Variables: %% mode:Metafont %% eval:(outline-minor-mode t) %% eval:(read-abbrev-file abbrev-file-name) %% outline-regexp:"%% [*\f]+" %% End: