function getRandomNumber(minNumber, maxNumber){
randomNumber = Math.round(Math.random() * maxNumber) + minNumber;
//console.log(randomNumber);
return randomNumber;
};
/**************************************************/
// Get the distance between 2 elements
function getDistanceBetweenElements(elementOne, elementTwo){
var positionElementOneX = $(elementOne).offset().top;
var positionElementOneY = $(elementOne).offset().left;
var positionElementTwoX = $(elementTwo).offset().top;
var positionElementTwoY = $(elementTwo).offset().left;
var distanceX = Math.abs(positionElementOneX - positionElementTwoX);
var distanceY = Math.abs(positionElementOneY - positionElementTwoY);
var finalDistance = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
return finalDistance;
};
function checkContamination(){
$(".person").each(function(){
// Only check if the selected element is sick
if($(this).hasClass("sick"))
{
var elementOne = $(this);
$(".person").each(function(){
var elementTwo = $(this);
//console.log(elementTwo);
// Check if the distance between those 2 elements is less than 50px. If so, make them sick
var finalDistance = getDistanceBetweenElements(elementOne, elementTwo);
if(finalDistance < 20){
// console.log("CONTAMINATED");
$(elementOne).removeClass("healthy").addClass("sick");
$(elementTwo).removeClass("healthy").addClass("sick");
}
});
}
});
};
setInterval("checkContamination()", 5000);
/**************************************************/
function createPeople(){
for(var i = 0; i < 100; i++){
var topPosition =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.