-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfood.py
More file actions
35 lines (24 loc) · 823 Bytes
/
food.py
File metadata and controls
35 lines (24 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# PY5 IMPORTED MODE CODE
class Food:
def __init__(self, num: int):
"""Start with some food."""
self.food_positions = [
Py5Vector2D(random(width), random(height))
for _ in range(num)
]
def add(self, position: Py5Vector2D) -> None:
"""Add some food at a location."""
self.food_positions.append(position.copy)
def run(self) -> None:
"""Display the food."""
rect_mode(CENTER)
stroke(0)
stroke_weight(1)
fill(175)
for position in self.food_positions:
square(position.x, position.y, 8)
# There's a small chance food will appear randomly.
if random() < 0.001:
self.food_positions.append(Py5Vector2D(
random(width), random(height)
))