Debian Codegraph @

docs/_sources/examples/22-events/06-randoms.rst.txt

raw
1 06-randoms.py - Exploring random generators.
2 ============================================================================================================================================
3
4
5 This example presents two more generators that randomly choose values.
6
7 **EventChoice** ::
8
9 EventChoice(values, occurrences=inf, stopEventsWhenDone=True)
10
11 EventChoice randomly pick a new value in a list of possible values.
12
13 **EventDrunk** ::
14
15 EventDrunk(values, maxStep=2, occurrences=inf, stopEventsWhenDone=True)
16
17 EventDrunk performs a random walk over a list of values. The 'maxStep'
18 argument determine the larger step in the list the walk can do between
19 two successive events. A negative 'maxStep' is the same but repetition
20 are not allowed.
21
22 .. code-block:: python
23
24 from pyo import *
25
26 s = Server().boot()
27
28 scl = [5.00, 5.02, 5.03, 5.05, 5.07, 5.08, 5.10, 6.00, 6.02, 6.03, 6.05, 6.07]
29
30 # Random walk for the melody.
31 e1 = Events(
32 degree=EventDrunk(scl, maxStep=-2), beat=1 / 4.0, db=-6, attack=0.001, decay=0.05, sustain=0.5, release=0.005,
33 ).play()
34
35 # Choose randomly for the bass.
36 e2 = Events(
37 degree=EventChoice(scl), beat=1, db=-6, transpo=-12, attack=0.001, decay=0.05, sustain=0.5, release=0.005,
38 ).play()
39
40 s.gui(locals())
41