ESP32 Code zur Laser-Steuerung
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.8KB

  1. #!/usr/bin/env python
  2. from svg.path import parse_path
  3. from xml.dom import minidom
  4. import pygame
  5. SVGFILE = 'hacKNology_nurlogo_klein_notran.svg'
  6. CFILE = 'logo.h'
  7. # Define the colors we will use in RGB format
  8. BLACK = (0, 0, 0)
  9. WHITE = (255, 255, 255)
  10. BLUE = (0, 0, 255)
  11. GREEN = (0, 255, 0)
  12. RED = (255, 0, 0)
  13. if __name__ == '__main__':
  14. with open(SVGFILE) as f:
  15. doc = minidom.parse(f)
  16. path_strings = [path.getAttribute('d') for path in doc.getElementsByTagName('path')]
  17. doc.unlink()
  18. print(path_strings)
  19. lines = []
  20. minx, miny, maxx, maxy = None, None, None, None
  21. for pathstr in path_strings:
  22. obj = parse_path(pathstr)
  23. line = []
  24. for seg in obj:
  25. print(seg.start, seg.end)
  26. x1, y1 = seg.start.real, seg.start.imag
  27. x2, y2 = seg.end.real, seg.end.imag
  28. line.append([x1, y1, x2, y2])
  29. if minx is None or x1 < minx:
  30. minx = x1
  31. if minx is None or x2 < minx:
  32. minx = x2
  33. if miny is None or y1 < miny:
  34. miny = y1
  35. if miny is None or y2 < miny:
  36. miny = y2
  37. if maxx is None or x1 > maxx:
  38. maxx = x1
  39. if maxx is None or x2 > maxx:
  40. maxx = x2
  41. if maxy is None or y1 > maxy:
  42. maxy = y1
  43. if maxy is None or y2 > maxy:
  44. maxy = y2
  45. lines.append(line)
  46. for line in lines:
  47. for seg in line:
  48. seg[0], seg[1], seg[2], seg[3] = (seg[0] - minx) / (maxx - minx), (seg[1] - miny) / (maxy - miny), (
  49. seg[2] - minx) / (maxx - minx), (seg[3] - miny) / (maxy - miny)
  50. print(lines)
  51. with open(CFILE, 'w') as f:
  52. f.write('#ifndef __LOGO_H\n')
  53. f.write('#define __LOGO_H\n\n')
  54. f.write('const float logo[] = {')
  55. lengths = []
  56. linestrs = []
  57. for line in lines:
  58. segstrs = []
  59. for seg in line:
  60. segstrs.append("%f,%f,%f,%f" % (seg[0], seg[1], seg[2], seg[3],))
  61. lengths.append("%d" % len(line))
  62. linestrs.append(",".join(segstrs))
  63. f.write(",".join(linestrs))
  64. f.write("};\n")
  65. f.write('const int logo_lines[] = {')
  66. f.write(",".join(lengths))
  67. f.write(",0};\n")
  68. f.write('\n#endif')
  69. pygame.init()
  70. size = [400, 300]
  71. screen = pygame.display.set_mode(size)
  72. pygame.display.set_caption("Example code for the draw module")
  73. clock = pygame.time.Clock()
  74. done = False
  75. while not done:
  76. clock.tick(10)
  77. screen.fill(WHITE)
  78. for line in lines:
  79. for seg in line:
  80. pygame.draw.line(screen, GREEN, [seg[0]*400,seg[1]*300], [seg[2]*400, seg[3]*300], 5)
  81. pygame.display.flip()