Issue
I'm a human trying to make an animated musical keyboard type thing so keystrokes play noises and flash pretty colors on screen that make ape brain happy. I don't want to bore you too much, that's all you really need to know to get what's going on. I think? Let me know.
Point is, I want to make the rectangle that flashes colors on keypress, fade back to gray on key release. I figured I'd do this with time
, having a list of colors, iterate through them in steps back to gray setting the rectangle's fill to each with canvas.itemconfig
with a like 0.01-second delay after each step. But the rectangle behaves as it did before I added the flair: key-press, cyan, key-release, gray. No animation. I tried lengthening the steps to 1 second (looong, but on purpose to see if I was just missing something; the same cyan shade stuck for 4 steps' worth of time, it should have iterated), and setting the rectangle color in the final step to an ugly magenta. The magenta stuck obviously because I never bothered changing it until another keypress cyanned it again. So why aren't the shades iterating. Also, feel free to call your band The Iterating Shades.
My code, slimmed down as much as possible:
# Blah blah blah, setup, but here's the key release handler (The part *I think* that's messing crap up).
def key_release(e):
if (e.char == 'q'):
for i in ["#0088dd", "#005e99", "#002841", "#2e2e2e"]:
canvas.itemconfig(rect, fill=i)
time.sleep(0.04)
canvas.itemconfig(kaq, fill="gray20")
elif (e.char == 'e'):
for i in ["#ff9500", "#9e5d00", "#523000", "#2e2e2e"]:
canvas.itemconfig(rect, fill=i)
time.sleep(0.04)
canvas.itemconfig(kae, fill="gray20")
time.sleep(0.04)
There. Short(?) code, and I didn't blab on too long. All's well that ends well!
Got any ideas? Fixes? Solutions? Pitchforks to throw? Let me know, with a healthy amount of thanks from me to you. I hope this glitch is just not me being silly! Have a great day! And let me know too if you need more code-- but some people are big on Minimum Reproducible Examples, so I kept it short here.
Solution
Sharing some good news and bad news about the project this question was asked for, in a
FINAL UPDATE 🎺🎺
My original idea was to make an "audiovisual keyboard" in a style like the Fischinger Google doodle combined with Animusic's videos. In a simple example, you'd press a key and a corresponding note would play, a rectangle flashing blue on screen. The idea was that I'd be able to play out music, and while my Youtube viewers were listening, I'd be able to plug something into their visual sense as well to liven it up a bit.
But quickly, I realized that I'd have to reconfigure the code for each song, and I'm pretty unmotivated to begin with. (I've never programmed anything bigger than like 20 lines on my own, except when I was wayyy young. I was inhumanly driven then). Why not, then, try to build a library so setting up the components of my presentation was as simple as:
import trink
world = Trink.World(size="full", background="black", name="A Couple Racks")
orange = "style:fade,color:orange,length_per:0.05,steps:4"
piano = world.addRack(instrument="piano", notes=3, note_keys="Q,W,E", note_pitches="C=4,E=4,G=4", style="matches_press", animation=orange)
piano.seal()
So that, friends, is exactly what I will be doing. And I'm calling it Trink as in trinket, because all the simulated instruments this program can build are gonna be like curios you can customize to your own whims and desires.
You?! Yes!! Why the heck not?! That way, you can use Trink to:
- PLAY lovely music generated by your input
- and have a nice DISPLAY to go along with it!
So, bad news, I'll have to rebuild the code. But, good news, as soon as I get out the gate, I'll be sharing the code. And someday, once I've gotten far enough for my taste, the code will go open source so you guys can poke around a bit. Add stuff. Who knows. Maybe you want to make a HIGH-POWERED LASER go off every time you hit <space>?! Is there a python library for doom lasers?
But yeah. I'll be working on-and-off on it, 'cause it's a hobby project. Hope it doesn't curl into the fetal position and die! But let's see where this thing goes. Check back in a few months!!!!1!!!
kthxbye
Answered By - JoJawesome09
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.