324 lines
8.1 KiB
JavaScript
324 lines
8.1 KiB
JavaScript
|
|
|
|
|
|
const socket = io();
|
|
|
|
let barreStress = document.getElementById('barreStress')
|
|
let stress = 0;
|
|
let maxInterval1;
|
|
let maxInterval2;
|
|
|
|
// ________________________________________________________________________________________
|
|
|
|
|
|
function test() {
|
|
setInterval(() => {
|
|
stress+=10;
|
|
console.log(stress);
|
|
testBarre();
|
|
}, 1000);
|
|
}
|
|
|
|
function teste(){
|
|
setInterval(() => {
|
|
stress=0;
|
|
}, 15000);
|
|
}
|
|
|
|
function animBarreMax() {
|
|
clearInterval(maxInterval1);
|
|
clearInterval(maxInterval2);
|
|
|
|
maxInterval1 = setInterval(() => {
|
|
barreStress.style.backgroundImage = 'url("barre/barreMax1.PNG")';
|
|
}, 250);
|
|
|
|
maxInterval2 = setInterval(() => {
|
|
barreStress.style.backgroundImage = 'url("barre/barreMax2.PNG")';
|
|
}, 500);
|
|
}
|
|
|
|
|
|
function stopAnimBarreMax() {
|
|
clearInterval(maxInterval1);
|
|
clearInterval(maxInterval2);
|
|
}
|
|
|
|
|
|
function testBarre() {
|
|
if (stress < 100) {
|
|
stopAnimBarreMax();
|
|
}
|
|
|
|
if (stress <= 10) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre1.PNG")';
|
|
} else if (stress <= 20) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre2.PNG")';
|
|
} else if (stress <= 30) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre3.PNG")';
|
|
} else if (stress <= 40) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre4.PNG")';
|
|
} else if (stress <= 50) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre5.PNG")';
|
|
} else if (stress <= 60) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre6.PNG")';
|
|
} else if (stress <= 70) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre7.PNG")';
|
|
} else if (stress <= 80) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre8.PNG")';
|
|
} else if (stress <= 90) {
|
|
barreStress.style.backgroundImage = 'url("barre/barre9.PNG")';
|
|
} else if (stress >= 100) {
|
|
animBarreMax();
|
|
}
|
|
}
|
|
|
|
// ________________________________________________________________________________________
|
|
|
|
|
|
function addNoise() {
|
|
const canvas = document.createElement('canvas');
|
|
const ctx = canvas.getContext('2d');
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
const imageData = ctx.createImageData(canvas.width, canvas.height);
|
|
const data = imageData.data;
|
|
|
|
for (let i = 0; i < data.length; i += 4) {
|
|
const value = Math.random() * 255;
|
|
data[i] = data[i + 1] = data[i + 2] = value;
|
|
data[i + 3] = 255; // alpha
|
|
}
|
|
|
|
ctx.putImageData(imageData, 0, 0);
|
|
document.body.style.backgroundImage = `url(${canvas.toDataURL()})`;
|
|
}
|
|
|
|
|
|
// ________________________________________________________________________________________
|
|
|
|
|
|
function lireTexte() {
|
|
// Récupérer le texte à lire depuis l'élément HTML avec l'ID 'texte'
|
|
const Texte = document.getElementById('texte');
|
|
const texteToSpeak = Texte ? Texte.innerText : "Texte par défaut";
|
|
|
|
// Appeler l'API backend pour lire le texte
|
|
fetch(`/speak?text=${encodeURIComponent(texteToSpeak)}`)
|
|
.then(reponse => {
|
|
if (!reponse.ok) {
|
|
throw new Error('Erreur réseau lors de l\'appel de l\'API');
|
|
}
|
|
return reponse.text();
|
|
})
|
|
.then(data => {
|
|
console.log(data); // Affiche la réponse du serveur
|
|
})
|
|
.catch(error => {
|
|
console.error('Erreur :', error);
|
|
});
|
|
}
|
|
|
|
|
|
// ________________________________________________________________________________________
|
|
|
|
let envoyerQuestion = document.getElementById("envoyerQuestion");
|
|
|
|
|
|
function doubleRandomWord(question) {
|
|
let words = question.split(' ');
|
|
if (words.length === 0) return question;
|
|
|
|
let randomIndex = Math.floor(Math.random() * words.length);
|
|
words.splice(randomIndex, 0, words[randomIndex]);
|
|
|
|
return words.join(' ');
|
|
}
|
|
|
|
|
|
function addInsulte(question) {
|
|
let listeInsulte = [
|
|
'PUTE',
|
|
'BITE',
|
|
'CON',
|
|
'CONNARD',
|
|
'SALOPE',
|
|
'MERDE',
|
|
'PUTAIN'
|
|
];
|
|
let Insulte = listeInsulte[Math.floor(Math.random() * listeInsulte.length)];
|
|
|
|
let words = question.split(' ');
|
|
let randomIndex = Math.floor(Math.random() * (words.length + 1));
|
|
words.splice(randomIndex, 0, Insulte);
|
|
|
|
return words.join(' ');
|
|
}
|
|
|
|
function submitQuestion (){
|
|
let question = document.getElementById('questionInput').value;
|
|
if (question.trim() !== '') {
|
|
|
|
// Modifier la question
|
|
// question = doubleRandomWord(question);
|
|
// question = addInsulte(question);
|
|
|
|
// Envoyer la question au serveur via socket.io ou une requête HTTP
|
|
socket.emit('question', question);
|
|
|
|
// Afficher la question dans le conteneur de réponses
|
|
const reponseContainer = document.getElementById('reponseContainer');
|
|
const questionElement = document.createElement('div');
|
|
questionElement.textContent = `Question: ${question}`;
|
|
reponseContainer.appendChild(questionElement);
|
|
|
|
// Vider le champ de saisie
|
|
document.getElementById('questionInput').value = '';
|
|
}
|
|
};
|
|
|
|
|
|
// ________________________________________________________________________________________
|
|
|
|
|
|
// // Créez une scène, une caméra et un rendu
|
|
// const scene = new THREE.Scene();
|
|
// const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
|
// const renderer = new THREE.WebGLRenderer();
|
|
// renderer.setSize(window.innerWidth, window.innerHeight);
|
|
// document.body.appendChild(renderer.domElement);
|
|
|
|
// // Ajoutez des lumières
|
|
// const light = new THREE.HemisphereLight(0xffffbb, 0x080820, 1);
|
|
// scene.add(light);
|
|
|
|
// // Chargez le modèle .obj
|
|
// const objLoader = new THREE.OBJLoader();
|
|
// objLoader.load(
|
|
// 'cybergirl.obj', // Remplacez par le chemin de votre fichier .obj
|
|
// (object) => {
|
|
// scene.add(object);
|
|
// object.position.set(0, 0, 0); // Ajustez la position si nécessaire
|
|
// },
|
|
// (xhr) => {
|
|
// console.log((xhr.loaded / xhr.total * 100) + '% loaded');
|
|
// },
|
|
// (error) => {
|
|
// console.error('Une erreur est survenue lors du chargement du modèle:', error);
|
|
// }
|
|
// );
|
|
|
|
|
|
// const mtlLoader = new THREE.MTLLoader();
|
|
// mtlLoader.load('cybergirl.mtl', (materials) => {
|
|
// materials.preload();
|
|
|
|
// const objLoader = new THREE.OBJLoader();
|
|
// objLoader.setMaterials(materials);
|
|
// objLoader.load('cybergirl.obj',(object) => {
|
|
// scene.add(object);
|
|
// object.position.set(0, 0, 0); // Ajustez la position si nécessaire
|
|
// },
|
|
// (xhr) => {
|
|
// console.log((xhr.loaded / xhr.total * 100) + '% loaded');
|
|
// },
|
|
// (error) => {
|
|
// console.error('Une erreur est survenue lors du chargement du modèle:', error);
|
|
// }
|
|
// );
|
|
// });
|
|
|
|
|
|
// // Positionnez la caméra
|
|
// camera.position.z = 5;
|
|
|
|
|
|
// // Fonction de rendu
|
|
// function animate() {
|
|
// requestAnimationFrame(animate);
|
|
// renderer.render(scene, camera);
|
|
// }
|
|
// animate();
|
|
|
|
|
|
|
|
// ________________________________________________________________________________________
|
|
|
|
|
|
let intervalEcoute;
|
|
let intervalEcoute1;
|
|
let intervalEcoute2;
|
|
|
|
let tete = document.getElementById('tete');
|
|
let tetegif =document.getElementById('teteGif')
|
|
let parle = -1;
|
|
|
|
function animAttente() {
|
|
tete.style.display='none';
|
|
tetegif.style.display='block';
|
|
}
|
|
|
|
function Ecoute() {
|
|
tete.style.display='block';
|
|
tetegif.style.display='none';
|
|
}
|
|
|
|
|
|
function animEcoute() {
|
|
tete.style.display='block';
|
|
tetegif.style.display='none';
|
|
clearInterval(intervalEcoute1);
|
|
clearInterval(intervalEcoute2);
|
|
|
|
intervalEcoute = setInterval(() => {
|
|
if (parle <= 0) {
|
|
|
|
intervalEcoute1 = setInterval(() => {
|
|
clearInterval(intervalEcoute1);
|
|
tete.style.backgroundImage='url("cybergirl_anim/png/^^1.png")';
|
|
console.log('1');
|
|
|
|
intervalEcoute2 = setInterval(() => {
|
|
clearInterval(intervalEcoute2);
|
|
tete.style.backgroundImage='url("cybergirl_anim/png/^^2.png")';
|
|
console.log('2');
|
|
|
|
}, 1000);
|
|
}, 1000);
|
|
} else {
|
|
console.log('stop');
|
|
clearInterval(intervalEcoute);
|
|
}
|
|
}, 2000);
|
|
}
|
|
|
|
|
|
function animParle() {
|
|
parle = 0;
|
|
}
|
|
|
|
|
|
function animInsulte() {
|
|
|
|
}
|
|
|
|
|
|
// ________________________________________________________________________________________
|
|
|
|
|
|
|
|
envoyerQuestion.addEventListener("click",submitQuestion);
|
|
document.addEventListener("keydown", function(event) {
|
|
if (event.key === "Enter") {
|
|
submitQuestion();
|
|
}
|
|
});
|
|
|
|
barreStress.addEventListener("click", lireTexte);
|
|
questionInput.addEventListener("click",animEcoute);
|
|
addNoise();
|
|
teste();
|
|
test();
|
|
|
|
|