Trinary
New Coder
Hi. I am working on a script that will help me visualize a grid within a grid.
What i would like help with is the structure to build up an square that has n amount of boxes inside it depending on what the existing code produces bases on user input. The boxes are generated from right to left and downward. On line 60 the variable w, h would represent how many boxes should be horizontal and vertical. I am not asking for a complete code snippet but for a good introduction on how to implement visual effects like described here.
[CODE lang="html" highlight="60"]<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
text-align: right;
}
.outercontainer {
width: 50%;
text-align: center;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
</style>
</head>
<body>
<div class="outercontainer">
<div class="container">
<p>Total number of cominations <input type="number" name="mynumber" value="9" id="tSquare" onclick="calculateGrid()"></p>
<p>Horizontal number of combinations <input type="number" name="mynumber" value="3" id="hSquare" onclick="calculateGrid()"></p>
<p>Total number of sub cominations <input type="number" name="mynumber" value="4" id="tSubSquare" onclick="calculateGrid()"></p>
<p>Horizontal number of sub combinations <input type="number" name="mynumber" value="2" id="hSubSquare" onclick="calculateGrid()"></p>
<p>Number of different colors <input type="number" name="mynumber" value="4" id="tColors" onclick="calculateGrid()"></p>
<p id="changeMe">Text is what</p>
</div>
</div>
<script>
function calculateGrid() {
var output2 = document.getElementById("changeMe");
const w = Number(hSquare.value);
const h = Math.ceil(Number(tSquare.value/hSquare.value));
const sw = Number(hSubSquare.value);
const sh = Math.ceil(Number(tSubSquare.value/hSubSquare.value));
const tw = w*sw;
const th = h*sh;
const ts = Number(tSquare.value);
const tss = Number(tSubSquare.value);
const tc = Number(tColors.value);
let colorfullText = "<br>"+tc**tc;
if (tc**tc < ts) colorfullText += " colors will fit with space to spare.";
else if (tc**tc == ts) colorfullText += " colors will fit perfect!";
else colorfullText += " colors will not fit!";
output2.innerHTML = "x: "+w+", y: "+h+"<br>Cell x: "+tw+", Cell y: "+th+colorfullText;
}
// var slider1 = document.getElementById("totalSquare");
// var output1 = document.getElementById("totalSquareResult");
// output1.innerHTML = slider1.value;
// slider1.oninput = function() {
// gvalue = "2";
// alert('was here');
// gvalue = "new val";
// }
<!-- <input type="range" min="1" max="100" value="50" class="slider" id="totalSquare" onclick="calculateGrid()">
<p>Value: <span id="totalSquareResult" val="0"></span></p>
output1.innerHTML = "World!"; -->
</script>
</body>
</html>[/CODE]
What i would like help with is the structure to build up an square that has n amount of boxes inside it depending on what the existing code produces bases on user input. The boxes are generated from right to left and downward. On line 60 the variable w, h would represent how many boxes should be horizontal and vertical. I am not asking for a complete code snippet but for a good introduction on how to implement visual effects like described here.
[CODE lang="html" highlight="60"]<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
text-align: right;
}
.outercontainer {
width: 50%;
text-align: center;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
</style>
</head>
<body>
<div class="outercontainer">
<div class="container">
<p>Total number of cominations <input type="number" name="mynumber" value="9" id="tSquare" onclick="calculateGrid()"></p>
<p>Horizontal number of combinations <input type="number" name="mynumber" value="3" id="hSquare" onclick="calculateGrid()"></p>
<p>Total number of sub cominations <input type="number" name="mynumber" value="4" id="tSubSquare" onclick="calculateGrid()"></p>
<p>Horizontal number of sub combinations <input type="number" name="mynumber" value="2" id="hSubSquare" onclick="calculateGrid()"></p>
<p>Number of different colors <input type="number" name="mynumber" value="4" id="tColors" onclick="calculateGrid()"></p>
<p id="changeMe">Text is what</p>
</div>
</div>
<script>
function calculateGrid() {
var output2 = document.getElementById("changeMe");
const w = Number(hSquare.value);
const h = Math.ceil(Number(tSquare.value/hSquare.value));
const sw = Number(hSubSquare.value);
const sh = Math.ceil(Number(tSubSquare.value/hSubSquare.value));
const tw = w*sw;
const th = h*sh;
const ts = Number(tSquare.value);
const tss = Number(tSubSquare.value);
const tc = Number(tColors.value);
let colorfullText = "<br>"+tc**tc;
if (tc**tc < ts) colorfullText += " colors will fit with space to spare.";
else if (tc**tc == ts) colorfullText += " colors will fit perfect!";
else colorfullText += " colors will not fit!";
output2.innerHTML = "x: "+w+", y: "+h+"<br>Cell x: "+tw+", Cell y: "+th+colorfullText;
}
// var slider1 = document.getElementById("totalSquare");
// var output1 = document.getElementById("totalSquareResult");
// output1.innerHTML = slider1.value;
// slider1.oninput = function() {
// gvalue = "2";
// alert('was here');
// gvalue = "new val";
// }
<!-- <input type="range" min="1" max="100" value="50" class="slider" id="totalSquare" onclick="calculateGrid()">
<p>Value: <span id="totalSquareResult" val="0"></span></p>
output1.innerHTML = "World!"; -->
</script>
</body>
</html>[/CODE]
