51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from PIL import Image
|
|
import numpy as np
|
|
from turtle import *
|
|
|
|
class programm():
|
|
def __init__(self):
|
|
pass
|
|
|
|
|
|
class LoadImage():
|
|
def __init__(self, src:str=""):
|
|
self.src = src
|
|
self.turtl()
|
|
|
|
def turtl(self):
|
|
image_array=self.load(src=self.src)
|
|
t = Turtle()
|
|
tracer(0)
|
|
t.pensize(1.1)
|
|
t.speed(0)
|
|
|
|
begin_fill()
|
|
t.penup()
|
|
for y,i in enumerate(image_array):
|
|
for x,j in enumerate(i):
|
|
|
|
if j == True:
|
|
|
|
continue
|
|
else:
|
|
t.goto(x,-y)
|
|
t.dot()
|
|
continue
|
|
update()
|
|
end_fill()
|
|
done()
|
|
|
|
def load(self, src:str):
|
|
new_size=(450,450)
|
|
threshold = 210
|
|
image_op = Image.open(src).convert("L")
|
|
image = image_op.point(lambda x: 255 if x > threshold else 0).convert('1')
|
|
image = image.convert('1')
|
|
image = image.resize(new_size, resample=Image.BOX)
|
|
|
|
image_array = np.array(image)
|
|
|
|
image.save("/home/jze9/Документы/git/acmp/turtle/save8.png")
|
|
return image_array
|
|
|
|
LoadImage(src="/home/jze9/Документы/git/acmp/turtle/test2.png") |