因此,我可以保存一个大图形并在图像可视化器中查看其完整大小,然后将乌龟窗口的大小调整为大于监视器大小。但是保存的图像没有调整大小,因此图形被截断了:
from turtle import Screen, Turtle
import random
screen = Screen()
screen.setup(width=1200, height=2700, startx=None, starty=None)
t = Turtle(visible=False)
t.speed('fastest') # because I have no patience
t2 = Turtle(visible=False)
t2.speed('fastest') # because I have no patience
t3 = Turtle(visible=False)
t3.speed('fastest') # because I have no patience
def got(x, y, d): # to use goto more easily
t.penup()
t.goto(x, y)
t.pendown()
t.seth(d)
def flatoval(r): # Horizontal Oval
t.right(45)
for loop in range(2):
t.circle(r, 90)
t.circle(r / 2, 90)
got(0, -200, 0)
def elipse(r, a, b, c):
for extent in range(9):
rnd = random.randint(1, 20)
# if extent == 0 or extent == 3 or extent == 6 :
# t.color('red')
# if extent == 1 or extent == 4 or extent == 7 :
# t.color('yellow')
# if extent == 2 or extent == 5 or extent == 8 :
# t.color('blue')
t.circle(r, 10)
heading = t.heading()
if extent == 0 or extent == 1 or extent == 2:
# t.color('green')
t.setheading(0)
t.forward(rnd)
t.forward(a)
t.backward(rnd)
t.forward(c)
t.setheading(heading)
def canais(x, y, d, egnar):
for tog in range(egnar):
got(x, y, d)
elipse(100, 0, 0, 0)
elipse(50, 0, 0, 0)
elipse(100, 0, 0, 0)
elipse(50, 0, 0, 0)
d = d + 10
elipse(200, 0, 0, 0)
elipse(100, 0, 0, 0)
elipse(200, 0, 0, 0)
elipse(100, 0, 0, 0)
elipse(300, 0, 0, 0)
elipse(200, 0, 0, 0)
elipse(300, 0, 0, 0)
elipse(200, 0, 0, 0)
canais(0, -100, 0, 40)
ts = t.getscreen()
ts.getcanvas().postscript(file="canais_organizados_separadamente.eps")
我也尝试了此更改:
screen = Screen()
screen.setup(width=1200, height=2700, startx=None, starty=None)
代替:
screen = Screen()
screen.setup(400, 500)
截断的图片:
答案 0 :(得分:3)
默认情况下,tkinter canvas postscript()
方法仅捕获画布的 visible 部分。您需要通过width
和height
参数来告诉它是否想要更多。下面是使用该修复程序和其他几个代码进行的改进,以提高性能和/或简化逻辑:
from turtle import Screen, Turtle
from random import randint
def got(x, y, d): # to use goto more easily
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.setheading(d)
def flatoval(r): # Horizontal Oval
turtle.right(45)
for _ in range(2):
turtle.circle(r, 90)
turtle.circle(r / 2, 90)
def elipse(r, a, b, c):
for extent in range(9):
rnd = randint(1, 20)
turtle.circle(r, 10)
heading = turtle.heading()
if extent <= 2:
turtle.setheading(0)
turtle.forward(rnd)
turtle.forward(a)
turtle.backward(rnd)
turtle.forward(c)
turtle.setheading(heading)
def canais(x, y, d, egnar):
for _ in range(egnar):
got(x, y, d)
elipse(100, 0, 0, 0)
elipse(50, 0, 0, 0)
elipse(100, 0, 0, 0)
elipse(50, 0, 0, 0)
elipse(200, 0, 0, 0)
elipse(100, 0, 0, 0)
elipse(200, 0, 0, 0)
elipse(100, 0, 0, 0)
elipse(300, 0, 0, 0)
elipse(200, 0, 0, 0)
elipse(300, 0, 0, 0)
elipse(200, 0, 0, 0)
d += 10
screen = Screen()
screen.setup(1200, 1200)
turtle = Turtle(visible=False)
got(0, -200, 0)
screen.tracer(False)
canais(0, -100, 0, 36)
screen.tracer(True)
canvas = screen.getcanvas()
canvas.postscript(file="canais_organizados_separadamente.eps", width=1200, height=1200)