We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all,
I'm a bit stuck with trying to achieve something. I've made a 'program' which draws three sentences, randomly picked from a string. On each mousePressed all the sentences are redrawn. But what I want to achieve is to change each sentence individually. So if you click on the first one, that one changes (and the other two don't). Same for the second and third.
I know it must be something like if (mouseX >0 && mouseX<100 && mouseY>0 && mouseY<100)
but I can't manage to make it work.
Here's my code:
String [] eersteregel = {
"dit stille weten", "in alle eenvoud", "vroege dageraad", "niets is er nodig", "ik ben zo iemand", "waar te beginnen"
};
String [] tweederegel = {
"dat jijzelf die ruimte bent", "wakker te zijn vanochtend", "kijken naar wat je lief is", "slechts eindeloze ruimte", "die stil de zon ziet opgaan", "cute", "crying", "de dag ligt nu nog open"
};
String [] derderegel = {
"waar alles plaatsvindt", "de dag beginnen", "meer is niet nodig", "en deze stilte", "en zich verwondert", "zo veelbelovend",
};
PFont georgia;
void setup() {
size(400, 400);
background(255);
georgia = createFont("Georgia", 24);
noLoop();
}
void draw() {
background(255);
textFont(georgia, 24);
fill(0);
String word1 = eersteregel[int(random(eersteregel.length))];
text(word1, 50, 100);
String word2 = tweederegel[int(random(tweederegel.length))];
text(word2, 50, 150);
String word3 = derderegel[int(random(derderegel.length))];
text(word3, 50, 200);
}
void mousePressed() {
redraw();
}
Has anyone a clue how to solve this? Any help is appreciated. Regards, roos laan
Answers
This would be easier with a class to wrap together the strings, the positions and the behaviour. Have you seen this tutorial? But with no classes it would look like this: