Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
help with random chord
-
<pre>
import sound
from scene import *
from random import random
from random import choice
from colorsys import hsv_to_rgb
sound.load_effect('Boing_1')s1=['Piano_C3','Piano_E3','Piano_G3']
s2=['Piano_D3','Piano_F3','Piano_A3']
s3=['Piano_E3','Piano_G3','Piano_B3']
s4=['Piano_F3','Piano_A3','Piano_C4']
s5=['Piano_G3','Piano_B3','Piano_D4']
s6=['Piano_A3','Piano_C4','Piano_E4']
s7=['Piano_B3','Piano_D4','Piano_F4']########PROBLEM HERE########
random_note=['s1','s2','s3','s4','s5','s6','s7']class Particle (object):
def init(self, location):
self.location = locationclass Particles (Scene):
def setup(self):
self.show_instructions = True
self.particles = set()
self.p_size = 64 if self.size.w > 700 else 32def should_rotate(self, orientation): return True def touch_began(self, touch): if self.show_instructions: self.show_instructions = False particle = Particle(touch.location) self.particles.add(particle) sound.play_effect(choice(random_note))
########AND HERE########
def draw(self): background(1, 1, 1) if self.show_instructions: s = 40 if self.size.w > 700 else 17 text('Touch here.', 'Futura', s, *self.bounds.center().as_tuple()) dead = set() for particle in self.particles: s = 20 x, y = particle.location.as_tuple() image('Musical_Notes', x - s/2, y - s/2, s, s)
run(Particles())
</pre> -
Please enclose pasted code in <pre>...</pre> tags, otherwise the indentation isn't preserved (which is important in Python). An alternative would be to post a link to Gist, which can be done directly from Pythonista via "Export...".
I've inserted the tags for you here.
Also, please describe <em>what exactly</em> the problem is with the code you've posted.
-
Part of your problem is in this line:
<pre>random_note=['s1','s2','s3','s4','s5','s6','s7']</pre>
It should be like this instead:
<pre>random_note=[s1,s2,s3,s4,s5,s6,s7]</pre>
's1' = the string 's1'
s1 (no quotes) = the variable named s1 you defined earlier in your program
random_note is supposed to be a list of musical notes to pick from, not a list of strings that happen to match variable names.