小编Jam*_*m_T的帖子

Python - 海龟重新创建图像太慢

我很好奇,想知道是否可以让 pyautogui 模块检测图像中每隔几个像素的颜色,并让海龟使用小圆圈在画布中重新创建它们。我最终找到了一种让它工作的方法,而且我喜欢图像的效果!我的代码唯一的问题是需要一段时间才能完成。根据图像的大小,可能需要将近 10-30 分钟才能完成。有什么办法可以优化我的代码吗?我是新手,一直在尝试不同的模块,所以我非常感谢任何建议或帮助!如果你需要我澄清什么,我也很高兴这花了大约 30 分钟?

import time
import turtle
import pyautogui

time.sleep(2)
minimum = pyautogui.position()
print(minimum)
time.sleep(2)
max_x, max_y = pyautogui.position()
print(max_x, max_y)#I use the first point as the top left corner, and the second as the bottom right.

wn = turtle.Screen()
t = turtle.Turtle()
wn.colormode(255)#Allows RGB colors
t.pensize(2)
t.speed(0)
wn.setup(width = 1.0, height = 1.0)
wn.bgcolor("black")
x, y = minimum
min_x, min_y = minimum

def turtlemove(x, y):
    t.pu()
    t.goto(x - 965, 565 - y)#Compared coordinates in pyautogui with positions …
Run Code Online (Sandbox Code Playgroud)

python turtle-graphics python-3.x pyautogui python-turtle

5
推荐指数
1
解决办法
185
查看次数