SpringMass := proc( L :: numeric, # length of the spring w :: numeric, # width of the spring s :: numeric # stretch ) local spring, mass, ceiling, h, ref_line; # construct the plot of the spring by calling procedure Spring spring := Spring([0,0], [0,-L-s], w); # the plot of the mass mass := plottools[rectangle]([-0.5*w,-L-s-0.5*w],[0.5*w,-L-s+0.5*w]); # plot of the ceiling ceiling := plottools[line]([-2,0],[2,0],thickness=2), plottools[line]([-2,0],[-1.5,0.5],thickness=1), plottools[line]([-1,0],[-0.5,0.5],thickness=1), plottools[line]([0,0],[0.5,0.5],thickness=1), plottools[line]([1,0],[1.5,0.5],thickness=1), plottools[line]([2,0],[2.5,0.5],thickness=1): # the reference line (the equilibrium of the spring-mass) h := max(2*w,2.5); ref_line:= plottools[line]([-h,-L],[h,-L],thickness=1,linestyle=2): # output the plot return plots[display]({ceiling, spring,mass, ref_line}, axes = NONE, view=[-h..h,-2*L..0.5], scaling=constrained) end proc; # program to construct a spring Spring := proc( a :: list, # one end of the spring in xy-plane b :: list, # the other end of the spring; w :: numeric # width ) local c, d, u, v, h, k, L; c := 0.75*a+0.25*b; d := 0.25*a+0.75*b; # actual ends of the spring v := b-a; # direction of the spring u := [v[2],-v[1]]/evalf(sqrt(v[1]^2+v[2]^2)); # direction perpendicular h := 1.0/28; # horizontal stepsize k := 0.5*w; # vertical stepsize # the zigzag lines L[0] := plottools[line](a,c,thickness = 2); L[1] := plottools[line](c,c+h*v+k*u,thickness=2); L[2] := plottools[line](c+h*v+k*u,c+3*h*v-k*u,thickness=2); L[3] := plottools[line](c+3*h*v-k*u,c+5*h*v+k*u,thickness=2); L[4] := plottools[line](c+5*h*v+k*u,c+7*h*v-k*u,thickness=2); L[5] := plottools[line](c+7*h*v-k*u,c+9*h*v+k*u,thickness=2); L[6] := plottools[line](c+9*h*v+k*u,c+11*h*v-k*u,thickness=2); L[7] := plottools[line](c+11*h*v-k*u,c+13*h*v+k*u,thickness=2); L[8] := plottools[line](c+13*h*v+k*u,c+14*h*v,thickness=2); L[9] := plottools[line](d,b,thickness=2); return plots[display]({seq(L[j],j=0..9)}) end proc;