Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jderda
Created October 20, 2016 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jderda/ced39f6923598733ab5a27889e947588 to your computer and use it in GitHub Desktop.
Save jderda/ced39f6923598733ab5a27889e947588 to your computer and use it in GitHub Desktop.
Tygodniowe wyzwanie programistyczne #7 - Creative coding challenge
<html>
<head>
<style>
#textedit {
width: 100%;
height: 100%;
background: transparent;
margin: 0px;
padding: 0px;
border: 0px none;
font-size: 2em;
}
</style>
</head>
<body>
<textarea id="textedit" onkeydown="keyPressed()"></textarea>
<script>
var lastTimeKeyPressed = 0;
var speed = 1000;
function keyPressed() {
lastTimeKeyPressed = (new Date).getTime();
}
function updateColor() {
var diff = (new Date).getTime()-lastTimeKeyPressed;
var r = 255-Math.floor((255-135)*Math.min(1, diff/speed));
var g = 105+Math.floor((206-105)*Math.min(1, diff/speed));
var b = 97+Math.floor((250-97)*Math.min(1, diff/speed));
var rgb = '#'+r.toString(16)+g.toString(16)+b.toString(16);
document.body.style.background = rgb;
}
setInterval(function(){ updateColor(); }, 50);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment