Skip to content

Commit

Permalink
Bada Boom
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexanders committed Sep 25, 2024
0 parents commit 0d6b24c
Show file tree
Hide file tree
Showing 698 changed files with 3,497,201 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea/
*.iml
*.iws
*.eml
out/
.DS_Store
.svn
log/*.log
tmp/**
node_modules/
.sass-cache
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/test
/examples
.github
.sass-cache
gulpfile.js
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2011-2024 Hakim El Hattab, http://hakim.se, and reveal.js contributors

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.
165 changes: 165 additions & 0 deletions OLD_js/components/playback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* UI component that lets the use control auto-slide
* playback via play/pause.
*/
export default class Playback {

/**
* @param {HTMLElement} container The component will append
* itself to this
* @param {function} progressCheck A method which will be
* called frequently to get the current playback progress on
* a range of 0-1
*/
constructor( container, progressCheck ) {

// Cosmetics
this.diameter = 100;
this.diameter2 = this.diameter/2;
this.thickness = 6;

// Flags if we are currently playing
this.playing = false;

// Current progress on a 0-1 range
this.progress = 0;

// Used to loop the animation smoothly
this.progressOffset = 1;

this.container = container;
this.progressCheck = progressCheck;

this.canvas = document.createElement( 'canvas' );
this.canvas.className = 'playback';
this.canvas.width = this.diameter;
this.canvas.height = this.diameter;
this.canvas.style.width = this.diameter2 + 'px';
this.canvas.style.height = this.diameter2 + 'px';
this.context = this.canvas.getContext( '2d' );

this.container.appendChild( this.canvas );

this.render();

}

setPlaying( value ) {

const wasPlaying = this.playing;

this.playing = value;

// Start repainting if we weren't already
if( !wasPlaying && this.playing ) {
this.animate();
}
else {
this.render();
}

}

animate() {

const progressBefore = this.progress;

this.progress = this.progressCheck();

// When we loop, offset the progress so that it eases
// smoothly rather than immediately resetting
if( progressBefore > 0.8 && this.progress < 0.2 ) {
this.progressOffset = this.progress;
}

this.render();

if( this.playing ) {
requestAnimationFrame( this.animate.bind( this ) );
}

}

/**
* Renders the current progress and playback state.
*/
render() {

let progress = this.playing ? this.progress : 0,
radius = ( this.diameter2 ) - this.thickness,
x = this.diameter2,
y = this.diameter2,
iconSize = 28;

// Ease towards 1
this.progressOffset += ( 1 - this.progressOffset ) * 0.1;

const endAngle = ( - Math.PI / 2 ) + ( progress * ( Math.PI * 2 ) );
const startAngle = ( - Math.PI / 2 ) + ( this.progressOffset * ( Math.PI * 2 ) );

this.context.save();
this.context.clearRect( 0, 0, this.diameter, this.diameter );

// Solid background color
this.context.beginPath();
this.context.arc( x, y, radius + 4, 0, Math.PI * 2, false );
this.context.fillStyle = 'rgba( 0, 0, 0, 0.4 )';
this.context.fill();

// Draw progress track
this.context.beginPath();
this.context.arc( x, y, radius, 0, Math.PI * 2, false );
this.context.lineWidth = this.thickness;
this.context.strokeStyle = 'rgba( 255, 255, 255, 0.2 )';
this.context.stroke();

if( this.playing ) {
// Draw progress on top of track
this.context.beginPath();
this.context.arc( x, y, radius, startAngle, endAngle, false );
this.context.lineWidth = this.thickness;
this.context.strokeStyle = '#fff';
this.context.stroke();
}

this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );

// Draw play/pause icons
if( this.playing ) {
this.context.fillStyle = '#fff';
this.context.fillRect( 0, 0, iconSize / 2 - 4, iconSize );
this.context.fillRect( iconSize / 2 + 4, 0, iconSize / 2 - 4, iconSize );
}
else {
this.context.beginPath();
this.context.translate( 4, 0 );
this.context.moveTo( 0, 0 );
this.context.lineTo( iconSize - 4, iconSize / 2 );
this.context.lineTo( 0, iconSize );
this.context.fillStyle = '#fff';
this.context.fill();
}

this.context.restore();

}

on( type, listener ) {
this.canvas.addEventListener( type, listener, false );
}

off( type, listener ) {
this.canvas.removeEventListener( type, listener, false );
}

destroy() {

this.playing = false;

if( this.canvas.parentNode ) {
this.container.removeChild( this.canvas );
}

}

}
Loading

0 comments on commit 0d6b24c

Please sign in to comment.