xxxxxxxxxx
64
//Declaring variables
let index = 0;
let word;
let myfont;
//Defining array to hold words
let words = [
"hello",
"hola",
"hallo",
"bonjour",
"olá",
"Aloha",
"Përshëndetje",
"Dia dhuit",
"Ahoj",
"Hei",
"Kamusta",
"Salve",
];
//creating word class
class Word {
constructor(x, y) {
this.x = x;
this.y = y;
this.word = words[index];
this.color = color(255);
index++;
if (index >= words.length) {
index = 0;
}
}
//display the words
display() {
textSize(50);
textAlign(CENTER, CENTER);
fill(this.color);
textFont(myfont);
text(this.word, this.x, this.y);
}
}
function setup() {
createCanvas(600, 400);
background(220);
word = new Word(width / 2, height / 2);
}
function draw() {
background(img);
word.display();
if (frameCount % 100 == 0) {
word = new Word(width / 2, height / 2);
}
}
//function to load background image and font-type
function preload() {
//soundFormats("mp3")
img = loadImage("apple.png");
myfont = loadFont("California.otf");
}