Re: Uniform scaling with gdisplay
Bruce Sherwood <[email protected]> Sat, 13 Oct 2012 16:59:34 -0600
| Newsgroups | gmane.comp.python.visualpython.user |
|---|---|
| Message-ID | <CAFDG03hsmVFsnpTPmvs=rmXgnx-O+8VBb3LA5Kqo39a+0c6yGg@mail.gmail.com> |
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
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev