-
Notifications
You must be signed in to change notification settings - Fork 1
/
rn_utils.py
62 lines (49 loc) · 1.4 KB
/
rn_utils.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
50
51
52
53
54
55
56
57
58
59
60
61
62
def pick_one(_lst):
""" randomly picks one from a list of items """
return _lst[int(random(len(_lst)))]
def shuffle(_lst):
n = len(_lst)
for i in range(0, n - 2):
j = int(random(i, n))
_lst[i], _lst[j] = _lst[j], _lst[i]
return _lst
def display_grid_points(x_margin, y_margin, num_rows, num_cols, sep):
for row in range(num_rows):
for col in range(num_cols):
x = x_margin + sep * col
y = y_margin + sep * row
ellipse(x, y, 3, 3)
def keyPressed():
global show
if key == "n":
circles = []
elif key == "t": # Toggle
show = not show
elif key == CODED and keyCode == CONTROL:
saveFrame("screenshot.png")
elif key == ENTER:
if msg:
t = Texto(msg)
elif key == "f": # freeze
noLoop()
elif key == "r": # resume
loop()
elif key == "g": # inch forward - slo motion
redraw()
def frange(start, stop=None, step=None):
# if stop and step argument is None set start=0.0 and step = 1.0
start = float(start)
if stop == None:
stop = start + 0.0
start = 0.0
if step == None:
step = 1.0
count = 0
while True:
temp = float(start + count * step)
if step > 0 and temp >= stop:
break
elif step < 0 and temp <= stop:
break
yield temp
count += 1