We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm working on a project for college that I could use a little bit of help with. Essentially, I want letters to correspond to different musical notes.
I need processing to recognize an input of letters as variables and to take action based on which variable as it reads through them.
Can anyone give any insight on how to assign variables to simple letters input as a string or an array or something?
Thanks
Answers
I guess you are looking for:
http://processing.org/reference/key.html
http://processing.org/reference/keyPressed_.html
Not really, but thank you. Let me explain a little better...
I want to have an input of text placed in the program, for example "Hello"
I'm looking to have the program basically read the input text, recognize that there are 5 letters, being H-E-L-L-O, and cause an action based on which letter it is.
For example, changing background color might be the variable. H is orange, e is yellow, l is green, and o is black. I want it to read through the inputed text and act upon it.
I can't figure out how to get processing to recognize the inputed text as variables
Perhaps what you're looking for is invoke a different method for a given letter.
There's an undocumented function called method("").
It invokes a method w/ the same name as the passed String argument.
Here's an example which uses method(""):
http://studio.processingtogether.com/sp/pad/export/ro.9eDRvB4LRmLrr/latest
But you gotta run it in Java Mode instead and uncomment the "Java only" line and comment out the "For JS".
Thanks I'll look into it and give it a shot! Appreciate the help
Can you explain this a little better to me? Sorry I'm relatively new with the program.
I just want processing to recognize the string of text as predefined variables
It's in the links i pointed...
That coding just lets you type and have it appear on screen. I want the text to already be placed in the code and have it run through. Something like this:
I want to use that splitTokens type of coding to basically split the letters in the string, then when it gets to each letter to perform a task assigned to that letter
In Java Mode, we can't declare variables nor define functions on-the-fly!
They gotta be typed in as source code and then compiled!
However, Java has an advanced feature called reflection.
The aforementioned method("") function used in my online example is an easy shortcut to accomplish that.
Let's say you wanna invoke a method called E(). Then you issue
method("E");
in order to call that!Of course, method E() gotta pre-exist within the source code!
I believe you're gonna need 26*2 methods. 1 for each alphabet letter including lower & upper cases!
First task, iterate on each letter of your messages:
And an example of making various parameters depending on the current letter:
A more streamlined example using an
interface
to wrap up a custom method called script().Each anonymous instance of it is assigned to a letter-indexed array slot.
Therefore it's much closer to what you're looking for. That is, individual letter variables: *-:)