Created
December 25, 2015 07:23
-
-
Save anonymous/514ad620cc0c9aebfa8d 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
(function () { | |
var refreshRate = 100; | |
var particleLimit = 5; | |
var snake = { | |
x: (window.innerWidth * Math.random()) - window.pageXOffset, | |
y: (window.innerHeight * Math.random()) - window.pageYOffset, | |
dx: Math.ceil(Math.random() * 50) - 25, | |
dy: Math.ceil(Math.random() * 50) - 25, | |
atan2: Math.atan2(this.dx, this.dy), | |
body: [], | |
update: function () { | |
// IIC.setAngle(Math.ceil(Math.random() * 360) * Math.PI / 180); | |
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); | |
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) { | |
IIC.setAngle(this.body[i].atan2); | |
mouseClick({ | |
clientX: this.body[i].x - window.pageXOffset, | |
clientY: this.body[i].y - window.pageYOffset, | |
button: 0 | |
}); | |
} | |
} | |
} | |
setInterval(function () { | |
snake.update(); | |
}, refreshRate); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment