Turtle Graphics are incompatible with gmpy
Mensanator
mensanator at aol.com
Wed Aug 5 18:31:17 EDT 2009
I fixed this to produce the actual image I'm looking
for instead of that stupid black square. All I did was
use up() & dowm() in place of penup(), pendown() and
replace dot(2) with forward(1).
I'll be posting a followup report later.
import gmpy
## (even) hi----|
## |
## lo (odd)
## or
##
## (even) lo
## |
## |
## ----hi (odd)
##
##
##
##
import turtle
tooter = turtle.Turtle()
#tooter.hideturtle()
tooter.speed('fast')
#turtle.update()
tooter.tracer(False)
#tooter.penup()
tooter.up()
tooter.color('black')
s = ['1','0']
while len(s[0])<10000:
s = [''.join(s), s[0]]
origin = [0,0]
if s[0] == '0':
tooter.goto(origin)
#tooter.dot(1)
tooter.down()
tooter.forward(1)
tooter.up()
if s[1] == '0':
tooter.goto([1,0])
#tooter.dot(1)
tooter.down()
tooter.forward(1)
tooter.up()
print len(s[0])
for i,j in enumerate(s[0]):
the_coord=[]
cur_root = gmpy.sqrt(i)
lo__root = gmpy.sqrt(i)**2
hi__root = (gmpy.sqrt(i)+1)**2
if hi__root%2==0:
side = 'northeast'
else:
side = 'southwest'
elbow = (hi__root - lo__root)/2 + lo__root + 1
if i>= elbow:
side_len = i - elbow
elbow_plus = True
else:
side_len = elbow - i
elbow_plus = False
if side == 'northeast':
elbow_offset = [(gmpy.sqrt(elbow)-1)/2 +1,-((gmpy.sqrt(elbow)-1)/2
+1)]
else:
elbow_offset = [-((gmpy.sqrt(elbow)-1)/2 +1),((gmpy.sqrt(elbow)-1)/
2 +1)]
elbow_coord = [origin[0]+elbow_offset[0],origin[1]+elbow_offset[1]]
if i != hi__root and i != lo__root:
if i == elbow:
the_coord = elbow_coord
else:
if elbow_plus:
if side == 'northeast':
the_coord = [elbow_coord[0]-side_len,elbow_coord[1]]
else:
the_coord = [elbow_coord[0]+side_len,elbow_coord[1]]
else:
if side == 'northeast':
the_coord = [elbow_coord[0],elbow_coord[1]+side_len]
else:
the_coord = [elbow_coord[0],elbow_coord[1]-side_len]
else:
if i % 2 == 0: # even square
n = gmpy.sqrt(i)/2 - 1
the_coord = [-n, -n-1]
else:
n = (gmpy.sqrt(i)-1)/2 - 1
the_coord = [1+n, 1+n]
if j == '0':
tooter.goto(the_coord)
#tooter.dot(2)
tooter.down()
tooter.forward(1)
tooter.up()
print 'done'
#turtle.update()
turtle.done()
print 'done'
More information about the Python-list
mailing list