-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhythm.py
49 lines (36 loc) · 1.29 KB
/
rhythm.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import random
from data import Data
class Rhythm:
def getMinRhythm(measure):
return Data.rhythm_atomic[-1] / measure[1] * measure[0]
def calcSpaceWhenString(item):
number = ""
for v in item:
if v.isdigit():
number += v
result = (Data.rhythm_atomic[-1] / int(number)) + Data.rhythm_atomic[-1] / (int(number)*2)
return result
def calcSpace(r, space):
tam = 0.0
fits = False
if isinstance(r, list):
for item in r:
if isinstance(item, str):
tam += int(Rhythm.calcSpaceWhenString(item))
else:
tam += Data.rhythm_atomic[-1] / item
else:
tam += Data.rhythm_atomic[-1] / r
if (space - tam) >= 0.0:
fits = True
return fits, tam
def getRhythm(space: float):
correct = False
while(correct!= True):
selection = random.random()
if selection>0.4:
r = Data.rhythm_cells[random.randint(0, len(Data.rhythm_cells)-1)]
else:
r = Data.rhythm_atomic[random.randint(0, len(Data.rhythm_atomic)-1)]
correct, tam = Rhythm.calcSpace(r, space)
return r, tam