Skip to content

Commit

Permalink
signa
Browse files Browse the repository at this point in the history
  • Loading branch information
redd-rl committed Jan 27, 2025
1 parent 4ce8a13 commit 4b26ff3
Show file tree
Hide file tree
Showing 7 changed files with 801 additions and 0 deletions.
36 changes: 36 additions & 0 deletions nti.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>NTI counter.</title>
<link rel="stylesheet" href="static/nti/styles/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<meta content="NTI counter." property="og:title" />
<meta content="The NTI Countdown." property="og:description" />
<meta content="redd-rl.github.io/nti" property="og:url" />
<meta content="https://cdn.discordapp.com/attachments/382404542245109772/1135830650331594792/favicon-dark.png" property="og:image" />
<meta content="#666666" data-react-helmet="true" name="theme-color" />
<link href="https://fonts.googleapis.com/css?family=Lexend" rel="stylesheet">
<link href="favicon-light.png" rel="icon" media="(prefers-color-scheme: light)"/>
<link href="favicon-dark.png" rel="icon" media="(prefers-color-scheme: dark)"/>
</head>
</div>
<div id="wholeThing" onmouseover="playMusic()">
<body>

<canvas id="canvas"> </canvas>
<!-- Display the countdown timer in an element -->
<p id="demo"></p>
<script src="static/nti/scripts/conditional.js"> </script>
<script src="static/nti/scripts/timer.js"> </script>

<audio autoplay loop id="bgmusic">
<source src="https://cdn.discordapp.com/attachments/382404542245109772/1057180414139179018/yt1s.com_-_Hyper_Spoiler.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
<script src="static/nti/scripts/music.js"></script>
<div id="shadowBox">
<h1 class="rainbow_text_animated" id="demo">Loading...</h1>
</div>
</body>
</div>
</html>
34 changes: 34 additions & 0 deletions static/nti/scripts/conditional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var currentDate = new Date();
var currentYear = new Date().getFullYear();
var targetCountdownDay = new Date("Feb 14, " + currentYear + " 12:00:00 AM GMT+1 (CET)");
var stopDay = new Date("Feb 14, " + currentYear + " 11:59:59 PM GMT+1 (CET)");
var scriptAdded = false;

function checkDate() {
currentDate = new Date();
if (currentDate > targetCountdownDay && currentDate < stopDay&& !scriptAdded) {
scriptAdded = true;
var fireworks = document.createElement("script");
fireworks.src = "static/scripts/fireworks.js";
fireworks.id = "fireworks";
document.body.appendChild(fireworks);

var confetti = document.createElement("script");
confetti.src = "confetti.js";
confetti.id = "confetti";
document.body.appendChild(confetti);
}
if (currentDate > stopDay) {
scriptAdded = false;
try {
document.getElementById("fireworks").remove();
document.getElementById("confetti").remove();
document.getElementById("fireworksCanvas").remove();
document.getElementById("confettiCanvas").remove();
} catch (error) {
// pass
}
}
}

var checkDateInterval = setInterval(checkDate, 1000);
232 changes: 232 additions & 0 deletions static/nti/scripts/confetti.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@

(function () {
// globals
var canvas;
var ctx;
var W;
var H;
var mp = 150; //max particles
var particles = [];
var angle = 0;
var tiltAngle = 0;
var confettiActive = true;
var animationComplete = true;
var deactivationTimerHandler;
var reactivationTimerHandler;
var animationHandler;
var SCREEN_WIDTH = window.innerWidth;
var SCREEN_HEIGHT = window.innerHeight;
// objects

var particleColors = {
colorOptions: ["DodgerBlue", "OliveDrab", "Gold", "pink", "SlateBlue", "lightblue", "Violet", "PaleGreen", "SteelBlue", "SandyBrown", "Chocolate", "Crimson"],
colorIndex: 0,
colorIncrementer: 0,
colorThreshold: 10,
getColor: function () {
if (this.colorIncrementer >= 10) {
this.colorIncrementer = 0;
this.colorIndex++;
if (this.colorIndex >= this.colorOptions.length) {
this.colorIndex = 0;
}
}
this.colorIncrementer++;
return this.colorOptions[this.colorIndex];
}
}

function confettiParticle(color) {
this.x = Math.random() * W; // x-coordinate
this.y = (Math.random() * H) - H; //y-coordinate
this.r = RandomFromTo(10, 30); //radius;
this.d = (Math.random() * mp) + 10; //density;
this.color = color;
this.tilt = Math.floor(Math.random() * 10) - 10;
this.tiltAngleIncremental = (Math.random() * 0.07) + .05;
this.tiltAngle = 0;

this.draw = function () {
ctx.beginPath();
ctx.lineWidth = this.r / 2;
ctx.strokeStyle = this.color;
ctx.moveTo(this.x + this.tilt + (this.r / 4), this.y);
ctx.lineTo(this.x + this.tilt, this.y + this.tilt + (this.r / 4));
return ctx.stroke();
}
}



function InitializeButton() {
$('#stopButton').click(DeactivateConfetti);
$('#startButton').click(RestartConfetti);
}

function SetGlobals() {
ctx = canvas.getContext("2d");
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
}


function InitializeConfetti() {
particles = [];
animationComplete = false;
for (var i = 0; i < mp; i++) {
var particleColor = particleColors.getColor();
particles.push(new confettiParticle(particleColor));
}
StartConfetti();
}

$(document).ready(function() {
canvas = document.createElement("canvas");
canvas.id = "confettiCanvas";
document.body.appendChild(canvas);
SetGlobals();
InitializeConfetti();
canvas.width = SCREEN_WIDTH;
canvas.height = SCREEN_HEIGHT;

$(window).resize(function() {
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
});
});

function Draw() {
ctx.clearRect(0, 0, W, H);
var results = [];
for (var i = 0; i < mp; i++) {
(function (j) {
results.push(particles[j].draw());
})(i);
}
Update();

return results;
}

function RandomFromTo(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}


function Update() {
var remainingFlakes = 0;
var particle;
angle += 0.01;
tiltAngle += 0.1;

for (var i = 0; i < mp; i++) {
particle = particles[i];
if (animationComplete) return;

if (!confettiActive && particle.y < -15) {
particle.y = H + 100;
continue;
}

stepParticle(particle, i);

if (particle.y <= H) {
remainingFlakes++;
}
CheckForReposition(particle, i);
}

if (remainingFlakes === 0) {
StopConfetti();
}
}

function CheckForReposition(particle, index) {
if ((particle.x > W + 20 || particle.x < -20 || particle.y > H) && confettiActive) {
if (index % 5 > 0 || index % 2 == 0) //66.67% of the flakes
{
repositionParticle(particle, Math.random() * W, -10, Math.floor(Math.random() * 10) - 20);
} else {
if (Math.sin(angle) > 0) {
//Enter from the left
repositionParticle(particle, -20, Math.random() * H, Math.floor(Math.random() * 10) - 20);
} else {
//Enter from the right
repositionParticle(particle, W + 20, Math.random() * H, Math.floor(Math.random() * 10) - 20);
}
}
}
}
function stepParticle(particle, particleIndex) {
particle.tiltAngle += particle.tiltAngleIncremental;
particle.y += (Math.cos(angle + particle.d) + 3 + particle.r / 2) / 10;
particle.x += Math.sin(angle);
particle.tilt = (Math.sin(particle.tiltAngle - (particleIndex / 3))) * 15;
}

function repositionParticle(particle, xCoordinate, yCoordinate, tilt) {
particle.x = xCoordinate;
particle.y = yCoordinate;
particle.tilt = tilt;
}

function StartConfetti() {
W = window.innerWidth;
H = window.innerHeight;
canvas.width = W;
canvas.height = H;
(function animloop() {
if (SCREEN_WIDTH != window.innerWidth) {
canvas.width = SCREEN_WIDTH = window.innerWidth;
}
if (SCREEN_HEIGHT != window.innerHeight) {
canvas.height = SCREEN_HEIGHT = window.innerHeight;
}
if (animationComplete) return null;
animationHandler = requestAnimFrame(animloop);
return Draw();
})();
}

function ClearTimers() {
clearTimeout(reactivationTimerHandler);
clearTimeout(animationHandler);
}

function DeactivateConfetti() {
confettiActive = false;
ClearTimers();
}

function StopConfetti() {
animationComplete = true;
if (ctx == undefined) return;
ctx.clearRect(0, 0, W, H);
}

function RestartConfetti() {
ClearTimers();
StopConfetti();
reactivationTimerHandler = setTimeout(function () {
confettiActive = true;
animationComplete = false;
InitializeConfetti();
}, 100);

}

window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
return window.setTimeout(callback, 1000 / 60);
};
})();
})();
Loading

0 comments on commit 4b26ff3

Please sign in to comment.