making it pretty

This commit is contained in:
iou1name 2018-03-21 11:33:32 -04:00
parent fef2254f8c
commit 64b1b91f21
4 changed files with 44 additions and 17 deletions

View File

@ -1,6 +1,6 @@
Stupid bullshit to support my drawing machine. Stupid bullshit to support my drawing machine.
Dependencies: `pyserial, Pillow, nOBEX` Dependencies: `pyserial, Pillow, nOBEX`
nOBEX: https://github.com/nccgroup/nOBEX nOBEX: https://github.com/nccgroup/nOBEX
Linedraw: https://github.com/LingDong-/linedraw Linedraw: https://github.com/LingDong-/linedraw

View File

@ -24,9 +24,26 @@ F_Blur = {
(-2,1):4,(-1,1):9,(0,1):12,(1,1):9,(2,1):4, (-2,1):4,(-1,1):9,(0,1):12,(1,1):9,(2,1):4,
(-2,2):2,(-1,2):4,(0,2):5,(1,2):4,(2,2):2, (-2,2):2,(-1,2):4,(0,2):5,(1,2):4,(2,2):2,
} }
F_SobelX = {(-1,-1):1,(0,-1):0,(1,-1):-1,(-1,0):2,(0,0):0,(1,0):-2,(-1,1):1,(0,1):0,(1,1):-1} F_SobelX = {
F_SobelY = {(-1,-1):1,(0,-1):2,(1,-1):1,(-1,0):0,(0,0):0,(1,0):0,(-1,1):-1,(0,1):-2,(1,1):-1} (-1,-1): 1,
(0,-1): 0,
(1,-1): -1,
(-1,0): 2,
(0,0): 0,
(1,0): -2,
(-1,1): 1,
(0,1): 0,
(1,1): -1}
F_SobelY = {
(-1,-1): 1,
(0,-1): 2,
(1,-1): 1,
(-1,0): 0,
(0,0): 0,
(1,0): 0,
(-1,1): -1,
(0,1): -2,
(1,1): -1}
def appmask(IM,masks): def appmask(IM,masks):
PX = IM.load() PX = IM.load()
@ -48,7 +65,17 @@ def appmask(IM,masks):
def distsum(*args): def distsum(*args):
return sum([ ((args[i][0]-args[i-1][0])**2 + (args[i][1]-args[i-1][1])**2)**0.5 for i in range(1,len(args))]) """
Takes a list of pairs of points, finds the distance between each point
pair, and returns the sum of all distances.
"""
dists = []
for i in range(1, len(args):
a = args[i][0]-args[i-1][0]
b = args[i][1]-args[i-1][1]
dist = (a**2 + b**2)**0.5
dists.append(dist)
return sum(dists)
def sortlines(lines): def sortlines(lines):
@ -117,7 +144,8 @@ def getdots(IM):
row.append((x,0)) row.append((x,0))
dots.append(row) dots.append(row)
return dots return dots
def connectdots(dots): def connectdots(dots):
print("connecting contour points...") print("connecting contour points...")
contours = [] contours = []
@ -183,7 +211,6 @@ def getcontours(IM,sc=2):
for i in range(0,len(contours)): for i in range(0,len(contours)):
for j in range(0,len(contours[i])): for j in range(0,len(contours[i])):
# contours[i][j] = int(contours[i][j][0]+10*perlin.noise(i*0.5,j*0.1,1)),int(contours[i][j][1]+10*perlin.noise(i*0.5,j*0.1,2))
contours[i][j] = int(contours[i][j][0]+10),int(contours[i][j][1]+10) contours[i][j] = int(contours[i][j][0]+10),int(contours[i][j][1]+10)
return contours return contours
@ -226,25 +253,25 @@ def hatch(IM,sc=16):
for i in range(0,len(lines)): for i in range(0,len(lines)):
for j in range(0,len(lines[i])): for j in range(0,len(lines[i])):
print(perlin.noise(i*0.5,j*0.1,1))
#lines[i][j] = int(lines[i][j][0]+sc*perlin.noise(i*0.5,j*0.1,1)),int(lines[i][j][1]+sc*perlin.noise(i*0.5,j*0.1,2))-j
lines[i][j] = int(lines[i][j][0]+sc),int(lines[i][j][1]+sc)-j lines[i][j] = int(lines[i][j][0]+sc),int(lines[i][j][1]+sc)-j
return lines return lines
def sketch(path, resolution=1024, hatch_size=16, contour_simplify=2): def sketch(path, export_path=None, resolution=1024, hatch_size=16, contour_simplify=2):
image = Image.open(path) image = Image.open(path)
w,h = image.size
image = image.convert("L") image = image.convert("L")
image = ImageOps.autocontrast(image ,10) image = ImageOps.autocontrast(image ,10)
lines = [] lines = []
if draw_contours: if draw_contours:
width = int(resolution/contour_simplify)
lines += getcontours(image.resize((int(resolution/contour_simplify), int(resolution/contour_simplify*h/w))), contour_simplify) height = int(resolution/contour_simplify*image.size[0]/image.size[1])
lines += getcontours(image.resize((width, height)), contour_simplify)
if draw_hatch: if draw_hatch:
lines += hatch(image.resize((int(resolution/hatch_size), int(resolution/hatch_size*h/w))), hatch_size) width = int(resolution/hatch_size)
height = int(resolution/hatch_size*image.size[0]/image.size[1])
lines += hatch(image.resize((width, height)), hatch_size)
lines = sortlines(lines) lines = sortlines(lines)
@ -370,5 +397,5 @@ if __name__ == "__main__":
draw_contours = not args.no_contour draw_contours = not args.no_contour
no_cv = args.no_cv no_cv = args.no_cv
sketch(args.input, args.resolution, args.contour_simplify, args.hatch_size) sketch(args.input, args.output, args.resolution, args.contour_simplify, args.hatch_size)

View File

@ -9,7 +9,7 @@ import signal
import traceback import traceback
from threading import Thread from threading import Thread
from servers.opp import OPPServer from opp import OPPServer
def thread_serve(serv_class, arg): def thread_serve(serv_class, arg):
t = Thread(target=serve, args=(serv_class, arg), daemon=True) t = Thread(target=serve, args=(serv_class, arg), daemon=True)