Skip to content

Instantly share code, notes, and snippets.

@PlasmaPower
Last active May 27, 2017 20:22
Show Gist options
  • Select an option

  • Save PlasmaPower/013445fa9d8bf25ffb68dafb61078bde to your computer and use it in GitHub Desktop.

Select an option

Save PlasmaPower/013445fa9d8bf25ffb68dafb61078bde to your computer and use it in GitHub Desktop.
diff --git a/server/static/js/chaos.js b/server/static/js/chaos.js
index f1664f5..e9dc6aa 100644
--- a/server/static/js/chaos.js
+++ b/server/static/js/chaos.js
@@ -31,13 +31,18 @@ canvas.onmousemove = function(e) {
lastY = e.offsetY;
}
-setInterval(function() {
+var previousTime = Date.now();
+
+function loop() {
+ var newTime = Date.now();
+ var delta = previousTime - newTime;
+ previousTime = newTime;
ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#f3482d";
for (x = 0; x < pix_location.length; x++) {
- var xPos = pix_location[x][0] + 0.1*(char_location[x][0]-pix_location[x][0]);
- var yPos = pix_location[x][1] + 0.1*(char_location[x][1]-pix_location[x][1]);
+ var xPos = pix_location[x][0] + delta*3*(char_location[x][0]-pix_location[x][0]);
+ var yPos = pix_location[x][1] + delta*3*(char_location[x][1]-pix_location[x][1]);
if (lastX > 0 && lastY > 0) {
dx = pix_location[x][0]-lastX;
dy = pix_location[x][1]-lastY;
@@ -50,7 +55,10 @@ setInterval(function() {
}
lastX = -1;
lastY = -1;
-}, 100);
+ window.requestAnimationFrame(loop);
+}
+
+loop();
var k = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65],
n = 0;
@@ -107,4 +115,4 @@ function unfade(element) {
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
op += op * 0.1;
}, 10);
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment