"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.61/examples/spring.asy" (18 Nov 2019, 671 Bytes) of package /linux/misc/asymptote-2.61.src.tgz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 pair coilpoint(real lambda, real r, real t)
    2 {
    3   return (2.0*lambda*t+r*cos(t),r*sin(t));
    4 }
    5   
    6 guide coil(guide g=nullpath, real lambda, real r, real a, real b, int n)
    7 {
    8   real width=(b-a)/n;
    9   for(int i=0; i <= n; ++i) {
   10     real t=a+width*i;
   11     g=g..coilpoint(lambda,r,t);
   12   }
   13   return g;
   14 }
   15 
   16 void drawspring(real x, string label) {
   17   real r=8;
   18   real t1=-pi; 
   19   real t2=10*pi;
   20   real lambda=(t2-t1+x)/(t2-t1);
   21   pair b=coilpoint(lambda,r,t1);
   22   pair c=coilpoint(lambda,r,t2);
   23   pair a=b-20;
   24   pair d=c+20;
   25  
   26   draw(a--b,BeginBar(2*barsize()));
   27   draw(c--d);
   28   draw(coil(lambda,r,t1,t2,100));
   29   dot(d);
   30 
   31   pair h=20*I;
   32   draw(label,a-h--d-h,red,Arrow,Bars,PenMargin);
   33 }