|
From: Bruce S. <Bru...@nc...> - 2012-10-13 22:59:41
|
The easiest way to achieve autoscaling with x and y scales equal is to
not use graphing. Here is the basic idea:
from __future__ import division, print_function
from visual import *
scene.title = 'Spiral'
scene.width = scene.height = 800
scene.background = color.white
scene.foreground = color.black
scale = 1
xaxis = curve(pos=[(-scale,0),(scale,0)], color=color.gray(.5))
yaxis = curve(pos=[(0,-scale),(0,scale)], color=color.gray(.5))
xlabel = label(pos=(0.95*scale,-0.05*scale), text='x', box=0)
ylabel = label(pos=(0.05*scale,0.95*scale), text='y', box=0)
p = points(color=color.blue)
kr = 1
kt = 1
t = 0
dt = pi/360
while True:
rate(1000)
r = kr*t
theta = kt*t
x = r*cos(theta)
y = r*sin(theta)
t += dt
m = max([x,y])
if m > scale:
scale = 1.05*m
xlabel.pos = (0.95*scale,-0.05*scale)
ylabel.pos = (0.05*scale,0.95*scale)
xaxis.pos = [(-scale,0),(scale,0)]
yaxis.pos = [(0,-scale),(0,scale)]
p.append(pos=(x,y))
You could also include in the x and y labels the value of "scale".
Bruce Sherwood
|