Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Draw colored squares. - Javascript Code Bank


Draw colored squares.
Draw colored squares.
                <!-- Made by TheMasterSinner -->

<html>
	<head>
		<script type="text/javascript">
			var hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
			var i;
			
			function drawsquare(e) {
				var square = document.createElement("div");
				square.className = "square";
				square.style.backgroundColor = rndcolor();
				square.style.left = e.clientX + "px";
				square.style.top = e.clientY + "px";
				document.body.appendChild(square);
			}
			
			function rndcolor() {
				var color = "#";
					for (i=0; i<6; i++) {
						color += hex[Math.floor(Math.random() * 16)];
					}
				return color;
			}
		</script>
		<style>
			body {
				overflow: hidden;
			}
			
			.square {
				position: absolute;
				width: 25px;
				height: 25px;
			}
		</style>
	</head>
	<body onmousemove="drawsquare(event);">
	
	</body>
</html>
            
Comments
ghost's avatar
ghost 15 years ago

colors:D

ghost's avatar
ghost 13 years ago

thats wiked! i hope u dont mind me putting that on my site,( il let them now its ur idea) nice coding, ive been doing jscript for a while but never came up with anything like dat :D also if you did more code with more vars i think u could make like a virtual paint! really nice script :):ninja:

buddywithgol's avatar
buddywithgol 12 years ago

that is soo cool dude, how did you come up with that idea?