/* * Render a cylindrical slide rule in Postscript * (Otis King model L lookalike). * * Copyright (c) 2001 Peter Monta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include #include #define N 20 /* number of helix turns in a scale-decade */ #define XS 74.592 /* circumference of upper scale */ #define YS 49.324 /* height of a scale-decade */ /* * draw a Postscript line */ void line(double x1,double y1,double x2,double y2) { printf("%f %f moveto %f %f lineto stroke\n",x1*XS,y1*YS,x2*XS,y2*YS); } /* * draw Postscript text */ void text(double x,double y,char* s) { printf("%f %f moveto (%s) show\n",x*XS,y*YS,s); } /* * draw a tick mark, with text if it's a major tick (type 0) */ void tick(double v,int t,int log,int dir) { double x,vorig; char s[128]; vorig=v; if (log) v = log10(v); x = N*v - (int)(N*v); switch (t) { case 0: line(x,v,x,v+dir*0.017); if (log) sprintf(s,"%3.0f",100.0*vorig); else sprintf(s,"%03.0f",1000.0*vorig); text(x-0.012,v+((dir==1)?0.015:-0.038),s); break; case 1: line(x,v,x,v+dir*0.012); break; case 2: line(x,v,x,v+dir*0.008); break; case 3: line(x,v,x,v+dir*0.017); if (log) sprintf(s,"%3.0f",10.0*vorig); else sprintf(s,"%03.0f",0.0); text(x-0.012,v+((dir==1)?0.015:-0.038),s); break; } } typedef struct { int n; double begin; double incr; int type; } tick_style; #define NTICK 10 tick_style tick_tab[NTICK] = { { 100, 1.00, 0.01, 0 }, /* major ticks */ { 75, 2.00, 0.02, 0 }, { 130, 3.50, 0.05, 0 }, { 24, 1.000, 0.005, 1 }, /* semiminor ticks */ { 200, 2.000, 0.010, 1 }, { 120, 1.000, 0.001, 2 }, /* minor ticks */ { 440, 1.120, 0.002, 2 }, { 400, 2.000, 0.005, 2 }, { 600, 4.000, 0.010, 2 }, { 1, 10.000, 0.000, 3 }, /* final "overflow" tick */ }; /* * draw a complete log scale */ void scale(int dir) { int i,b; printf("0.076 setlinewidth\n"); for (i=0; i