Guest User

Untitled

a guest
Dec 11th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import Image
  2.  
  3.  
  4. def getpix(img, r, g=0, b=0):
  5. ret = []
  6. sizex, sizey = img.size
  7. for x in range(sizex):
  8. for y in range(sizey):
  9. _r, _g, _b, _a = img.getpixel((x, y))
  10. if _r == r and _g == g and _b == b:
  11. ret.append((x, y))
  12. return ret
  13.  
  14.  
  15. def getstroke(imgfile='picture.png', outfile='stroke.java'):
  16. img = Image.open(imgfile)
  17. outf = open(outfile, 'w')
  18. for b in range(5, 256, 5):
  19. lst = sorted(getpix(img, r=0,g=0,b=b))
  20. if len(lst) == 0:
  21. continue
  22. outf.write('path = new Path();\n')
  23. outf.write('this.paths.add(path);\n')
  24. first = True
  25. for ele in lst:
  26. if first:
  27. func = 'moveTo'
  28. first = False
  29. else:
  30. func = 'lineTo'
  31. outf.write('path.{0}({1}f, {2}f);\n'.format(func, ele[0], ele[1]))
  32. outf.write('\n')
  33. outf.close()
Add Comment
Please, Sign In to add comment