Python Turtle 绘图偏心

问题描述 投票:0回答:0

我写了以下代码:

import turtle

t = turtle.Turtle()
t.speed(0)
t._delay(0)

screen = turtle.Screen()
screen.colormode(255)


BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)

IMG_WIDTH = 8
IMG_HEIGHT = 8

TILE_SIZE = 32

image = [[2,0,0,0,0,0,0,2],
         [0,2,0,2,2,0,2,0],
         [0,0,2,3,3,2,0,0],
         [4,4,1,2,2,1,4,4],
         [3,0,0,4,4,0,0,3],
         [3,0,0,4,4,0,0,3],
         [3,0,0,4,4,0,0,3],
         [2,0,0,3,3,0,0,2]]

COLOR_DICTIONARY = { 0 : BLACK,
                     1 : WHITE,
                     2 : RED,
                     3 : BLUE,
                     4 : GREEN}


for y in range(0,IMG_HEIGHT):
  for x in range(0,IMG_WIDTH):
    t.color(COLOR_DICTIONARY.get(image[y][x]))
    t.fillcolor(COLOR_DICTIONARY.get(image[y][x]))
    t.goto(x*TILE_SIZE, -y*TILE_SIZE)
    t.begin_fill()

    for i in range(4):
      t.pendown()
      t.forward(TILE_SIZE)
      t.right(90)
      t.penup()

    t.end_fill()

当我运行这段代码时,绘图偏离了中心,其中一半不在屏幕上。我的代码有问题吗?

绘图: (https://i.stack.imgur.com/pbuTP.png)

我不确定该怎么做才能解决这个问题,因为我不知道该怎么做,所以尝试弄乱图像网格。

python turtle-graphics python-turtle
© www.soinside.com 2019 - 2024. All rights reserved.