We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello all! I am an "old" newbie in processing, meaning interested since a long time but did not manage to "get my hands dirty" with it since then. I am trying to programming an interactive poetry system, implying the use of a makey makey. The idea is that everytime you touch a letter, it will randomly display a word at the place where the first letter is placed vertically. The thing is that I did manage to have my words randomly choosen and displayed but two problems occured : 1) Every time another letter is hit, it erase the former word. I know that because of "background(0)" in the void draw() bloc, it is normal but if I remove it, than all words connected to the letter appears simultaneously. How to fix that, and make that when the relevant key is pressed, only this word is replace 2) when a key is pressed, every words assigned to this key are displayed before to stop on one word, probably because of the function random(), how do I fix that? 3) Other question : is it then better to use void keyPressed (), or the function keyPressed inside void draw() Here an extract of my testing code :
String [] words ={"alligator","attaque","array","avion","amour","tyran","talmudique","thalasso","tantrique","tyrannique","tu","labile","label","arraisonnement","condition","voix","charisme","cannibale","sciemment","collusion","calice","calvitie","fin"};
String textDisplay;
// int y = (displayHeight / 8);
void setup (){
size (displayWidth, displayHeight);
background (0);
textSize (80);
textAlign(CENTER);
}
void draw () {
int y = (displayHeight / 8);
if (keyPressed) {
if (key == 'z' || key == 'Z') {
// int y = (displayHeight / 8);
background (0);
fill (255);
textDisplay = words[int(random(5))];
text (textDisplay, width/2, y);
}
else {
fill(0);
}
if (key == 'm' || key == 'M') {
background (0);
fill (255);
textDisplay = words[int(random(6, words.length))];
text (textDisplay, width/2, 2*y);
}
else {
fill (0); }
} } I assume my code is pretty much rubbish, but be gentle, I am in the early experimentation level of Programmering!
Answers
Definitely use void keyPressed () for this purpose
You need to learn some more advanced concepts
You need class placedWord and an ArrayList of that class
Then for loop over the ArrayList and display the content
On keyPressed add to ArrayList
The class holds the word as a String and a x,y position as start.
Think of an underlying grid (like chess) to help you find the positions
Find a way not to check each letter separately but in a for loop
Hey Chrisir, thanks for your answer. I was trying to avoid the use of classes, because I have it somehow hard to understand how it works. If I understand you correctly, I have to build a class for each letter/key pressed?
No it's Only one class for all words placed on the grid
But you can also use 3 parallel arrays instead of the class which would be x[] y[] and textDisplay[]
@Pebpeb -- re:
I want to make sure that I understand.
This sketch always displays the same string, but pressing buttons adds new words (with line breaks) to the string each time:
@jeremydouglass the letters are placed vertically but everytime you hit the letter,you will have a new word which replacing the former one with the same letter on the beginning/on the same line. For example you have the word "plane": P -> key "p" is hitten, one out of five words will be displayed. Key is pressed one more time, it will display another word out of the five. L -> key "l" is hitten, one out of five words will be displayed. Key is pressed one more time, it will display another word out of the five.
A -> and so on with "A" N -> and so on with "N" E -> and so on with "E"
Everytime one of the assigned key is pressed, it has not to affect the other words, just changing the one of her line. Make it sens? Tell me if it does'nt.
@Chrisir, is it the way you understood it?
I am still not sure what you mean.
My sketch shows how you can hit the key l, v, a, etc. and hit a key multiple times so e.g. the word with "a" gets replaced but stays in the same line.
;-)
Woh ! Ok, I will need some time to process it & understand how you get there! But thanks!
It is more or less what I meant, but there it involves a makey makey, I do have to assign the keyPressed function to another key then the first letter of the words btw, the ones which are embedded in the makey makey.
I try to be clearer (I realise that it is not at all the case, sorry for that!): You have a word made of letters that you can touch. When one of the letter is touched, it displays on the screen one of the word out of the list beginning with the same letter that have been touch and place accordingly. (If there is to "A" in the word, one at the beginning, one at the end, it as then to display it on the screen vertically on the right place of the word which is ).
That's why I thought the code so in the first place : "For a word like "ARRAY" : If the object (IRL) firstletter A is touched, then screen displays on y = firstposition one word which is in the array from 0 -> 5 and are assigned to key "Q", because my object (letter A) is connected to the slot "Q" on the makey makey". Then if first letter R is touched then screen will show one word out of the array from position 6 -> 11) , assigned to key "space", placed vertically on y = secondposition. If the first letter "A" is touched, then replace the word and only the word in the first position, If the fourth letter, which also happens to be a "A" is touched, then screen displays at the fourth place vertically (y = fourthposition) one word out of the array from position 21 -> 26.
So how do I break it into functions?
Description
Programming is probably first about being able to describe your goal and break it down into single steps. You are not very clear (for me).
can you post a link to a description of a makey makey you are talking about?
can you draw an image of the makey makey you mean?
Questions
Please answer these questions.
You wrote:
Do you mean I touch it with the mouse?
Do your initial letters look like this?
Do they?
They are vertical.
Can you lay only left (or on both sides?)?
If I click on "A" I get a list with all words starting with A and I can choose from the list with the mouse? Correct? Or is he doing this automatically?
Do you plan a thing similar to a cross word? Or just one vertical word and many horizontal words ?
Your fourth paragraph
Your fourth paragraph (of 5) is unclear. Do you mean a coding going from Y to A and from Q to whatever? So if you press Q , the A is handled?
Why?
I wouldn't do this with ifs........ it would be long and repetitive...
Instead make two parallel arrays of type char and once read the first, and if Q is found in array 1, A must be at same index in array 2 and you can use it.
new version
new version (treating only the first occurrence of A in the word), but do you mean this kind of process in principle?
here is a code for a letter grid when you click mouse on the letter
Yep, I clearly have to improve that ;)
Answers :
http://tienda.bricogeek.com/kits-electronica-para-montar/527-kit-makey-makey.html
no, you can actually touch the letters, here is an image of my "device" : http://hpics.li/6b41270
my initials letters are the way you see it on the picture. There are no letters displayed on screen before someone touch them.
you are right about the way the words should be displayed on the screen (tought I want them to be on the center, but that is not the issue here).
if you touch "A", then one word which is beginning with "A" in the list is randomly choosen and displayed after the "A". But for a certain "A". The idea is to get certain words, which happened to be beginning with the same letter, but it is actually not really that relevant. What is relevant is the _position__ of the letter in the word. The words to be displayed are actually not random : I write five to ten sentences which a meaning of themselves and beginning with the letter of the original word (ex : planer : Paradise Later A New Economic Realm/ Paris lately avoiding Nuclear Essais Realities / etc..). So when someone touch the letter "P", it displays "Paradise" or "Paris" (randomly), but if the word was initially "PAPER", the second "P" will not be displaying those two words when the second "P" of the word is touched, but the words that I wrote before.
the fact that "Q" is handed if "A "is stroked is because of the way the makey makey works.
I hope it is clearer.... And I go back to some early tutorials of "object orienting programming" and processing!
@Chrisir. I did not see your other post before posting, I'll look into that also, many thanks!
new version with a Q to Y translator and a form to store entire sentences