Hi, for my study i had a task which i have already completed (code below) i needed to draw four different names using a method. What i’ve made below works however how can i improve the method?
Code below doesn’t work its to illustrate what i want to achieve. Basically i want the new method to call an index number which stores the string and display that word so i can keep everything in one array.
String[] words = { "bla", "argh", "woohoo" };
void draw () {
newMethod(wordNumber[1], 10, 10);
println(newMethod);
}
// new method
void newMethod(String[] wordNumber, float x, float y) {
wordNumber = words;
}
To add to the stuff above: i’ve dabbled in Coding train concerning String array’s , split, join functions and using the for loop. However i’m still at banging at a wall for the thing i want to achieve.
This is my task.
PFont
myFont;
float
x, y, cX, cY,
hoeken, cHoeken,
linksX, linksY, rechtsX, rechtsY;
String
hallo, groet, n;
String[]
naam;
void setup() {
size(600, 400);
background(20);
myFont = createFont("Georgia", 16);
x = width;
y = height;
cX = x/2;
cY = y/2;
hoeken = sq(5);
linksX = cX-cX+hoeken;
linksY = cY-hoeken;
rechtsX = cX+hoeken;
rechtsY = cY+cY-hoeken;
hallo = "Hallo ";
groet = " hoe gaat het met je?";
n = "Harry, Marianne, Ludo, Maaike";
naam = split(n, ",");
}
void draw() {
textFont (myFont);
naam0(linksX, linksY);
naam1(rechtsX, linksY);
naam2(linksX, rechtsY);
naam3(rechtsX, rechtsY);
}
void naam0(float naamX, float naamY) {
text(hallo+naam[0]+groet, naamX, naamY);
}
void naam1(float naamX, float naamY) {
text(hallo+naam[1]+groet, naamX, naamY);
}
void naam2(float naamX, float naamY) {
text(hallo+naam[2]+groet, naamX, naamY);
}
void naam3(float naamX, float naamY) {
text(hallo+naam[3]+groet, naamX, naamY);
}