Guest User

Untitled

a guest
Dec 10th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. from gui import *
  2. from random import *
  3. from music import *
  4. from midi import *
  5. from timer import *
  6. import time
  7.  
  8. def setUp():
  9. global window
  10. window = Display("Visualizer", getScreenWidth(), getScreenHeight())
  11. gradient = Rectangle(0, 0, getScreenWidth(), getScreenHeight(), Color.BLACK, True, 1)
  12. window.add(gradient)
  13. updateColor(gradient)
  14.  
  15.  
  16. #input: None
  17. #return: the width of the screen
  18. def getScreenWidth():
  19. return Toolkit.getDefaultToolkit().getScreenSize().width
  20.  
  21. #input: none
  22. #return: the height of the screen
  23. def getScreenHeight():
  24. return Toolkit.getDefaultToolkit().getScreenSize().height
  25.  
  26. b = True
  27.  
  28. def updateColor(shape):
  29. while b:
  30. for count in range(0,3):
  31. #From red (255,0,0) to blue (0,0,255)
  32. for i in range(0,255):
  33. red = 255 - i
  34. green = 0
  35. blue = i
  36. color = Color(red,green,blue)
  37. shape.setColor(color)
  38. time.sleep(0.01)
  39. if color == Color(1,0,254):
  40. #From blue (0,0,255) to red (255,0,0)
  41.  
  42. for i in range(0,255):
  43. red = i
  44. green = 0
  45. blue = 255 - i
  46. color = Color(red,green,blue)
  47. shape.setColor(color)
  48. time.sleep(0.01)
  49.  
  50.  
  51. #input: the incoming midi note from a midi keyboard with the pitch and volume of the note
  52. # return: none
  53. def drawShape(eventType, channel, data1, data2):
  54.  
  55. global window, shape1, shape2, shape3, shape4, shape5, shape6
  56.  
  57. # iicon position is random
  58. x = randint(0, getScreenWidth()) # x may be anywhere on display
  59. y = randint(0, getScreenHeight()) # y may be anywhere on display
  60.  
  61.  
  62. colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Pink", "White", "Teal"]
  63. colorIdx = (data1 / 2) % len(colors)
  64. color = colors[colorIdx]
  65.  
  66. shapeLists = [shape1, shape2, shape3, shape4, shape5, shape6]
  67. shapeListIdx = (data1 / 3) % len(shapeLists)
  68. shapeList = shapeLists[shapeListIdx]
  69. shape = shapeList[color]
  70. icon = Icon(shape,x,y)
  71. window.add(icon)
  72.  
  73. # play note
  74. Play.noteOn(data1, data2)
  75.  
  76. # establish a connection to an input MIDI device
  77. midiIn = MidiIn("Unknown Vendor Oxygen 25")
  78.  
  79.  
  80. # register a callback function to process incoming MIDI events
  81. midiIn.onNoteOn(drawShape)
  82.  
  83. def resolve(relativePath):
  84. cd = os.path.dirname(os.path.abspath(__file__))
  85. return os.path.join(cd, relativePath)
  86.  
  87.  
  88. shape1 = {
  89. "Red" : resolve("./Shapes/Shape 1/Shape 1 Red.png"),
  90. "Orange" : resolve("./Shapes/Shape 1/Shape 1 Orange.png"),
  91. "Yellow" : resolve("./Shapes/Shape 1/Shape 1 Yellow.png"),
  92. "Green" : resolve("./Shapes/Shape 1/Shape 1 Green.png"),
  93. "Blue" : resolve("./Shapes/Shape 1/Shape 1 Blue.png"),
  94. "Purple" : resolve("./Shapes/Shape 1/Shape 1 Purple.png"),
  95. "Pink" : resolve("./Shapes/Shape 1/Shape 1 Pink.png"),
  96. "White" : resolve("./Shapes/Shape 1/Shape 1 White.png"),
  97. "Teal" : resolve("./Shapes/Shape 1/Shape 1 Teal.png")
  98. }
  99.  
  100. shape2 = {
  101. "Red" : resolve("./Shapes/Shape 2/Shape 2 Red.png"),
  102. "Orange" : resolve("./Shapes/Shape 2/Shape 2 Orange.png"),
  103. "Yellow" : resolve("./Shapes/Shape 2/Shape 2 Yellow.png"),
  104. "Green" : resolve("./Shapes/Shape 2/Shape 2 Green.png"),
  105. "Blue" : resolve("./Shapes/Shape 2/Shape 2 Blue.png"),
  106. "Purple" : resolve("./Shapes/Shape 2/Shape 2 Purple.png"),
  107. "Pink" : resolve("./Shapes/Shape 2/Shape 2 Pink.png"),
  108. "White" : resolve("./Shapes/Shape 2/Shape 2 White.png"),
  109. "Teal" : resolve("./Shapes/Shape 2/Shape 2 Teal.png")
  110. }
  111.  
  112. shape3 = {
  113. "Red" : resolve("./Shapes/Shape 3/Shape 3 Red.png"),
  114. "Orange" : resolve("./Shapes/Shape 3/Shape 3 Orange.png"),
  115. "Yellow" : resolve("./Shapes/Shape 3/Shape 3 Yellow.png"),
  116. "Green" : resolve("./Shapes/Shape 3/Shape 3 Green.png"),
  117. "Blue" : resolve("./Shapes/Shape 3/Shape 3 Blue.png"),
  118. "Purple" : resolve("./Shapes/Shape 3/Shape 3 Purple.png"),
  119. "Pink" : resolve("./Shapes/Shape 3/Shape 3 Pink.png"),
  120. "White" : resolve("./Shapes/Shape 3/Shape 3 White.png"),
  121. "Teal" : resolve("./Shapes/Shape 3/Shape 3 Teal.png")
  122. }
  123.  
  124.  
  125. shape4 = {
  126. "Red" : resolve("./Shapes/Shape 4/Shape 4 Red.png"),
  127. "Orange" : resolve("./Shapes/Shape 4/Shape 4 Orange.png"),
  128. "Yellow" : resolve("./Shapes/Shape 4/Shape 4 Yellow.png"),
  129. "Green" : resolve("./Shapes/Shape 4/Shape 4 Green.png"),
  130. "Blue" : resolve("./Shapes/Shape 4/Shape 4 Blue.png"),
  131. "Purple" : resolve("./Shapes/Shape 4/Shape 4 Purple.png"),
  132. "Pink" : resolve("./Shapes/Shape 4/Shape 4 Pink.png"),
  133. "White" : resolve("./Shapes/Shape 4/Shape 4 White.png"),
  134. "Teal" : resolve("./Shapes/Shape 4/Shape 4 Teal.png")
  135. }
  136.  
  137. shape5 = {
  138. "Red" : resolve("./Shapes/Shape 5/Shape 5 Red.png"),
  139. "Orange" : resolve("./Shapes/Shape 5/Shape 5 Orange.png"),
  140. "Yellow" : resolve("./Shapes/Shape 5/Shape 5 Yellow.png"),
  141. "Green" : resolve("./Shapes/Shape 5/Shape 5 Green.png"),
  142. "Blue" : resolve("./Shapes/Shape 5/Shape 5 Blue.png"),
  143. "Purple" : resolve("./Shapes/Shape 5/Shape 5 Purple.png"),
  144. "Pink" : resolve("./Shapes/Shape 5/Shape 5 Pink.png"),
  145. "White" : resolve("./Shapes/Shape 5/Shape 5 White.png"),
  146. "Teal" : resolve("./Shapes/Shape 5/Shape 5 Teal.png")
  147. }
  148.  
  149. shape6 = {
  150. "Red" : resolve("./Shapes/Shape 6/Shape 6 Red.png"),
  151. "Orange" : resolve("./Shapes/Shape 6/Shape 6 Orange.png"),
  152. "Yellow" : resolve("./Shapes/Shape 6/Shape 6 Yellow.png"),
  153. "Green" : resolve("./Shapes/Shape 6/Shape 6 Green.png"),
  154. "Blue" : resolve("./Shapes/Shape 6/Shape 6 Blue.png"),
  155. "Purple" : resolve("./Shapes/Shape 6/Shape 6 Purple.png"),
  156. "Pink" : resolve("./Shapes/Shape 6/Shape 6 Pink.png"),
  157. "White" : resolve("./Shapes/Shape 6/Shape 6 White.png"),
  158. "Teal" : resolve("./Shapes/Shape 6/Shape 6 Teal.png")
  159. }
  160.  
  161. setUp()
Add Comment
Please, Sign In to add comment