I'm having a little trouble with randomly positioning a bunch of random boxes throughout a page.
The goal is to have a randomly amount of boxes show up in random positions and the boxes are to be random colors on a page. The boxes should also be overlapping, making them truly in random positions.
Thus far all I have is one randomly colored box on the page, clearly not randomly positioned. I'm suck of where to go from here with the positioning and creating a bunch of random boxes...
Please note JQuery cannot be used.
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Ramdom Boxes</title>
<script src="A2Q1.js"></script>
</head>
<body>
</body>
</html>
Javascript:
window.onload = init;
function init() {
//when page is loaded create a bunch of boxes randomly throughout the page
//get the body element of the document
var body = document.getElementsByTagName("body")[0];
//create the canvas tag
var canvas = document.createElement("canvas");
canvas.height = 100;
canvas.width = 100;
var context = canvas.getContext("2d");
//create the box and append onto the canvas
var colour = '#'+ Math.round(0xffffff * Math.random()).toString(16);
context.fillStyle = colour;
context.fillRect(25,25,50,50);
//append the canvas onto the body
body.appendChild(canvas);
}