Tygodniowe wyzwanie programistyczne #7 - Creative coding challenge
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
<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