Skip to content

Instantly share code, notes, and snippets.

@pepgonzalez
Created April 25, 2013 05:53
Show Gist options
  • Save pepgonzalez/5457784 to your computer and use it in GitHub Desktop.
Save pepgonzalez/5457784 to your computer and use it in GitHub Desktop.
def genera_lineas(imagen, po, eje, fondo, tot = 100):
x,y = imagen.size
puntos = list()
if eje == "x":
if fondo == "negro":
for i in range(tot):
imagen = pintalinea((0, po[i][0]), (x, po[i][0]), imagen, (0,0,255), "x")
puntos.append(po[i][0])
elif fondo == "blanco":
for i in range(-tot-1, -1):
imagen = pintalinea((0, po[i][0]), (x, po[i][0]), imagen, (0,0,255), "x")
puntos.append(po[i][0])
else:
for i in range(tot):
imagen = pintalinea((0, po[i][0]), (x, po[i][0]), imagen, (0,0,255), "x")
puntos.append(po[i][0])
for i in range(-tot-1, -1):
imagen = pintalinea((0, po[i][0]), (x, po[i][0]), imagen, (0,0,255), "x")
puntos.append(po[i][0])
else:
if fondo == "negro":
for i in range(tot):
imagen = pintalinea((po[i][0], 0), (po[i][0], y), imagen, (0,255,0), "y")
puntos.append(po[i][0])
elif fondo == "blanco":
for i in range(-tot-1, -1):
imagen = pintalinea((po[i][0], 0), (po[i][0], y), imagen, (0,255,0), "y")
puntos.append(po[i][0])
else:
for i in range(tot):
imagen = pintalinea((po[i][0], 0), (po[i][0], y), imagen, (0,255,0), "y")
puntos.append(po[i][0])
for i in range(-tot-1, -1):
imagen = pintalinea((po[i][0], 0), (po[i][0], y), imagen, (0,255,0), "y")
puntos.append(po[i][0])
return imagen, puntos
def pintalinea(p1,p2,imagen, color, eje):
px = imagen.load()
try:
if eje == "x":
if px[0, p1[1]-1] != (0,0,255) and px[0, p1[1]+1] != (0,0,255):
draw = ImageDraw.Draw(imagen)
draw.line((p1, p2), fill=color)
else:
if px[(p1[0]-1,0)] != (0, 255, 0) and px[(p1[0]+1,0)] != (0, 255, 0):
draw = ImageDraw.Draw(imagen)
draw.line((p1, p2), fill= color)
except:
pass
return imagen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment