Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return false;
}
const shpsContainer = document.getElementById("shps");
let shpArray = []; // Array to store the shp elements
cTime = Date.now()
for (let i = 0; i < 20; i++) {
const shpDiv = document.createElement("div");
shpDiv.classList.add("shp");
shpDiv.id = "shp-" + i; // Add id with shp-index
shpsContainer.appendChild(shpDiv);
pos = [Math.random()*100, Math.random()*100]
vel = [Math.random()*4-2, Math.random()*4-2]
shpDiv.style.backgroundColor = getRandomColor(); // Set random background color
shpArray.push([shpDiv, pos, vel]); // Add shpDiv to the array
}
function getRandomColor() {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color + "88";
}
let prevTime = Date.now();
function animShps(){
wrapWidth = shpsContainer.clientWidth;
wrapHeight = shpsContainer.clientHeight;
let cTime = Date.now();
let dTime = (cTime - prevTime) / 1000;
for (let i = 0; i < shpArray.length; i++) {
const shp = shpArray[i];
const pos = shp[1];
const vel = shp[2];
if((pos[0] + vel[0]) >= 100){
vel[0] = vel[0] * -1;
}
if((pos[1] + vel[1]) >= 100){
vel[1] = vel[1] * -1;
}
if((pos[0] + vel[0]) <= 0){
vel[0] = vel[0] * -1;
}
if((pos[1] + vel[1]) <= 0){
vel[1] = vel[1] * -1;
}
if(!(0 < pos[0] < 100)){
pos[0] = 50;
}
if(!(0 < pos[1] < 100)){
pos[1] = 50;
}
pos[0] += vel[0] * dTime;
pos[1] += vel[1] * dTime;
shpArray[i] = [shp[0], pos, vel];
shpSz = [shp[0].clientWidth, shp[0].clientHeight]
abPosX = pos[0]/100*wrapWidth-(shpSz[0]/2);
abPosY = pos[1]/100*wrapHeight-(shpSz[1]/2);
shp[0].style.left = (abPosX-50)+"px";
shp[0].style.top = (abPosY-50)+"px";
}
prevTime = cTime;
requestAnimationFrame(animShps);
}
requestAnimationFrame(animShps);
messageWrapper = document.querySelector(".messagesWrapper");
messageWrapper.scrollTop = messageWrapper.scrollHeight;
messageWrapper.style.scrollBehavior = "smooth";