Skip to content

Instantly share code, notes, and snippets.

@cloverrose
Created August 28, 2012 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloverrose/3494505 to your computer and use it in GitHub Desktop.
Save cloverrose/3494505 to your computer and use it in GitHub Desktop.
import Image
def getpix(img, r, g=0, b=0):
ret = []
sizex, sizey = img.size
for x in range(sizex):
for y in range(sizey):
_r, _g, _b, _a = img.getpixel((x, y))
if _r == r and _g == g and _b == b:
ret.append((x, y))
return ret
def getstroke(imgfile='picture.png', outfile='stroke.java'):
img = Image.open(imgfile)
outf = open(outfile, 'w')
for b in range(5, 256, 5):
lst = sorted(getpix(img, r=0,g=0,b=b))
if len(lst) == 0:
continue
outf.write('path = new Path();\n')
outf.write('this.paths.add(path);\n')
first = True
for ele in lst:
if first:
func = 'moveTo'
first = False
else:
func = 'lineTo'
outf.write('path.{0}({1}f, {2}f);\n'.format(func, ele[0], ele[1]))
outf.write('\n')
outf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment