A Pen by Something Formed on CodePen.
Last active
April 30, 2017 04:41
-
-
Save shuuki/ed8e56093dedaba2a37b90508675184b to your computer and use it in GitHub Desktop.
jmmPvr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// globals | |
var up = 0, | |
time = 0, | |
running = false; | |
// elements | |
var body = document.getElementsByTagName('body')[0]; | |
var button = document.createElement('button'); | |
button.innerHTML = 'Begin'; | |
body.appendChild(button); | |
button.addEventListener ('click', init); | |
var div = document.createElement('div'); | |
body.appendChild(div); | |
var pre = document.createElement('pre'); | |
body.appendChild(pre); | |
// steps | |
function init() { | |
time = Date.now(); | |
if (!running) { | |
window.requestAnimationFrame(update); | |
running = true; | |
button.innerHTML = 'Pause'; | |
} else { | |
window.cancelAnimationFrame(update); | |
running = false; | |
button.innerHTML = 'Resume'; | |
} | |
} | |
function update() { | |
tick(); | |
render(); | |
if (running) window.requestAnimationFrame(update); | |
} | |
function tick () { | |
var del = 0, | |
past = time; | |
time = Date.now(); | |
del = time - past; | |
up = up + del; | |
} | |
function render() { | |
var seconds = Math.floor(up / 1000), | |
cosy = Math.cos(up/1400).toFixed(2); | |
div.innerHTML = p(running) + ' ' + p(seconds) + p(cosy); | |
} | |
function p(content) { return '<p>' + content + '</p>' } | |
//function roll() {} | |
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: black; | |
color: white; | |
text-align: center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://codepen.io/somethingformed/pen/wJKaKd" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment