- Viết một file metapost như sau, lưu thành file clock9.mp :
path hand[];
hand1 = origin .. (.257,1/50) .. (.377,1/60)
& (.377,1/60) {up} .. (.40,3/50)
.. (.60, 1/40) .. {right} (.75,0);
hand1 := (hand1 .. reverse hand1 reflectedabout(left,right)
.. cycle) scaled 50;
hand2 = origin .. (.60, 1/64) .. {right} (.925,0);
hand2 := (hand2 .. reverse hand2 reflectedabout(left,right)
.. cycle) scaled 50;
% hour of the day to degrees
vardef htod(expr hours) = 30*((15-hours) mod 12) enddef;
vardef mtod(expr minutes) = 6*((75-minutes) mod 60) enddef;
vardef clock(expr hours, minutes) = image(
% face and outer ring
fill fullcircle scaled 100 withcolor 1/256(240, 240, 230);
draw fullcircle scaled 99 withcolor .8 white;
draw fullcircle scaled 100 withpen pencircle scaled 7/8;
% hour and minute marks
for t=0 step 6 until 359:
draw ((48,0)--(49,0)) rotated t;
endfor
for t=0 step 30 until 359:
draw ((47,0)--(49,0)) rotated t withpen pencircle scaled 7/8;
endfor
% numerals
for h=1 upto 12:
label(decimal h infont "bchr8r", (40,0) rotated htod(h));
endfor
% hands rotated to the given time
pickup pencircle scaled 7/8;
filldraw hand1 rotated htod(hours+minutes/60);
filldraw hand2 rotated mtod(minutes);
% draw the center on top
draw origin withpen pencircle scaled 5;
undraw origin withpen pencircle scaled 3;
)
enddef;
% Tạo 60 hình từ 0 đến 59, mỗi hình trên một trang riêng
for i = 0 upto 59:
beginfig(i);
draw clock(9, i); % 9 giờ, i phút
endfig;
endfor
end
|
- Mở một Terminal, chuyển đến thư mục làm việc là thư mục chứa file mp nói trên. Tại dòng lệnh ta gõ:
nhấn Enter, metapost sẽ biên dịch thành 60 file pdf đặt tên là clock9-0.pdf, clock9-1.pdf, ... , clock9-59.pdf
- Viết một file $\rm \TeX$ đặt tên là clock9.tex như sau:
\documentclass{minimal}
\usepackage{graphicx}
\usepackage{multido}
\usepackage[paperwidth=8cm,paperheight=8cm,
top=0.3cm,bottom=0cm,left=-.3cm,right=0cm]{geometry}
\DeclareGraphicsRule{*}{mps}{*}{}
\begin{document}
\multido{\n=0+1}{60}{\includegraphics[scale=2]{clock9-\n.pdf} \newpage }
\end{document}
|
Biên dịch bằng PdfLaTeX ta được file clock9.pdf. Để không bị rối xóa tất cả file có dạng clock9-*.pdf
- Dùng GIMP mở file clock9.pdf, export to clock9.gif , chọn tần số là 60000 (mili giây).
 | Đồng hồ chạy lúc 9g, kim phút và kim giờ sẽ chạy sau mỗi 15 giây. Xem chỉnh sửa file mp và file $\rm \TeX$ ở dưới.
|
filldraw hand1 rotated htod(hours+minutes/240) withcolor red;
filldraw hand2 rotated mtod(minutes/4) withcolor blue;
|
Edit file
$\rm Lua\LaTeX$
\multido{\n=0+1}{240}{\includegraphics[scale=2]{dh9giay-\n.pdf} \newpage }
|
Không có nhận xét nào:
Đăng nhận xét