From 64b1b91f21416f61ac3baf7f4256565d39023df1 Mon Sep 17 00:00:00 2001 From: iou1name Date: Wed, 21 Mar 2018 11:33:32 -0400 Subject: [PATCH] making it pretty --- README.md | 4 +-- linedraw.py | 55 ++++++++++++++++++++++++++++++---------- servers/opp.py => opp.py | 0 startBluetooth.py | 2 +- 4 files changed, 44 insertions(+), 17 deletions(-) rename servers/opp.py => opp.py (100%) diff --git a/README.md b/README.md index 2341537..57865a8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Stupid bullshit to support my drawing machine. Dependencies: `pyserial, Pillow, nOBEX` -nOBEX: https://github.com/nccgroup/nOBEX -Linedraw: https://github.com/LingDong-/linedraw +nOBEX: https://github.com/nccgroup/nOBEX +Linedraw: https://github.com/LingDong-/linedraw diff --git a/linedraw.py b/linedraw.py index 4cc0f85..8cee331 100644 --- a/linedraw.py +++ b/linedraw.py @@ -24,9 +24,26 @@ F_Blur = { (-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, } -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_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} - +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_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): PX = IM.load() @@ -48,7 +65,17 @@ def appmask(IM,masks): 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): @@ -117,7 +144,8 @@ def getdots(IM): row.append((x,0)) dots.append(row) return dots - + + def connectdots(dots): print("connecting contour points...") contours = [] @@ -183,7 +211,6 @@ def getcontours(IM,sc=2): for i in range(0,len(contours)): 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) return contours @@ -226,25 +253,25 @@ def hatch(IM,sc=16): for i in range(0,len(lines)): 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 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) - w,h = image.size image = image.convert("L") image = ImageOps.autocontrast(image ,10) lines = [] if draw_contours: - - lines += getcontours(image.resize((int(resolution/contour_simplify), int(resolution/contour_simplify*h/w))), contour_simplify) + width = int(resolution/contour_simplify) + height = int(resolution/contour_simplify*image.size[0]/image.size[1]) + lines += getcontours(image.resize((width, height)), contour_simplify) 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) @@ -370,5 +397,5 @@ if __name__ == "__main__": draw_contours = not args.no_contour 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) diff --git a/servers/opp.py b/opp.py similarity index 100% rename from servers/opp.py rename to opp.py diff --git a/startBluetooth.py b/startBluetooth.py index 10a5aa8..f6753cc 100755 --- a/startBluetooth.py +++ b/startBluetooth.py @@ -9,7 +9,7 @@ import signal import traceback from threading import Thread -from servers.opp import OPPServer +from opp import OPPServer def thread_serve(serv_class, arg): t = Thread(target=serve, args=(serv_class, arg), daemon=True)