Skip to content

Commit 4615e79

Browse files
authored
making code clearer
1 parent b0566be commit 4615e79

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

img_to_thread.py

+12-25
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
from PIL import Image, ImageOps
22
from xiaolinWusLineAlgorithm import draw_line
3-
from queue import PriorityQueue
43
import numpy as np
54

6-
75
class StringArt:
8-
def __init__(self, nails, input_image, thickness=2):
6+
def __init__(self, nails, input_image, resolution=0.7):
97
if type(input_image) == str:
108
self.image = self.load_image(input_image)
119
else:
1210
self.image = input_image
13-
self.scale = 1-(thickness-1)/self.image.width
11+
self.scale = resolution
1412
self.image = self.image.resize((round(self.image.width*self.scale), round(self.image.height*self.scale)), Image.Resampling.LANCZOS)
1513
self.nails = nails
1614
self.radius = min(self.image.height, self.image.width)*0.49
@@ -30,46 +28,35 @@ def nailToCoordinate(self, nail):
3028
def getLine(self, start, end):
3129
p0 = self.nailToCoordinate(start)
3230
p1 = self.nailToCoordinate(end)
33-
if p1==p0:
34-
return 2000
3531
sum = [0.0, 0.1]
3632
def pixel(img, p, color, alpha_correction, transparency):
3733
sum[0] += transparency*img.getpixel(p)
3834
sum[1] += transparency
3935
draw_line(self.image, p0, p1, 0, 1.0, pixel)
4036
return sum[0]/sum[1]
4137

42-
def drawLine(self, start, end, color=200, alpha_correction=1):
38+
def drawLine(self, start, end, color=200, alpha_correction=1, function=None):
4339
p0 = self.nailToCoordinate(start)
4440
p1 = self.nailToCoordinate(end)
45-
draw_line(self.image, p0, p1, color, alpha_correction)
41+
if function is None:
42+
draw_line(self.image, p0, p1, color, alpha_correction)
43+
else:
44+
draw_line(self.image, p0, p1, color, alpha_correction, function)
4645
self.operations.append((start, end))
4746

48-
def tryChange(self, start, end, color=200, alpha_correction=1):
47+
def tryChange(self, start, end, color=200, alpha_correction=1, function=None):
4948
self.pending_img = self.image.copy()
50-
p0 = self.nailToCoordinate(start)
51-
p1 = self.nailToCoordinate(end)
52-
draw_line(self.pending_img, p0, p1, color, alpha_correction)
49+
draw_line(self.pending_img, start, end, color, alpha_correction, function)
5350
self.pending_operation = (start,end)
5451

5552
return self.pending_img
5653

5754
def acceptChange(self):
5855
self.image = self.pending_img
5956
self.operations.append(self.pending_operation)
60-
61-
def printOperations(self, file=None):
62-
pass
63-
57+
6458
def invert(self):
6559
self.image = ImageOps.invert(self.image)
66-
6760

68-
69-
def random_pattern(nails, thread):
70-
import random
71-
print(nails)
72-
for i in range(thread):
73-
a = random.randint(0,nails)
74-
b = random.randint(0,nails)
75-
print(f"{a} {b}")
61+
def printOperations(self, file=None):
62+
pass # TODO implement

0 commit comments

Comments
 (0)