调整和保存海龟屏幕时出现问题

2021-12-08 06:16:28 发布

您现在位置:Python中文网/ 问答频道 /正文

为了保存一幅大图,并在图像可视化工具中看到它的全尺寸,我调整了海龟窗口的大小,使其大于显示器的大小。但保存的图像不会调整大小,因此图形将被截断:

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)

截断图像:

cutted image