[ Launch: bugs ] 6334228 by georules
-
-
Save georules/6334228 to your computer and use it in GitHub Desktop.
bugs
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
{"description":"bugs","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/5Lev3BY.png"} |
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 | |
bb = document.createElement('div'), | |
bugBoxes = []; | |
bb.style.background="#ffffff"; | |
bb.style.width="300px"; | |
bb.style.height="300px"; | |
$('body').append(bb); | |
function getRandomColor() { | |
return '#'+Math.floor(Math.random()*16777215).toString(16); | |
} | |
function getRandomInt (min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function handleBBClick(event) { | |
var newBox = document.createElement('div'); | |
bb.appendChild(newBox); | |
newBox.style.position = "absolute"; | |
newBox.style.left = event.clientX + "px"; | |
newBox.style.top = event.clientY +"px"; | |
newBox.style.background = getRandomColor(); | |
newBox.style.width = "12px"; | |
newBox.style.height = "12px"; | |
newBox.style.border="1px solid black"; | |
newBox.style.borderRadius = "2px"; | |
bugBoxes.push(newBox); | |
if(bugBoxes.length > 200) | |
bugBoxes.shift().remove(); | |
} | |
function swarm() { | |
for (var i = 0; i < bugBoxes.length; i++) { | |
var bug = bugBoxes[i]; | |
var xChange = getRandomInt(-20,20); | |
var yChange = getRandomInt(-20,20); | |
bug.style.left = parseInt(bug.style.left,10) + xChange + "px"; | |
bug.style.top = parseInt(bug.style.top,10) + yChange +"px"; | |
} | |
console.log('hi'); | |
} | |
$(document).ready(function() { | |
window.setInterval(swarm,100); | |
$('body').click(handleBBClick); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment