/*
* This fuction displays the dots on the page.
*
* @param pointsArray - Array containing the [top,left] dot positions
* @param colorsArray - Array of Colors
* @param maxDots - max number of Array elements
*/
function displayDots(pointsArray, colorsArray, maxDots) {
var container = document.getElementById('container');
container.innerHTML = "";
for (var i = 0; i < maxDots; i++) {
// get current element from the Array
var element = pointsArray[i]; // this is a two-dimensional Array [top,left]
var top = element[0]; // first element in two-dim Array
var left = element[1]; // second element
// get color
var color = colorsArray[i];
// create new div element
var dot = document.createElement('div');
// assign attribute prop to new div element
dot.id = "dot_" + i;
dot.style.top = top + "px";
dot.style.left = left + "px";
dot.className = "dot";
dot.style.backgroundColor = color;
// create new textNode
var txtNode = document.createTextNode(i + 1);
// add textNode to div
dot.appendChild(txtNode);
// add new div element to the container element
container.appendChild(dot);
}
}
/*
* This fuction populates the pointsArray top/left positions
* for the number of dots passed in the maxDots param.
*
* @param maxDots - max number of Array elements
* @return dotsArray - Array containing maxDots number of [top, left] positions in two-dimensional Arrays
*/
function getDots(maxDots) {
var dotsArray = [];
var TOP_MAX = 250;
var LEFT_MAX = 1000;
for (var i = 0; i < maxDots; i++) {
// http://www.w3schools.com/jsref/jsref_random.asp
// http://www.w3schools.com/jsref/jsref_floor.asp
var top = Math.floor((Math.random() * TOP_MAX));
var left = Math.floor((Math.random() * LEFT_MAX));
//...
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.