Skip to content

Commit

Permalink
1st birthday confetti!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
nayakrujul committed Oct 20, 2024
1 parent b88c344 commit ad05ad3
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 4 deletions.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
<body>
<div id="header"></div>
<div id="content">
<h1 id="main-header"><span id="orange"></span>&nbsp;<span id="purple"></span></h1>
<h1 id="main-header">
<!-- <span id="orange"></span>&nbsp;<span id="purple"></span> -->
<span id="orange">Celebrating our</span> <span id="purple">first birthday!</span>
</h1>
<h2 id="main-text">A new way to learn vocabulary, <i>completely&nbsp;for&nbsp;free.</i></h2>
<h3 id="link-text"><a href="./folders/">Explore vocabulary folders now</a> &nbsp; <span id="animate-arrow">&rarr;</span></h3>
</div>
<canvas id="canvas"></canvas>
<div id="footer"></div>
<script src="./scripts/lightdark.js"></script>
<script src="./scripts/header.js"></script>
<script src="./scripts/cookies.js"></script>
<script src="./scripts/homepage.js"></script>
<script src="./scripts/confetti.js"></script>
<script src="./scripts/footer.js"></script>
<script src="./scripts/misc.js"></script>
<script async data-id="101454906" src="//static.getclicky.com/js"></script>
Expand Down
Binary file added logos/logo-birthday.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions scripts/confetti.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
let W = window.innerWidth;
let H = window.innerHeight;
const canvas = document.getElementById("canvas");
const context = canvas.getContext("2d");
const maxConfettis = 150;
const particles = [];

const possibleColors = [
"DodgerBlue",
"OliveDrab",
"Gold",
"Pink",
"SlateBlue",
"LightBlue",
"Gold",
"Violet",
"PaleGreen",
"SteelBlue",
"SandyBrown",
"Chocolate",
"Crimson"
];

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

function confettiParticle() {
this.x = Math.random() * W; // x
this.y = Math.random() * H - H; // y
this.r = randomFromTo(11, 33); // radius
this.d = Math.random() * maxConfettis + 11;
this.color =
possibleColors[Math.floor(Math.random() * possibleColors.length)];
this.tilt = Math.floor(Math.random() * 33) - 11;
this.tiltAngleIncremental = Math.random() * 0.07 + 0.05;
this.tiltAngle = 0;

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

function Draw() {
const results = [];

// Magical recursive functional love
requestAnimationFrame(Draw);

context.clearRect(0, 0, W, window.innerHeight);

for (var i = 0; i < maxConfettis; i++) {
results.push(particles[i].draw());
}

let particle = {};
let remainingFlakes = 0;
for (var i = 0; i < maxConfettis; i++) {
particle = particles[i];

particle.tiltAngle += particle.tiltAngleIncremental;
particle.y += (Math.cos(particle.d) + 3 + particle.r / 2) / 2;
particle.tilt = Math.sin(particle.tiltAngle - i / 3) * 15;

if (particle.y <= H) remainingFlakes++;

// If a confetti has fluttered out of view,
// bring it back to above the viewport and let if re-fall.
if (particle.x > W + 30 || particle.x < -30 || particle.y > H) {
particle.x = Math.random() * W;
particle.y = -30;
particle.tilt = Math.floor(Math.random() * 10) - 20;
}
}

return results;
}

window.addEventListener(
"resize",
function() {
W = window.innerWidth;
H = window.innerHeight;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
},
false
);

// Push new confetti objects to `particles[]`
for (var i = 0; i < maxConfettis; i++) {
particles.push(new confettiParticle());
}

// Initialize
canvas.width = W;
canvas.height = H;
Draw();
4 changes: 2 additions & 2 deletions scripts/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function add_header() {

if (screen_width >= 1000 && header_version !== 0) {
document.getElementById("header").innerHTML = `
<a href="/"><img src="/logos/logo-banner.png" id="banner-logo" alt="VTP6" /></a>
<a href="/"><img src="/logos/logo-birthday.png" id="banner-logo" alt="VTP6" /></a>
<a href="/help/" class="banner-link no-underline">HELP</a>
<a href="/folders/" class="banner-link no-underline">FOLDERS</a>
<a href="/grammar/" class="banner-link no-underline">GRAMMAR</a>
Expand All @@ -20,7 +20,7 @@ function add_header() {
} else if (screen_width < 1000 && header_version !== 1) {
document.getElementById("header").innerHTML = `
<img id="dropdown-arrow" alt="Menu" />
<a href="/" class="centre"><img src="/logos/logo-banner.png" id="banner-logo" alt="VTP6" /></a>
<a href="/" class="centre"><img src="/logos/logo-birthday.png" id="banner-logo" alt="VTP6" /></a>
<div id="dropdown-container" class="hidden">
<a href="/help/" class="banner-link no-underline">HELP</a>
<a href="/folders/" class="banner-link no-underline">FOLDERS</a>
Expand Down
4 changes: 3 additions & 1 deletion scripts/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ function increment() {
if (++n <= 6) setTimeout(increment, 50)
}

next_run();
// Uncomment when birthday is over
// next_run();

7 changes: 7 additions & 0 deletions styles/homepage.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ div#content {
}
}

canvas#canvas {
overflow-y: hidden;
overflow-x: hidden;
width: 100%;
margin: 0;
}

@media (max-width: 999px) {
div#content {
h1#main-header {
Expand Down

0 comments on commit ad05ad3

Please sign in to comment.