Skip to content

Commit

Permalink
Some METAFONT exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
hansonchar committed May 19, 2024
1 parent b38f554 commit e5e7a03
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
39 changes: 39 additions & 0 deletions learning-latex/METAFONT/mftut/1.10-SimpleE.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
% Draw a character "E":
%
% 3------4
% |
% |
% 2---5
% |
% |
% 1------6
%
% Golden ratio
Phi=(1+sqrt5)/2;
% Width in pixel by default
w=100;
% Height
h=Phi*w;

% Bottom line
y1=y6=0;
% Top line
y3=y4=h;
% Middle line
y2=y5;
% Vertical stroke
x1=x2=x3=0;

% Make the middle horizontal stroke relatively shorter.
Phi*x5=x6=x4=w;

% Make the ratio of the areas above and below the middle horizontal a golden ratio.
(y3-y2)=(y2-y1)*Phi;

draw z1..z6;
draw z2..z5;
draw z3..z4;
draw z1..z3;

labels(range 1 thru 6);
showit; shipit; end;
45 changes: 45 additions & 0 deletions learning-latex/METAFONT/mftut/ex-1.13K.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
% Exercise 1.13K - Create a capital "K" such that
% 1. The ratio of its height by its width is equal to the golden number.
% 2. The middle point is at the same height as that of the E character in 1.10-SimpleE.mf.
% 3. The south east stroke meets the north east stroke that splits the north east stroke by
% some power of the golden ratio.
%
% 3| /5
% | /
% 2|/\4
% | \
% 1| \6
%
% Golden ratio
Phi=(1+sqrt5)/2;
% Width in pixel by default
w=100;
% Set the height to satisfy the first requirement.
h=Phi*w;

% Anchor the bottom.
% Use an arbitrary location other than (0,0) to show that this works without
% an implicit assumption about the origin.
z1=(3, 7);

% Anchor the top right.
z5=(x1+w, h);
% Anchor the top left.
z3=(x1, h);
% Anchor the bottom right.
z6=(x1+w, y1);

% Set the height of the middle point to satisfy the second requirement.
(y3-y2)=(y2-y1)*Phi;
x2=x1;

% Set the position of z4 so it would divide the north east stroke by the golden ratio.
(z4-z2)*Phi*Phi=(z5-z4);
z4=whatever[z2,z5];

draw z1..z3;
draw z2..z5;
draw z4..z6;

labels(range 1 thru 6);
showit; shipit; end;

0 comments on commit e5e7a03

Please sign in to comment.