MCPcopy Create free account
hub / github.com/geekcomputers/Python / generateClosedPolygons

Method generateClosedPolygons

floodfill/floodfill.py:25–54  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

23 self.queue = []
24
25 def generateClosedPolygons(self):
26 if self.window_height < 128 or self.window_width < 128:
27 return # surface too small
28
29 from random import randint, uniform
30 from math import pi, sin, cos
31
32 for n in range(0, randint(0, 5)):
33 x = randint(50, self.window_width - 50)
34 y = randint(50, self.window_height - 50)
35
36 angle = 0
37 angle += uniform(0, 0.7)
38 vertices = []
39
40 for i in range(0, randint(3, 7)):
41 dist = randint(10, 50)
42 vertices.append(
43 (int(x + cos(angle) * dist), int(y + sin(angle) * dist))
44 )
45 angle += uniform(0, pi / 2)
46
47 for i in range(0, len(vertices) - 1):
48 pygame.draw.line(
49 self.surface, (255, 0, 0), vertices[i], vertices[i + 1]
50 )
51
52 pygame.draw.line(
53 self.surface, (255, 0, 0), vertices[len(vertices) - 1], vertices[0]
54 )
55
56 def run(self):
57 looping = True

Callers 1

__init__Method · 0.95

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected