This week we have been mainly working on removing any bugs and getting our final submission ready. One thing that was clearly an issue was the latency in our program. Ben recommended revising the gradient function so that it only used timers rather than time.sleep. This was somewhat difficult as the structure of the function did not work with timers. I re-wrote the function like this:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from gui import * | |
| from timer import * | |
| d = Display("Gradient", 300, 300) | |
| rect = Rectangle(0, 0, 300, 300, Color.BLACK, True, 1) | |
| d.add(rect,0,0) | |
| r = 0 | |
| color =None | |
| # This function either updates the color from red to blue or blue to red using if statements | |
| # The arguments are the r variable which is used to change the color by subtracting it or | |
| # adding it to the | |
| def updateColor(): | |
| global rect, color, r | |
| #From blue (0,0,255) to red (255,0,0) | |
| if color == Color(1,0,254): | |
| red = r | |
| green = 0 | |
| blue = 255 – r | |
| color = Color(red,green,blue) | |
| rect.setColor(color) | |
| r = r + 1 | |
| if color == Color(254,0,1): | |
| r = 0 | |
| color = 0 | |
| pass | |
| else: | |
| color = Color(1,0,254) | |
| #for count in range(0,3): | |
| #From red (255,0,0) to blue (0,0,255) | |
| else: | |
| red = 255 – r | |
| green = 0 | |
| blue = r | |
| color = Color(red,green,blue) | |
| rect.setColor(color) | |
| r = r + 1 | |
| if color == Color(1,0,254): | |
| r = 0 | |
| # Calls the updateColor function continuosly after a time interval | |
| t = Timer(10, updateColor) | |
| t.start() |
I think this will run somewhat fast but our program still has considerable latency when a note is played. I do not think we have the time or ability to make this program run faster.
One of our stretch goals was to run an animated gradient on each shape on the display, however, based on how the program is currently running, I think it will have even more delay if we were to add this feature.
Regardless, we are nearing completion and our program is doing what we expected it to.