-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaw.py
35 lines (29 loc) · 828 Bytes
/
saw.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
import itertools
class saw:
"""provides a sawtooth waveform."""
def __init__(self, scale=1, steps=100, pos=True):
self.scale = scale
self.steps = steps
self.stepval = self.scale / float(self.steps)
self.num = 0
self.stepn = 0
if pos:
self.pos = 0
else:
self.pos = -self.steps
self.up = True
def step(self):
self.num = self.stepn * self.stepval
if self.stepn == self.steps:
self.up = False
elif self.stepn == self.pos:
self.up = True
if self.up:
self.stepn += 1
else:
self.stepn -= 1
return self.num
if(__name__ == "__main__"):
test = saw(10, 40, False)
for _ in itertools.repeat(None, 200):
print(test.step())