xxxxxxxxxx
59
let fontSize = 20; // Makes variable fontSize equal 20
let sentences = []; // Array to hold individual sentences of the song
let currentSentenceIndex = 0; // Index to keep track of the current sentence to display
let bgImage; // Variable to hold the background image
let bgMusic; // Variable to hold the background music
function preload() {
// Load the background image
bgImage = loadImage('brazil.jpg');
// Load the song lyrics from the CSV file
sentences = loadStrings('song.csv');
// Load the background music
bgMusic = loadSound('wave.mp3');
}
function setup() {
createCanvas(550, 480);
textSize(fontSize);
// Start playing the background music
bgMusic.play();
}
function draw() {
// Display the background image
image(bgImage, 0, 0, width, height);
// Sets the text alignment to center
textAlign(CENTER);
// Calculate y-coordinate with a sinusoidal function for wave animation
let y = height - 20 + sin(frameCount * 0.05) * 10; // Adjust the amplitude (10) for desired wave height
// Adjust the frequency (0.05) for wave speed
// Draw the current sentence at the bottom center with animated wave effect
drawWords(width / 2, y);
}
function drawWords(x, y) {
// Text color
fill('gold');
// Display the current sentence at the specified position on the canvas
text(sentences[currentSentenceIndex], x, y);
}
// Function to advance to the next sentence when the mouse is pressed
function mousePressed() {
// Increment the currentSentenceIndex
currentSentenceIndex++;
// If the currentSentenceIndex exceeds the length of the sentences array, reset it to 0
if (currentSentenceIndex >= sentences.length) {
currentSentenceIndex = 0;
}
}