I got curious and wondered if I could have the pyautogui module detect the color from every few pixels from an image and have turtle recreate them in it's canvas using small circles. I ended up finding a way to make it work, and I liked how the images were turning out! The only issue with my code is that it takes a while to finish. Depending on the size of the image, it can take almost 10-30 minutes to finish. Is there any way to optimize my code? I'm fairly new and have been experimenting with different modules, so I'd greatly appreciate any advice or help! If you need me to clarify anything, I'd be happy too
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 in turtle so they match.
def circle():
t.pd()
t.begin_fill()
t.circle(2.9)
t.end_fill()
t.pu()
screenshot = pyautogui.screenshot()
while x != max_x and y != max_y:
coordinate = x, y
color = screenshot.getpixel(coordinate)
t.pencolor(color)
t.fillcolor(color)
turtlemove(x, y)
circle()
if x < max_x:
x += 6
else:
x = min_x
y += 6
#if y >= max_y:
#break
print(t.pos())
wn.exitonclick()