JSFiddle - React, Tailwind, and code Playground
HTML
<div id="page">
<div id="header">
<div id="sketch">Click a Sketch
<div id="small_box"></div>
</div>
</div>
<div id="left"></div>
<div id="area"></div>
<div id="right"></div>
</div>
CSS
*{border: 0;
margin:0;
padding: 0;
}
body
{
margin:0;border:0;padding:0;
font-family:"Times New Roman";
font-size: 12pt;
}
#header
{
width: 36em;
height: 3em;
border: 1px solid black;
margin-left: auto;
margin-right: auto;
text-align: center;
}
#left
{
height: 21em;
width: 7em;
border: 1px solid black;
margin-left: auto;
margin-right: auto;
position: relative;
left: -223px;
}
#area
{
height: 21em;
width: 21em;
border: 1px solid black;
margin-left: auto;
margin-right: auto;
position: relative;
top: -338px;
left: 2px;
}
#right
{
height: 21em;
width: 7em;
border: 1px solid black;
margin-left: auto;
margin-right: auto;
position: relative;
top: -677px;
left: 228px;
}
#sketch
{
margin: 0px;
font-size: 3em;
}
#small_box
{
height: 2em;
width: 2em;
border: 1px solid black;
position: relative;
top: -57px;
left: 458px;
font-size: 12pt;
background-color: red;
margin-top: 10px;
}
.box{border: 1px solid; display: inline-block; width: 10px; height: 10px;}
JavaScript
var array;
var count;
var html;
var i;
i = 0;
count = 0;
array = new Array(4);
array[0] = getRandomRGB();
array[1] = getRandomRGB();
array[2] = getRandomRGB();
array[3] = getRandomRGB();
document.getElementById("small_box").style.backgroundColor = getRandomRGB();
createColorChoice(array, "left", "palette", updateCurrentColor);
createColorChoice(array, "right", "canvas", updateCanvasColor);
html = createDrawingArea("grid", 20, 30, "box", "startofRow");
document.getElementById("area").innerHTML = html;
count = countElementsWithIdPrefixOf("grid");
for (i = 0; i < count; i++)
{
document.getElementById("grid" + i).style.backgroundColor = "red";
}
}
function colorTheBox(prefix, color)
{
this.style.backgroundColor = document.getElementById("small_box").style.backgroundColor;
}
function createDrawingArea(prefix, rows, columns, classId, start)
{
var classInfo;
var count;
var html;
var i;
var j;
html = "";
count = 0;
i = 0;
j = 0;
for (i = 0; i < rows; i = i + 1)
{
classInfo = classId + " " + start;
j = 0;
for (j = 0; j < columns; j = j + 1)
{
html = html + createHTMLElement("div", prefix + count, classInfo, "");
count = count + 1;
j = j + 1;
}
i = i + 1;
}
return html;
}
function setColorChoice()
{
var prompt;
prompt = window.prompt("Enter a color: ")
if (prompt.length > 0)
{
this.style.backgroundColor = prompt;
}
}
function updateCanvasColor() {
document.getElementById("area").style.backgroundColor = this.style.backgroundColor;
}
function updateCurrentColor()
{
document.getElementById("small_box").style.backgroundColor = this.style.backgroundColor;
}
function createColorChoice(array, containerId, palettePrefix, reference)
{
var containerHeight;
var containerWidth;
var i;
var newHtml;
i = 0;
...