Skip to content

Instantly share code, notes, and snippets.

@CalvinLogan
Created December 10, 2018 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CalvinLogan/3427039e8a15ca92e0debe50e524ac8a to your computer and use it in GitHub Desktop.
Save CalvinLogan/3427039e8a15ca92e0debe50e524ac8a to your computer and use it in GitHub Desktop.
from gui import *
from random import *
from music import *
from midi import *
from timer import *
import time
def setUp():
global window
window = Display("Visualizer", getScreenWidth(), getScreenHeight())
gradient = Rectangle(0, 0, getScreenWidth(), getScreenHeight(), Color.BLACK, True, 1)
window.add(gradient)
updateColor(gradient)
#input: None
#return: the width of the screen
def getScreenWidth():
return Toolkit.getDefaultToolkit().getScreenSize().width
#input: none
#return: the height of the screen
def getScreenHeight():
return Toolkit.getDefaultToolkit().getScreenSize().height
b = True
def updateColor(shape):
while b:
for count in range(0,3):
#From red (255,0,0) to blue (0,0,255)
for i in range(0,255):
red = 255 - i
green = 0
blue = i
color = Color(red,green,blue)
shape.setColor(color)
time.sleep(0.01)
if color == Color(1,0,254):
#From blue (0,0,255) to red (255,0,0)
for i in range(0,255):
red = i
green = 0
blue = 255 - i
color = Color(red,green,blue)
shape.setColor(color)
time.sleep(0.01)
#input: the incoming midi note from a midi keyboard with the pitch and volume of the note
# return: none
def drawShape(eventType, channel, data1, data2):
global window, shape1, shape2, shape3, shape4, shape5, shape6
# iicon position is random
x = randint(0, getScreenWidth()) # x may be anywhere on display
y = randint(0, getScreenHeight()) # y may be anywhere on display
colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Pink", "White", "Teal"]
colorIdx = (data1 / 2) % len(colors)
color = colors[colorIdx]
shapeLists = [shape1, shape2, shape3, shape4, shape5, shape6]
shapeListIdx = (data1 / 3) % len(shapeLists)
shapeList = shapeLists[shapeListIdx]
shape = shapeList[color]
icon = Icon(shape,x,y)
window.add(icon)
# play note
Play.noteOn(data1, data2)
# establish a connection to an input MIDI device
midiIn = MidiIn("Unknown Vendor Oxygen 25")
# register a callback function to process incoming MIDI events
midiIn.onNoteOn(drawShape)
def resolve(relativePath):
cd = os.path.dirname(os.path.abspath(__file__))
return os.path.join(cd, relativePath)
shape1 = {
"Red" : resolve("./Shapes/Shape 1/Shape 1 Red.png"),
"Orange" : resolve("./Shapes/Shape 1/Shape 1 Orange.png"),
"Yellow" : resolve("./Shapes/Shape 1/Shape 1 Yellow.png"),
"Green" : resolve("./Shapes/Shape 1/Shape 1 Green.png"),
"Blue" : resolve("./Shapes/Shape 1/Shape 1 Blue.png"),
"Purple" : resolve("./Shapes/Shape 1/Shape 1 Purple.png"),
"Pink" : resolve("./Shapes/Shape 1/Shape 1 Pink.png"),
"White" : resolve("./Shapes/Shape 1/Shape 1 White.png"),
"Teal" : resolve("./Shapes/Shape 1/Shape 1 Teal.png")
}
shape2 = {
"Red" : resolve("./Shapes/Shape 2/Shape 2 Red.png"),
"Orange" : resolve("./Shapes/Shape 2/Shape 2 Orange.png"),
"Yellow" : resolve("./Shapes/Shape 2/Shape 2 Yellow.png"),
"Green" : resolve("./Shapes/Shape 2/Shape 2 Green.png"),
"Blue" : resolve("./Shapes/Shape 2/Shape 2 Blue.png"),
"Purple" : resolve("./Shapes/Shape 2/Shape 2 Purple.png"),
"Pink" : resolve("./Shapes/Shape 2/Shape 2 Pink.png"),
"White" : resolve("./Shapes/Shape 2/Shape 2 White.png"),
"Teal" : resolve("./Shapes/Shape 2/Shape 2 Teal.png")
}
shape3 = {
"Red" : resolve("./Shapes/Shape 3/Shape 3 Red.png"),
"Orange" : resolve("./Shapes/Shape 3/Shape 3 Orange.png"),
"Yellow" : resolve("./Shapes/Shape 3/Shape 3 Yellow.png"),
"Green" : resolve("./Shapes/Shape 3/Shape 3 Green.png"),
"Blue" : resolve("./Shapes/Shape 3/Shape 3 Blue.png"),
"Purple" : resolve("./Shapes/Shape 3/Shape 3 Purple.png"),
"Pink" : resolve("./Shapes/Shape 3/Shape 3 Pink.png"),
"White" : resolve("./Shapes/Shape 3/Shape 3 White.png"),
"Teal" : resolve("./Shapes/Shape 3/Shape 3 Teal.png")
}
shape4 = {
"Red" : resolve("./Shapes/Shape 4/Shape 4 Red.png"),
"Orange" : resolve("./Shapes/Shape 4/Shape 4 Orange.png"),
"Yellow" : resolve("./Shapes/Shape 4/Shape 4 Yellow.png"),
"Green" : resolve("./Shapes/Shape 4/Shape 4 Green.png"),
"Blue" : resolve("./Shapes/Shape 4/Shape 4 Blue.png"),
"Purple" : resolve("./Shapes/Shape 4/Shape 4 Purple.png"),
"Pink" : resolve("./Shapes/Shape 4/Shape 4 Pink.png"),
"White" : resolve("./Shapes/Shape 4/Shape 4 White.png"),
"Teal" : resolve("./Shapes/Shape 4/Shape 4 Teal.png")
}
shape5 = {
"Red" : resolve("./Shapes/Shape 5/Shape 5 Red.png"),
"Orange" : resolve("./Shapes/Shape 5/Shape 5 Orange.png"),
"Yellow" : resolve("./Shapes/Shape 5/Shape 5 Yellow.png"),
"Green" : resolve("./Shapes/Shape 5/Shape 5 Green.png"),
"Blue" : resolve("./Shapes/Shape 5/Shape 5 Blue.png"),
"Purple" : resolve("./Shapes/Shape 5/Shape 5 Purple.png"),
"Pink" : resolve("./Shapes/Shape 5/Shape 5 Pink.png"),
"White" : resolve("./Shapes/Shape 5/Shape 5 White.png"),
"Teal" : resolve("./Shapes/Shape 5/Shape 5 Teal.png")
}
shape6 = {
"Red" : resolve("./Shapes/Shape 6/Shape 6 Red.png"),
"Orange" : resolve("./Shapes/Shape 6/Shape 6 Orange.png"),
"Yellow" : resolve("./Shapes/Shape 6/Shape 6 Yellow.png"),
"Green" : resolve("./Shapes/Shape 6/Shape 6 Green.png"),
"Blue" : resolve("./Shapes/Shape 6/Shape 6 Blue.png"),
"Purple" : resolve("./Shapes/Shape 6/Shape 6 Purple.png"),
"Pink" : resolve("./Shapes/Shape 6/Shape 6 Pink.png"),
"White" : resolve("./Shapes/Shape 6/Shape 6 White.png"),
"Teal" : resolve("./Shapes/Shape 6/Shape 6 Teal.png")
}
setUp()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment