-
Notifications
You must be signed in to change notification settings - Fork 0
/
Astroid.py
34 lines (26 loc) · 825 Bytes
/
Astroid.py
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
from random import randint, random
from math import pi, cos, sin
class Astroid:
def __init__(self, x, y, size):
self.x = x
self.y = y
self.size = size
dir = random() * 2 * pi
sp = mapFromTo(random(), 0.0, 1.0, 1.0, 3)
self.vel = [cos(dir) * sp, sin(dir) * sp]
def move(self):
self.x += self.vel[0]
self.y += self.vel[1]
def split(self):
self.size -= 1
if self.size == 0:
return None
else:
dir = random() * 2 * pi
sp = mapFromTo(random(), 0.0, 1.0, 1.0, 2)
self.vel = [cos(dir) * sp, sin(dir) * sp]
a = Astroid(self.x, self.y, self.size)
return a
def mapFromTo(x, a, b, c, d):
y = (x - a) / (b - a) * (d - c) + c
return y