commit 0cd1d502c7ed407f55579ebff05cb1673eab23c7 Author: Samuel Sloniker Date: Sat Dec 31 16:04:35 2022 -0800 Initial commit diff --git a/DSEG14ClassicMini-Regular.woff b/DSEG14ClassicMini-Regular.woff new file mode 100644 index 0000000..3444c9d Binary files /dev/null and b/DSEG14ClassicMini-Regular.woff differ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..18754e1 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,118 @@ +Code +==== + +Code for fireworks animation copyright (c) 2022 Vitalij Ryndin +Other code copyright (c) 2022 Samuel Sloniker + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Font +==== + +The font is DSEG14 Classic Mini Regular. + +Copyright (c) 2017, keshikan (http://www.keshikan.net), with Reserved Font Name +"DSEG". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide development +of collaborative font projects, to support the font creation efforts of +academic and linguistic communities, and to provide a free and open framework +in which fonts may be shared and improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The fonts, +including any derivative works, can be bundled, embedded, redistributed and/or +sold with any software provided that any reserved names are not used by +derivative works. The fonts and derivatives, however, cannot be released under +any other type of license. The requirement for fonts to remain under this +license does not apply to any document created using the fonts or their +derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright Holder(s) +under this license and clearly marked as such. This may include source files, +build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the copyright +statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, or +substituting -- in part or in whole -- any of the components of the Original +Version, by changing formats or by porting the Font Software to a new +environment. + +"Author" refers to any designer, engineer, programmer, technical writer or +other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining a copy of +the Font Software, to use, study, copy, merge, embed, modify, redistribute, and +sell modified and unmodified copies of the Font Software, subject to the +following conditions: + +1) Neither the Font Software nor any of its individual components, in Original +or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy contains +the above copyright notice and this license. These can be included either as +stand-alone text files, human-readable headers or in the appropriate +machine-readable metadata fields within text or binary files as long as those +fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font Name(s) +unless explicit written permission is granted by the corresponding Copyright +Holder. This restriction only applies to the primary font name as presented to +the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software +shall not be used to promote, endorse or advertise any Modified Version, except +to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) +or with their explicit written permission. + +5) The Font Software, modified or unmodified, in part or in whole, must be +distributed entirely under this license, and must not be distributed under any +other license. The requirement for fonts to remain under this license does not +apply to any document created using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, +TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, +INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE +THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/fireworks.js b/fireworks.js new file mode 100644 index 0000000..08bbe58 --- /dev/null +++ b/fireworks.js @@ -0,0 +1,6 @@ +/*! + * fireworks-js 1.4.1 by Vitalij Ryndin (https://crashmax.ru) + * https://fireworks.js.org + * License MIT + */ +!function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i();else if("function"==typeof define&&define.amd)define([],i);else{var s=i();for(var e in s)("object"==typeof exports?exports:t)[e]=s[e]}}(this,(function(){return(()=>{"use strict";var t={511:(t,i,s)=>{Object.defineProperty(i,"__esModule",{value:!0}),i.Explosion=void 0;var e=s(909);i.Explosion=class{constructor(t){var{x:i,y:s,ctx:n,hue:h,gravity:o,friction:a,brightness:r,flickering:c,lineWidth:_,explosionLength:d}=t;for(this._coordinates=[],this._alpha=1,this._x=i,this._y=s,this._ctx=n,this._gravity=o,this._friction=a,this._flickering=c,this._lineWidth=_,this._explosionLength=d;this._explosionLength--;)this._coordinates.push([i,s]);this._angle=(0,e.randomFloat)(0,2*Math.PI),this._speed=(0,e.randomInt)(1,10),this._hue=(0,e.randomInt)(h-20,h+20),this._brightness=(0,e.randomInt)(r.min,r.max),this._decay=(0,e.randomFloat)(r.decay.min,r.decay.max)}update(t){this._coordinates.pop(),this._coordinates.unshift([this._x,this._y]),this._speed*=this._friction,this._x+=Math.cos(this._angle)*this._speed,this._y+=Math.sin(this._angle)*this._speed+this._gravity,this._alpha-=this._decay,this._alpha<=this._decay&&t()}draw(){var t=this._coordinates.length-1;this._ctx.beginPath(),this._ctx.lineWidth=this._lineWidth,this._ctx.fillStyle=(0,e.hsla)(this._hue,this._brightness,this._alpha),this._ctx.moveTo(this._coordinates[t][0],this._coordinates[t][1]),this._ctx.lineTo(this._x,this._y),this._ctx.strokeStyle=(0,e.hsla)(this._hue,this._flickering?(0,e.randomFloat)(0,this._brightness):this._brightness,this._alpha),this._ctx.stroke()}}},909:(t,i)=>{Object.defineProperty(i,"__esModule",{value:!0}),i.hsla=i.getDistance=i.randomInt=i.randomFloat=void 0,i.randomFloat=function(t,i){return Math.random()*(i-t)+t},i.randomInt=function(t,i){return Math.floor(t+Math.random()*(i+1-t))},i.getDistance=function(t,i,s,e){var n=Math.pow;return Math.sqrt(n(t-s,2)+n(i-e,2))},i.hsla=function(t,i){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return"hsla(".concat(t,", 100%, ").concat(i,"%, ").concat(s,")")}},449:function(t,i,s){var e=this&&this.__awaiter||function(t,i,s,e){return new(s||(s=Promise))((function(n,h){function o(t){try{r(e.next(t))}catch(t){h(t)}}function a(t){try{r(e.throw(t))}catch(t){h(t)}}function r(t){var i;t.done?n(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(o,a)}r((e=e.apply(t,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.Sound=void 0;var n=s(909);i.Sound=class{constructor(t){this._buffer=[],this.onInit=!0,this.options=Object.assign({enabled:!1,files:["explosion0.mp3","explosion1.mp3","explosion2.mp3"],volume:{min:4,max:8}},t),this.init()}init(){this.onInit&&this.options.enabled&&(this.onInit=!1,this._audioContext=new(window.AudioContext||window.webkitAudioContext),this.load())}load(){return e(this,void 0,void 0,(function*(){for(var t of this.options.files){var i=yield(yield fetch(t)).arrayBuffer();this._audioContext.decodeAudioData(i).then((t=>{this._buffer.push(t)})).catch((t=>{throw t}))}}))}play(){if(this.options.enabled&&this._buffer.length){var t=this._audioContext.createBufferSource(),i=this._buffer[(0,n.randomInt)(0,this._buffer.length-1)],s=this._audioContext.createGain();t.buffer=i,s.gain.value=(0,n.randomFloat)(this.options.volume.min/100,this.options.volume.max/100),s.connect(this._audioContext.destination),t.connect(s),t.start(0)}else this.init()}}},668:(t,i,s)=>{Object.defineProperty(i,"__esModule",{value:!0}),i.Trace=void 0;var e=s(909);i.Trace=class{constructor(t){var{x:i,y:s,dx:n,dy:h,ctx:o,hue:a,speed:r,traceLength:c,acceleration:_}=t;for(this._coordinates=[],this._currentDistance=0,this._x=i,this._y=s,this._sx=i,this._sy=s,this._dx=n,this._dy=h,this._ctx=o,this._hue=a,this._speed=r,this._traceLength=c,this._acceleration=_,this._totalDistance=(0,e.getDistance)(i,s,n,h);this._traceLength--;)this._coordinates.push([i,s]);this._angle=Math.atan2(h-s,n-i),this._brightness=(0,e.randomInt)(50,70)}update(t){this._coordinates.pop(),this._coordinates.unshift([this._x,this._y]),this._speed*=this._acceleration;var i=Math.cos(this._angle)*this._speed,s=Math.sin(this._angle)*this._speed;this._currentDistance=(0,e.getDistance)(this._sx,this._sy,this._x+i,this._y+s),this._currentDistance>=this._totalDistance?t(this._dx,this._dy,this._hue):(this._x+=i,this._y+=s)}draw(){var t=this._coordinates.length-1;this._ctx.beginPath(),this._ctx.moveTo(this._coordinates[t][0],this._coordinates[t][1]),this._ctx.lineTo(this._x,this._y),this._ctx.strokeStyle=(0,e.hsla)(this._hue,this._brightness),this._ctx.stroke()}}}},i={};function s(e){var n=i[e];if(void 0!==n)return n.exports;var h=i[e]={exports:{}};return t[e].call(h.exports,h,h.exports,s),h.exports}var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.Fireworks=void 0;var i=s(668),n=s(449),h=s(511),o=s(909);t.Fireworks=class{constructor(t){var{autoresize:i=!0,boundaries:s,brightness:e,delay:h,hue:o,mouse:a,sound:r,rocketsPoint:c,lineWidth:_,lineStyle:d="round",flickering:l=50,trace:u=3,traceSpeed:m=10,intensity:p=30,explosion:x=5,gravity:v=1.5,opacity:g=.5,particles:f=50,friction:y=.95,acceleration:b=1.05}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this._tick=0,this._timestamp=performance.now(),this._version="1.4.1",this._running=!1,this._m=!1,t instanceof HTMLCanvasElement?(this._container=t,this._canvas=t):(this._container=t,this._canvas=document.createElement("canvas"),this._container.appendChild(this._canvas)),this._ctx=this._canvas.getContext("2d"),this._sound=new n.Sound(r),this.setSize(),this.setBoundaries(Object.assign({visible:!1,x:50,y:50},s)),this.autoresize=i,this.trace=u,this.explosion=x,this.gravity=v,this.opacity=g,this.particles=f,this.friction=y,this.acceleration=b,this.flickering=l,this.intensity=p,this.traceSpeed=m,this.lineStyle=d,this.hue=Object.assign({min:0,max:360},o),this.rocketsPoint=Object.assign({min:50,max:50},c),this.lineWidth=Object.assign({explosion:{min:1,max:3},trace:{min:1,max:2}},_),this.mouse=Object.assign({click:!1,move:!1,max:1},a),this.delay=Object.assign({min:15,max:30},h),this.brightness=Object.assign({min:50,max:80,decay:{min:.015,max:.03}},e),this.autoresize&&window.addEventListener("resize",(()=>this.windowResize())),this._canvas.addEventListener("mousedown",(t=>{this.mouseDown(t)})),this._canvas.addEventListener("mouseup",(t=>{this.mouseUp(t)})),this._canvas.addEventListener("mousemove",(t=>{this.mouseMove(t)}))}get isRunning(){return this._running}get version(){return this._version}start(){this._running||(this._running=!0,this.clear(),this.render())}stop(){this._running&&(this._running=!1,this.clear())}unmount(){window.removeEventListener("resize",this.windowResize),this._canvas.removeEventListener("mousedown",this.mouseDown),this._canvas.removeEventListener("mouseup",this.mouseUp),this._canvas.removeEventListener("mousemove",this.mouseMove)}pause(){this._running=!this._running,this._running&&this.render()}clear(){this._ctx&&(this._traces=[],this._explosions=[],this._ctx.clearRect(0,0,this._width,this._height))}setOptions(t){for(var[i,s]of Object.entries(t)){var e=Object.prototype.hasOwnProperty.call(this,i);if("function"==typeof this[i])throw new Error("You cannot change the methods of the class!");e&&("object"==typeof this[i]?Object.assign(this[i],s):this[i]=s),"sound"===i&&Object.assign(this._sound.options,s)}}setSize(){var{width:t=(this._container instanceof HTMLCanvasElement?this._canvas.width:this._container.clientWidth),height:i=(this._container instanceof HTMLCanvasElement?this._canvas.height:this._container.clientHeight)}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._width=t,this._height=i,this._canvas.width=t,this._canvas.height=i,this.setBoundaries({width:t,height:i})}setBoundaries(t){this.boundaries=Object.assign(Object.assign({},this.boundaries),t)}useMouse(t,i){(this.mouse.click||this.mouse.move)&&(this._mx=t.pageX-this._canvas.offsetLeft,this._my=t.pageY-this._canvas.offsetTop,this._m=i)}windowResize(){this.setSize()}mouseDown(t){this.useMouse(t,this.mouse.click)}mouseUp(t){this.useMouse(t,!1)}mouseMove(t){this.useMouse(t,this._m)}render(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._timestamp;if(this._ctx&&this._running){requestAnimationFrame((t=>this.render(t))),this._ctx.globalCompositeOperation="destination-out",this._ctx.fillStyle="rgba(0, 0, 0, ".concat(this.opacity,")"),this._ctx.fillRect(0,0,this._width,this._height),this._ctx.globalCompositeOperation="lighter",this._ctx.lineCap=this.lineStyle,this._ctx.lineJoin="round",this.drawBoundaries(),this.initTrace(),this.drawTrace(),this.drawExplosion();var i=t-this._timestamp;this._timestamp=t,this._tick+=i*(this.intensity*Math.PI)/1e3}}drawBoundaries(){this.boundaries.visible&&(this._ctx.beginPath(),this._ctx.lineWidth=1,this._ctx.strokeStyle="red",this._ctx.rect(this.boundaries.x,this.boundaries.y,this.boundaries.width-2*this.boundaries.x,.5*this.boundaries.height),this._ctx.stroke())}initTrace(){this._ds=(0,o.randomInt)(this.delay.min,this.delay.max),(this._tick>this._ds||this._m&&this.mouse.max>this._traces.length)&&(this._traces.push(new i.Trace({x:this._width*(0,o.randomInt)(this.rocketsPoint.min,this.rocketsPoint.max)/100,y:this._height,dx:this._mx&&this.mouse.move||this._m?this._mx:(0,o.randomInt)(this.boundaries.x,this.boundaries.width-2*this.boundaries.x),dy:this._my&&this.mouse.move||this._m?this._my:(0,o.randomInt)(this.boundaries.y,.5*this.boundaries.height),ctx:this._ctx,hue:(0,o.randomInt)(this.hue.min,this.hue.max),speed:this.traceSpeed,acceleration:this.acceleration,traceLength:this.trace})),this._tick=0)}drawTrace(){var t=this._traces.length;for(this._ctx.lineWidth=(0,o.randomFloat)(this.lineWidth.trace.min,this.lineWidth.trace.max);t--;)this._traces[t].draw(),this._traces[t].update(((i,s,e)=>{this.initExplosion(i,s,e),this._sound.play(),this._traces.splice(t,1)}))}initExplosion(t,i,s){for(var e=this.particles;e--;)this._explosions.push(new h.Explosion({x:t,y:i,ctx:this._ctx,hue:s,friction:this.friction,gravity:this.gravity,flickering:(0,o.randomInt)(0,100)<=this.flickering,lineWidth:(0,o.randomFloat)(this.lineWidth.explosion.min,this.lineWidth.explosion.max),explosionLength:Math.round(this.explosion),brightness:this.brightness}))}drawExplosion(){for(var t=this._explosions.length;t--;)this._explosions[t].draw(),this._explosions[t].update((()=>{this._explosions.splice(t,1)}))}}})(),e})()})); \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..f380b46 --- /dev/null +++ b/index.html @@ -0,0 +1,20 @@ + + + + New Year Coundown + + + + + + +
+

NEW YEAR COUNTDOWN

+

loading

+
+

Font (DSEG14 Classic Mini Regular) by Keshikan; effect that happens at midnight by Vitalij Ryndin; all other code by Samuel Sloniker. Click here for license information. This site is open-source.

+
+
+
+ + diff --git a/main.js b/main.js new file mode 100644 index 0000000..26d9b5c --- /dev/null +++ b/main.js @@ -0,0 +1,69 @@ +"use strict" + +/* + * Copyright (c) 2022 Samuel Sloniker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +function format(number) { + return (number < 10)?("0" + String(number)):String(number) +} + +function adjust() { + let ce = document.querySelector("#countdown") + let cec = document.querySelector("#countdownbox") + let cet = document.querySelector("#countdowntext") + + let time = (newYear - new Date()) / 1000 + if (time <= 0) { + clearInterval(intervalID) + cet.innerHTML = "HAPPY NEW YEAR" + let fireworks = new Fireworks(document.querySelector("div#firepops"), { /* options */ }) + fireworks.start() + } else { + let days = Math.floor(time / (60 * 60 * 24)) + let hours = Math.floor(time / (60 * 60)) % 24 + let minutes = Math.floor(time / 60) % 60 + let seconds = Math.floor(time) % 60 + cet.textContent = (days?(format(days) + ":"):"") + + ((hours || days)?(format(hours) + ":"):"") + + ((minutes || hours || days)?(format(minutes) + ":"):"") + + format(seconds) + } + + let fontSize = 1 + ce.style.fontSize = String(fontSize - 1) + "px" + ce.style.fontSize = "1px" + while (ce.clientHeight <= cec.clientHeight && cec.scrollWidth <= document.documentElement.clientWidth && fontSize <= 180) { + fontSize += 1 + ce.style.fontSize = String(fontSize) + "px" + } + +} + +function main() { + window.newYear = new Date(new Date().getFullYear() + 1, 0, 1) + document.querySelector("h1#header").textContent = "NEW YEAR " + String(newYear.getFullYear()) + " COUNTDOWN" + window.intervalID = setInterval(adjust, 100) + window.addEventListener("resize", adjust) + adjust() +} + +window.onload = main diff --git a/style.css b/style.css new file mode 100644 index 0000000..c7d3895 --- /dev/null +++ b/style.css @@ -0,0 +1,68 @@ +@font-face { + font-family: "DSEG"; + src: url(DSEG14ClassicMini-Regular.woff); +} + +body { + background-color: #000; + text-align: center; + margin: 0 !important; + padding: 0 !important; + font-family: DSEG; + color: #0F0 +} + +div#container { + display: flex; + flex-flow: column; + height: 100vh; +} + +h1 { + font-size: 32pt; + flex: 0 1 auto; + margin-bottom: 0; +} + +div#countdownbox { + font-size: 20pt; + flex: 1 1 auto; + overflow: hidden; + align-items: center; + justify-content: center; + display: flex; +} + +p#countdown { + margin-top: 0; + margin-bottom: 0; + margin-left: 10px; + margin-right: 10px; +} + +div#creditbox { + font-size: 8pt; + padding-left: 4px; + padding-right: 4px; + flex: 0 1 auto; + z-index: 200; +} + +div#creditbox p.credits { + margin-top: 2px; + margin-bottom: 2px; + font-family: sans-serif; +} + +div#creditbox p.credits a { + color: #0F8; +} + +div#firepops { + position: absolute; + top: 0px; + left: 0px; + height: 100vh; + width: 100vw; + z-index: 100; +}