Advertisement
shh_algo_PY

Coehn - Piano Project

Apr 1st, 2022
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. import play
  2. import pygame
  3. play.set_backdrop('light blue')
  4.  
  5. text1 = play.new_text("Minecraft piano for fun!", x = -200, y = 250)
  6. text2 = play.new_text("Created in python!", x = -200, y = 200)
  7. text3 = play.new_text("Create your melody by pressing the keys!", x = 0, y = 150)
  8. piano = play.new_image("piano.png", x = 50, y = 225,size = 30)
  9. key_clear_melody = play.new_box(color='blue',border_color = 'gold', x = -200, y = -200, width = 200, height = 100)
  10. kcm = play.new_text(words='clear melody', x=-200, y=-200, font_size=45)
  11. key_play_melody = play.new_box(color='red', border_color = 'gold', x = 200, y = -200, width = 200, height = 100)
  12. kpm = play.new_text(words='play melody', x=200, y=-200, font_size=45)
  13. sound = pygame.mixer.Sound("clear_melody.wav")
  14.  
  15. keys = []
  16. sounds = []
  17.  
  18. for i in range(8):
  19.  
  20.     key_x = -350 + i * 100
  21.     key = play.new_box(color='white', border_color = 'black', border_width=3, x =key_x, y = 0, width=80, height=200)
  22.     keys.append(key)
  23.     sound = pygame.mixer.Sound(str(i+1)+'.ogg')
  24.     sounds.append(sound)
  25.    
  26. buttons = ["a", "s", "d", "f", "g", "h", "j", "k"]    
  27. image = []
  28. melody = []
  29.  
  30. i1 = play.new_image("creeper.png", x = -350, y = 0,size = 20)
  31. c = play.new_text("C", x = -350, y = -75)
  32. image.append(i1)
  33.  
  34. i2= play.new_image("skeleton.png", x = -250, y = 0,size = 15)
  35. image.append(i2)
  36. d = play.new_text("D", x = -250, y = -75)
  37.  
  38. i3= play.new_image("enderman.png", x = -150, y = 0,size = 25)
  39. image.append(i3)
  40. E = play.new_text("E", x = -150, y = -75)
  41.  
  42. i4= play.new_image("steve1.png", x = -50, y = 0,size = 45)
  43. image.append(i4)
  44. F = play.new_text("F", x = -50, y = -75)
  45.  
  46. i5= play.new_image("chicken1.png", x = 50, y = 0,size = 20)
  47. image.append(i5)
  48. G = play.new_text("G", x = 50, y = -75)
  49.  
  50. i6= play.new_image("spider.png", x = 150, y = 0,size = 8)
  51. image.append(i6)
  52. A = play.new_text("A", x = 150, y = -75)
  53.  
  54. i7= play.new_image("wither.png", x = 250, y = 0,size = 33)
  55. B = play.new_text("B", x = 250, y = -75)
  56. image.append(i7)
  57.  
  58. i8= play.new_image("dragon.png", x = 350, y = 0,size = 13)
  59. C = play.new_text("C", x = 350, y = -75)
  60. image.append(i8)
  61.  
  62. @key_clear_melody.when_clicked
  63. def play_sound():
  64.     sound.play()
  65.  
  66. @play.when_program_starts
  67. def start():
  68.     pygame.mixer_music.load("hello.mp3")
  69.     pygame.mixer_music.play()
  70.  
  71. @key_play_melody.when_clicked
  72. async def play_m():
  73.     for i in range(len(melody)):
  74.         await play.timer(seconds=0.5)
  75.         sounds[melody[i]].play()
  76.  
  77. @key_clear_melody.when_clicked
  78. def clear():
  79.     melody.clear()
  80.     sound_clear_melody.play()
  81.  
  82. @play.repeat_forever
  83. async def play_instrument():
  84.     for i in range(len(keys)):
  85.         if keys[i].is_clicked or play.key_is_pressed(buttons[i]):
  86.             keys[i].color = 'light grey'
  87.             sounds[i].play()
  88.             await play.timer(seconds=0.3)
  89.             keys[i].color = 'white' #alternately, "white"
  90.             melody.append(i)
  91.  
  92. play.start_program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement