from turtle import *
from time import sleep
from turtle import TurtleScreenBase
def _convertxy(self,x,y):
"""把角色的x,y坐标转换回画布原来以左上角为原点的坐标"""
x, y = x/self.xscale,-y/self.yscale
return x,y
TurtleScreenBase.convertxy = _convertxy
screen = Screen()
x1,y1 = screen.convertxy(-100,100)
x2,y2 = screen.convertxy(0,0)
def draw_rect(width,height,direction=1,fill=True,border=0):
if direction != 1:direction = -1
w2 = width/2
x1 = t.xcor() - w2
y1 = t.ycor() + height * direction
x2 = t.xcor() + w2
y2 = t.ycor()
x1,y1 = screen.convertxy(x1,y1)
x2,y2 = screen.convertxy(x2,y2)
if fill:
item = t.screen.cv.create_rectangle(x1,y1,x2,y2,width=border,fill=t.fillcolor())
else:
item = t.screen.cv.create_rectangle(x1,y1,x2,y2,width=border)
return item
t = Turtle()
t.color('blue','red')
r = draw_rect(50,100,-1,2,5)
canvas = t.screen.cv
for x in range(100):
canvas.move(r,1,0)
canvas.update()
sleep(0.01)
-
- 2026 年 2 月
- 2026 年 1 月
- 2025 年 12 月
- 2025 年 11 月
- 2025 年 10 月
- 2025 年 9 月
- 2025 年 6 月
- 2025 年 5 月
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 8 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 3 月
- 2024 年 2 月
- 2023 年 11 月
- 2023 年 9 月
- 2023 年 6 月
- 2023 年 5 月
- 2023 年 4 月
- 2023 年 3 月
- 2023 年 2 月
- 2023 年 1 月
- 2022 年 12 月
- 2022 年 11 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 2 月
- 2022 年 1 月
- 2021 年 12 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 8 月
- 2021 年 7 月
- 2021 年 6 月
- 2021 年 5 月
- 2021 年 4 月
- 2021 年 3 月
- 2021 年 2 月
- 2021 年 1 月
- 2020 年 12 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 9 月
- 2020 年 8 月
- 2020 年 7 月
- 2020 年 6 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 3 月
- 2020 年 2 月
- 2020 年 1 月
- 2019 年 12 月
- 2019 年 11 月
- 2019 年 10 月
- 2019 年 9 月
- 2019 年 8 月
- 2019 年 7 月
- 2019 年 6 月
- 2019 年 5 月
- 2019 年 4 月
- 2019 年 3 月
- 2019 年 2 月
- 2018 年 3 月
- 2018 年 1 月
- 2017 年 9 月
- 2017 年 5 月
- 2017 年 1 月
