-
Notifications
You must be signed in to change notification settings - Fork 1
/
pendulum.min.js
1 lines (1 loc) · 3.5 KB
/
pendulum.min.js
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Pendulum=e()}}(function(){var e,t,n;return function r(e,t,n){function i(o,u){if(!t[o]){if(!e[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(s)return s(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=t[o]={exports:{}};e[o][0].call(l.exports,function(t){var n=e[o][1][t];return i(n?n:t)},l,l.exports,r,e,t,n)}return t[o].exports}var s=typeof require=="function"&&require;for(var o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,t,n){function r(e){var t="dontDisplayHorrendousMessageBoxOnIE8EvenThoughItsAShittyBrowserNobodyShouldNeverEverUse";navigator.userAgent.match(/MSIE 8/i)&&e[t]!==!0&&alert("Please consider upgrading your browser. It's really old."),this.options=e,this.canvas=document.createElement("canvas"),this.fromColor=this.parseColor(e.color1),this.toColor=this.parseColor(e.color0),this.timeStep=0,this.context=this.canvas.getContext("2d"),this.diffR=this.toColor.r-this.fromColor.r,this.diffG=this.toColor.g-this.fromColor.g,this.diffB=this.toColor.b-this.fromColor.b,this.clearFillStyle="rgba(255,255,255,"+this.options.fadeout+")";var n=e.ballHeight+e.ballRadius*4,r=(e.ballRadius*2+1)*e.numBalls+e.ballRadius,i=window.devicePixelRatio||1;this.canvas.width=r*i,this.canvas.height=n*i,this.canvas.style.width=r+"px",this.canvas.style.height=n+"px",this.context.strokeStyle="rgba(0, 0, 0, 0)",this.context.scale(i,i),this.play()}r.prototype.play=function(){if(this.interval)return;this.tick(),this.interval=setInterval(this.tick.bind(this),16)},r.prototype.pause=function(){clearInterval(this.interval),this.interval=null},r.prototype.clear=function(e){this.context.fillStyle="rgba(255,255,255,1)",this.context.globalCompositeOperation="destination-out",this.context.fillRect(0,0,this.canvas.width,this.canvas.height)},r.prototype.step=function(e){this.clear(),this.timeStep=e,this.tick()},r.prototype.parseColor=function(e){return typeof e=="number"?{r:Math.floor(e/256/256)%256,g:Math.floor(e/256)%256,b:e%256}:(e.substr(0,1)==="#"&&(e=e.substr(1)),{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16)})},r.prototype.getCanvas=function(){return this.canvas},r.prototype.getY=function(e,t){return this.options.ballHeight/2*(1+Math.sin(this.timeStep*(e/500+.02)%2*Math.PI))},r.prototype.tick=function(){this.context.fillStyle=this.clearFillStyle,this.context.globalCompositeOperation="destination-out",this.context.fillRect(0,0,this.canvas.width,this.canvas.height),this.context.globalCompositeOperation="source-over";for(var e=0;e<this.options.numBalls;e++){var t=this.getY(e,this.timeStep),n=Math.abs(t-this.options.ballHeight/2)/(this.options.ballHeight/2);this.context.fillStyle="rgb("+Math.floor(this.fromColor.r+this.diffR*n)+","+Math.floor(this.fromColor.g+this.diffG*n)+","+Math.floor(this.fromColor.b+this.diffB*n)+")",this.context.beginPath(),this.context.arc((this.options.ballRadius*2+1)*e+this.options.ballRadius*2,this.options.ballRadius*2+t,this.options.ballRadius,0,Math.PI*2,!1),this.context.fill()}this.timeStep++},t.exports=function(e){var t={numBalls:40,ballHeight:40,ballRadius:2,color0:"#000000",color1:"#000000",fadeout:.2};for(var n in e)t[n]=e[n];var i=new r(t);return{canvas:i.getCanvas(),play:i.play.bind(i),pause:i.pause.bind(i),step:i.step.bind(i)}}},{}]},{},[1])(1)});