%% draw clock faces with random times
%% and random times under empty clock faces
% The resulting output will be clockquiz.1, .., clockquiz.n, where n
% is the number of pages. These can be printed on a postscript printer
% just by copying them to the printer, or on any other type of printer
% using ghostscript
% gs -sDEVICE=ljet4 -sOutputFile=myclock.lj -dNOPAUSE -dBATCH myclock.1 myclock.2
% lpr -l myclock.lj [unix]
% copy /b myclock.lj lpt1: [win32/os2]
%% copyright 2003 Patrick TJ McPhee
% $Header: /usr/home/ptjm/tex/RCS/clockquiz.mp,v 1.1 2003/06/28 02:19:28 ptjm Exp $
% number of pages to do -- overwrite from command-line or including file
% as in
% mpost '\pages = 25; input clockquiz' [unix]
% mpost \pages=25; input clockquiz [win32/os2]
%
% or myclock.mp:
% pages = 25;
% input clockquiz;
%
% mpost myclock
if unknown pages:
pages := 1;
fi;
% offset of bottom left image
(hoff, voff) = (2cm, 2cm);
% number of images per column and row
(nocols, norows) = (3, 5);
% width and height of each image
(coff, roff) = ((8.5in-2hoff)/nocols, (11in-2voff)/norows);
% make the pens round so I don't confuse the kid with lines of
% varying thickness
pickup pencircle scaled 2pt;
thick nib = savepen;
pickup pencircle scaled 1pt;
normal nib = savepen;
clock radius := 2cm;
path clock;
% the clock is a circle that starts at the top
clock = (clock radius, 2 clock radius)..
(2 clock radius, clock radius)..
(clock radius, 0)..
(0, clock radius)..
cycle;
% I want it to have 12 points, so redraw it
clock := (point 0 of clock)..
for i = 1 upto 11: (point i/3 of clock).. endfor
cycle;
string roman[];
roman[1] = "I";
roman[2] = "II";
roman[3] = "III";
roman[4] = "IV";
roman[5] = "V";
roman[6] = "VI";
roman[7] = "VII";
roman[8] = "VIII";
roman[9] = "IX";
roman[10] = "X";
roman[11] = "XI";
roman[12] = "XII";
defaultfont := "ptmr8r";
defaultscale := 2;
prologues := 2;
% draw a clock face with a spot to the right to write the time.
% h is the hour, m is the minute
% how is 0 if the hands should be drawn (so the kid can fill
% in the time) or 1 if the time should be given (so the kid can
% draw in the hands)
% ticks indicates how the hours should be marked on the clock
% 0 for lines, 1 for arabic numerals perpendicular to the radius
% of the clock, 2 for roman numerals perpendicular to the radius
% of the clock, or 3 for arabic numerals right-way up, with a dot
% to mark the hour
%
% The hour hand is set between the hour it marks and the next hour,
% proportionate to the number of minutes. The teaching materials
% I've seen put the hour hand right on the hour, and this seems
% to cause confusion with real-world clocks. All the different ways
% of marking the time are justified for the same reason, although I
% haven't observed any confusion on that count. I really did them
% for aesthetics.
def drawclock(expr h, m, how, ticks) =
begingroup;
save c, p, ods;
pair c;
picture p;
c = center clock;
pickup thick nib;
draw clock;
drawdot c;
pickup normal nib;
% draw the hours either as ticks,
if ticks = 0:
for i = 1 upto 12:
draw 12/13[c, point i of clock]..(point i of clock);
endfor;
% as numbers,
elseif ticks = 1:
for i = 1 upto 12:
p := decimal i infont defaultfont;
p := p shifted ((0, -10pt) - center p);
draw (p rotated(angle(direction i of clock)))
shifted (point i of clock);
endfor;
% as roman numerals,
elseif ticks=2:
for i = 1 upto 12:
p := roman[i] infont defaultfont;
p := p shifted ((0, -10pt) - center p);
draw (p rotated(angle(direction i of clock)))
shifted (point i of clock);
endfor;
% or as numbers and dots
else:
ods = defaultscale;
defaultscale := 1.3;
pickup thick nib;
for i = 1 upto 12:
drawdot((12/13[c, point i of clock]));
label(decimal i, (8/10[c, point i of clock]));
endfor;
defaultscale := ods;
pickup normal nib;
fi
draw (2 clock radius, 0)..(3 clock radius, 0);
label.top(":", (2.5 clock radius, 0));
% either draw the clock face or the time in words
if how = 0:
drawarrow c..(9/10[c,point m/5 of clock]);
drawarrow c..(6/10[c,point (h+ m/60) of clock]);
else:
label.ulft(if h = 0: "12" else: decimal h fi, (2.5 clock radius, 0));
label.urt(if m < 10: "0" & fi decimal m, (2.5 clock radius, 0));
fi
endgroup;
enddef;
% generate so many pages of clocks
for i = 1 upto pages:
beginfig(i);
for j = 0 upto (norows-1):
for k = 0 upto (nocols-1):
draw image(drawclock(round(uniformdeviate(11)), round(uniformdeviate(59)),
round(uniformdeviate(1)), round(uniformdeviate(3)));)
shifted ((hoff,voff)+(k*coff,j*roff));
endfor;
endfor;
endfig;
endfor;
end