Hans,
This sample code will give you an idea of my last feature request for
mp-tool. Often, I will design my schematic on graph paper, then start to
code. But there are times when I like to work interactively, write a little
code, test to see what I get, adjust, ... When I am in that mode, a grid is
"very" helpful. Once I am through with adjustments, I simply comment out
the line " drawgrid(0,0,20,10,1u,1u);".
My drawgrid routine was stolen from the schema.mp file and adjusted for a
quick fix (I am writing for a deadline again), but it works. But it would
be nice if something like this were in mp-tool. Turn on your numbered grid,
work interactively, turn it off when done. Very nice.
Happy New Year!
input mp-tool
def drawgrid(expr xo,yo,nx,ny,sx,sy)=
begingroup
save cpen,result;
pen cpen;
picture result;
cpen:=pencircle scaled 1pt;
result:=nullpicture;
for x=0 upto nx:
for y=0 upto ny:
addto result doublepath (x*sx,y*sy) withpen cpen;
endfor
endfor
defaultfont:="cmr7";
defaultscale:=7pt/fontsize defaultfont;
for x=0 upto nx:
addto result also thelabel.bot(decimal(x),(x*sx,0)) withpen cpen;
endfor
for y=0 upto ny:
addto result also thelabel.lft(decimal(y),(0,y*sy)) withpen cpen;
endfor;
draw result;
endgroup
enddef;
beginfig(6);
%initialize scale
numeric u; 1u=0.25in;
drawgrid(0,0,20,10,1u,1u);
%draw line for measurement later
draw (0,0)--(10u,0);
%draw base for pivot
path base;
base:=unitsquare xyscaled (4u,1u);
base:=base shifted (8u,-2u);
stripe_path_a(withcolor black)(draw)
base withcolor white;
draw (8u,-1u)--(12u,-1u);
%draw pivot
path tri;
tri:=(-1,-1)--(0,1)--(1,-1)--cycle;
tri:=tri scaled u;
tri:=tri shifted (10u,0);
fill tri withcolor 0.85white;
%initialize pendulum
path pend;
pend:=(9.5,-0.5)--(10.5,-0.5)--(10.5,10.5)--(9.5,10.5)--cycle;
pend:=pend scaled u;
draw pend;
%draw pivot point
drawdot(10u,0) withpen pencircle scaled 6pt;
%draw spring block left
path left;
left:=(2,9)--(3,9)--(3,11)--(2,11)--cycle;
left:=left scaled u;
stripe_path_a(withcolor black)(draw)
left withcolor white;
draw (3u,9u)--(3u,11u);
%draw spring block right
path right;
right:=(17,9)--(18,9)--(18,11)--(17,11)--cycle;
right:=right scaled u;
stripe_path_a(withcolor black)(draw)
right withcolor white;
draw (17u,9u)--(17u,11u);
%spring
path spring, link;
link:=(0,0)--(0.25,0.5)--(0.75,-0.5)--(1,0);
spring:=link;
for k=1 upto 2:
spring:=spring--(link shifted (k,0));
endfor
spring:=spring scaled u;
%left spring
draw (3u,10u)--(5u,10u);
draw spring shifted (5u,10u);
draw (8u,10u)--(10u,10u);
%right spring
draw (10u,10u)--(12u,10u);
draw spring shifted (12u,10u);
draw (15u,10u)--(17u,10u);
%draw spring contact point
drawdot(10u,10u) withpen pencircle scaled 6pt;
%label springs
label(btex $k$ etex, (6.5u,11u));
label(btex $k$ etex, (13.5u,11u));
%label some measurement lengths
pair A, B, C, D, E;
A:=(1u,0);
B:=(1u,10u);
C:=(5u,0);
D:=(5u,5u);
E:=(10u,5u);
drawdblarrow A--B;
label.lft(btex $L$ etex, 0.5[A,B]);
drawdblarrow C--D;
draw (0,10u)--(2u,10u);
label.lft(btex $L/2$ etex, 0.5[C,D]);
draw (4u,5u)--(6u,5u);
drawdot(E) withpen pencircle scaled 6pt;
label.top(btex cm etex,E shifted (0,5));
endfig;