JSFiddle - React, Tailwind, and code Playground
HTML
<link href="https://fonts.googleapis.com/css?family=Mountains+of+Christmas" rel="stylesheet">
<canvas id="cv" width="600px" height="400px"><</canvas>
JavaScript
// Created by tensaix2j
function Christmas() {
this.snows = [];
this.tick = 0;
this.init = function() {
this.canvas = document.getElementById("cv");
this.canvas.style.backgroundColor = "#ffffff";
this.ctx = this.canvas.getContext('2d');
for ( i = 0 ; i < 50 ; i++ ) {
obj = {}
obj.x = Math.random() * this.canvas.width;
obj.y = Math.random() * this.canvas.height;
obj.tick = Math.random();
obj.cr = Math.random() * 4 - 2;
this.snows.push(obj);
}
this.update();
}
this.update = function() {
for ( i = 0 ; i < this.snows.length ; i++) {
this.snows[i].y += 1;
this.snows[i].x += this.snows[i].cr * Math.cos(this.snows[i].tick);
this.snows[i].tick += 0.01;
if ( this.snows[i].y > this.canvas.height ) {
this.snows[i].y = Math.random() * 50 - 50;
this.snows[i].x = Math.random() * this.canvas.width;
this.snows[i].cr = Math.random() * 2 - 1;
this.snows[i].tick = Math.random();
}
}
this.tick += 1;
this.draw();
var cmt = this;
window.requestAnimationFrame( function() {
cmt.update();
});
}
this.draw = function() {
this.ctx.clearRect( 0,0, this.canvas.width , this.canvas.height );
this.drawChrismasTree(500, 160, 20 );
this.drawChrismasTree(420, 180, 12 );
for ( i = 0 ; i < this.snows.length ; i++ ) {
this.ctx.fillStyle = "rgba( 0 , 0 ,0, " + (i/this.snows.length) +")";
this.ctx.font = i +"px Comic Sans";
this.ctx.fillText( "*",this.snows[i].x , this.snows[i].y);
}
var mrcm_fontsize = ( Math.cos(this.tick / 100 ) + 15 ) * 3 ;
this.ctx.font = mrcm_fontsize + "px Mountains of Christmas";
this.ctx.fillText( "Merry Christmas!", 170, 120);
}
this.drawChrismasTree = function( x , y , size) {
var posoffset = Math.cos(this.tick/50) * 5;
var curveoffset = Math.cos(this.tick/50) * 0.1;
for ( i = 4 ;...