circular slide rule
Will Ware
wware at world.std.com
Tue Jun 13 13:03:25 EDT 2000
"""This generates a Postscript file, which when printed on
an 8.5x11 sheet of paper, gives you a circular slide rule.
Without the transparent slider, it's probably a lot less useful
than a log table, but there may be some nostalgic fun in here
for somebody."""
import sys, math
center = (72 * 4.25, 72 * 5.5)
def p2r(r, theta):
t = math.pi * theta / 180.
return (r * math.cos(t) + center[0],
r * math.sin(t) + center[1])
print '%!PS'
print '/Times-Roman findfont 10 scalefont setfont'
def axis(theta):
x1, y1 = p2r(0, theta)
x2, y2 = p2r(72 * 4, theta)
print '%g %g moveto %g %g lineto stroke' % (x1, y1, x2, y2)
def span(xlim, dx, n):
global x
i = 0
while x + 1.e-8 < xlim:
nextx = x + dx
if i == 0:
label = '%.3g' % x
gap = 4
else:
label = ''
gap = 2
L1 = math.log10(x)
L2 = math.log10(nextx)
r1 = (72 * 3.5) - L1 * (72 * 1)
r2 = (72 * 3.5) - L2 * (72 * 1)
th1 = 720 * L1
th2 = 720 * L2
x1, y1 = p2r(r1, th1)
x2, y2 = p2r(r2, th2)
x3, y3 = p2r(r1 + gap, th1)
x4, y4 = p2r(r1 - gap, th1)
print '%g %g moveto gsave %g rotate' % (x3, y3, th1)
print '( %s) show grestore' % (label)
print '%g %g moveto %g %g lineto stroke' % (x1, y1, x2, y2)
print '%g %g moveto %g %g lineto stroke' % (x3, y3, x4, y4)
x = nextx
i = (i + 1) % n
def magnitude():
x0 = x
span(1.5 * x0, .005 * x0, 4)
span(2 * x0, .01 * x0, 5)
span(4 * x0, .01 * x0, 10)
span(7 * x0, .02 * x0, 5)
span(10. * x0, .05 * x0, 5)
print '.7 setgray'
for i in range(36):
axis(i * 10)
print '0 setgray'
x = 1.
magnitude()
magnitude()
span(x + 0.00001, .001, 1)
print 'showpage'
--
- - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware email: wware @ world.std.com
More information about the Python-list
mailing list