Developpement d'une application permettant de se réperer dans un batiment
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

svg_example.py 1.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from __future__ import division # we need floating division
  2. from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
  3. import pygame
  4. """ demo of using a great python module svg.path by Lennart Regebro
  5. see site: https://pypi.org/project/svg.path/
  6. to draw svg in pygame
  7. """
  8. from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
  9. svgpath = """m 76,232.24998 c 81.57846,-49.53502 158.19366,-20.30271 216,27 61.26714,
  10. 59.36905 79.86223,123.38417 9,156
  11. -80.84947,31.72743 -125.19991,-53.11474 -118,-91 v 0 """
  12. path = parse_path(svgpath)
  13. # svg.path point method returns a complex number p, p.real and p.imag can pull the x, and y
  14. # # on 0.0 to 1.0 along path, represent percent of distance along path
  15. n = 100 # number of line segments to draw
  16. # pts = []
  17. # for i in range(0,n+1):
  18. # f = i/n # will go from 0.0 to 1.0
  19. # complex_point = path.point(f) # path.point(t) returns point at 0.0 <= f <= 1.0
  20. # pts.append((complex_point.real, complex_point.imag))
  21. # list comprehension version or loop above
  22. pts = [ (p.real,p.imag) for p in (path.point(i/n) for i in range(0, n+1))]
  23. pygame.init() # init pygame
  24. surface = pygame.display.set_mode((700,600)) # get surface to draw on
  25. surface.fill(pygame.Color('white')) # set background to white
  26. pygame.draw.aalines( surface,pygame.Color('blue'), False, pts) # False is no closing
  27. pygame.display.update() # copy surface to display
  28. while True: # loop to wait till window close
  29. for event in pygame.event.get():
  30. if event.type == pygame.QUIT:
  31. exit()