Created
December 23, 2017 15:22
-
-
Save EliTheCoder/7cd45ec07318f10a1a87d4cd63f0d086 to your computer and use it in GitHub Desktop.
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
var refreshRate = 100; var particleLimit = 15; | |
var snake = { | |
x: (window.innerWidth * Math.random()) - window.pageXOffset, | |
y: (window.innerHeight * Math.random()) - window.pageYOffset, | |
dx: Math.ceil(Math.random() * 30) - 15, | |
dy: Math.ceil(Math.random() * 30) - 15, | |
atan2: Math.atan2(this.dx, this.dy) + (Math.PI / 2), body: [], | |
update: function () { | |
if (this.x < 0) { this.x = 0; this.dx = -this.dx;} | |
else if (this.x > window.innerWidth) { this.x = window.innerWidth; this.dx = -this.dx; } | |
if (this.y < 0) { this.y = 0; this.dy = -this.dy; } | |
else if (this.y > window.innerHeight) { this.y = window.innerHeight; this.dy = -this.dy; } | |
var ddx = (this.dx + ((Math.random() * 10) - 5)); | |
var ddy = (this.dy + ((Math.random() * 10) - 5)); | |
this.x = this.x + ddx; | |
this.y = this.y + ddy; | |
this.atan2 = Math.atan2(ddy, ddx) + (Math.PI / 2); | |
this.body.unshift({ x: this.x, y: this.y, atan2: this.atan2 }); | |
if (this.body.length > particleLimit) { this.body.pop(); } | |
for (var i = this.body.length - 1; i >= 0; --i) { | |
mouseClick({ clientX: this.body[i].x - window.pageXOffset, clientY: this.body[i].y - window.pageYOffset, button: 0 }); | |
IIC.setPosition(this.body[i].x - window.pageXOffset, this.body[i].y - window.pageYOffset); | |
IIC.makeGhost(this.body[i].x - window.pageXOffset, this.body[i].y - window.pageYOffset, IIC.getId); | |
} } | |
}; | |
setInterval(function () { snake.update(); }, refreshRate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment