TileVisualizer / interactive_3x3_tile_tool_js_test.html
MarkTheArtist's picture
Upload interactive_3x3_tile_tool_js_test.html
4be9eeb verified
Raw History Blame Contribute Delete
8.26 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Interactive 3x3 Tile Tool</title>
<style>
body {
margin: 0;
padding: 22px;
background: #eee4cf;
font-family: Arial, Helvetica, sans-serif;
color: #222;
}
h1 { margin: 0 0 8px 0; }
.notice {
padding: 12px;
margin: 12px 0 18px 0;
border-radius: 10px;
border: 3px solid #9b2f2f;
background: #ffe7e7;
font-weight: bold;
}
.notice.ok {
border-color: #276c35;
background: #e5f6e8;
}
.layout {
display: flex;
flex-wrap: wrap;
gap: 22px;
align-items: flex-start;
}
.panel {
background: white;
border: 3px solid #aa9568;
border-radius: 14px;
padding: 18px;
box-shadow: 0 8px 18px rgba(0,0,0,.08);
}
#grid {
display: grid;
grid-template-columns: repeat(3, 150px);
grid-template-rows: repeat(3, 150px);
gap: 12px;
background: #b69d6a;
border: 6px solid #302614;
padding: 12px;
max-width: 100%;
overflow: auto;
}
.cell {
position: relative;
width: 150px;
height: 150px;
background: #fff8e8;
border: 4px solid #453720;
box-sizing: border-box;
cursor: pointer;
}
.cell.selected {
outline: 8px solid #ffcc33;
outline-offset: -10px;
}
.num {
position: absolute;
top: 6px;
left: 8px;
font-weight: bold;
color: #7e6c49;
z-index: 5;
}
.tile {
position: absolute;
left: 18px;
top: 18px;
width: 114px;
height: 114px;
transform-origin: 57px 57px;
}
.square-outline {
position: absolute;
left: 0;
top: 0;
width: 102px;
height: 102px;
border: 6px solid black;
}
.bar {
position: absolute;
left: 6px;
top: 50px;
width: 102px;
height: 14px;
background: black;
}
.elbow-v {
position: absolute;
left: 50px;
top: 0;
width: 14px;
height: 57px;
background: black;
}
.elbow-h {
position: absolute;
left: 57px;
top: 50px;
width: 57px;
height: 14px;
background: black;
}
.controls {
width: 330px;
max-width: 100%;
}
.group {
border-bottom: 1px solid #dccba5;
padding-bottom: 16px;
margin-bottom: 18px;
}
.group:last-child { border-bottom: none; }
button {
margin: 5px;
padding: 11px 13px;
border: 2px solid #6f5b35;
border-radius: 8px;
background: #fff8e8;
font-weight: bold;
cursor: pointer;
font-size: 15px;
}
button:hover { background: #ead6aa; }
button.active { background: #ffcc33; }
#status {
background: #fff8e8;
border: 2px solid #d2bd8d;
border-radius: 8px;
padding: 10px;
line-height: 1.45;
}
textarea {
width: 100%;
height: 135px;
font-family: monospace;
font-size: 12px;
box-sizing: border-box;
}
@media (max-width: 650px) {
#grid {
grid-template-columns: repeat(3, 90px);
grid-template-rows: repeat(3, 90px);
gap: 8px;
padding: 8px;
}
.cell {
width: 90px;
height: 90px;
}
.tile {
left: 10px;
top: 10px;
width: 70px;
height: 70px;
transform-origin: 35px 35px;
}
.square-outline {
width: 62px;
height: 62px;
border-width: 4px;
}
.bar {
left: 4px;
top: 33px;
width: 62px;
height: 7px;
}
.elbow-v {
left: 33px;
top: 0;
width: 7px;
height: 35px;
}
.elbow-h {
left: 35px;
top: 33px;
width: 35px;
height: 7px;
}
}
</style>
</head>
<body>
<h1>Interactive 3×3 Tile Tool</h1>
<div id="jsCheck" class="notice">
JavaScript is NOT running yet. If this message stays here, the file is being opened in a preview mode that blocks interaction.
</div>
<div class="layout">
<div class="panel">
<div id="grid"></div>
</div>
<div class="panel controls">
<div class="group">
<h2>Selected tile</h2>
<div id="status">Waiting for JavaScript...</div>
</div>
<div class="group">
<h2>Design</h2>
<button id="designA" type="button">Design A</button>
<button id="designB" type="button">Design B</button>
</div>
<div class="group">
<h2>Orientation</h2>
<button class="rot" data-rot="0" type="button">0°</button>
<button class="rot" data-rot="90" type="button">90°</button>
<button class="rot" data-rot="180" type="button">180°</button>
<button class="rot" data-rot="270" type="button">270°</button>
<br>
<button id="turn" type="button">Rotate selected 90°</button>
</div>
<div class="group">
<h2>Layout data</h2>
<textarea id="dataBox"></textarea>
<button id="selectData" type="button">Select data</button>
<button id="reset" type="button">Reset</button>
</div>
</div>
</div>
<script>
(function () {
var selected = 0;
var cells = [
{design:"A", rot:0}, {design:"B", rot:90}, {design:"A", rot:90},
{design:"B", rot:0}, {design:"A", rot:0}, {design:"B", rot:180},
{design:"A", rot:90}, {design:"B", rot:270}, {design:"A", rot:0}
];
var jsCheck = document.getElementById("jsCheck");
jsCheck.className = "notice ok";
jsCheck.textContent = "JavaScript is working. You can click cells and change the design or rotation.";
function makeTile(cell) {
var design = '<div class="square-outline"></div>';
if (cell.design === "A") {
design += '<div class="bar"></div>';
} else {
design += '<div class="elbow-v"></div><div class="elbow-h"></div>';
}
return '<div class="tile" style="transform: rotate(' + cell.rot + 'deg)">' + design + '</div>';
}
function render() {
var grid = document.getElementById("grid");
grid.innerHTML = "";
for (var i = 0; i < 9; i++) {
var div = document.createElement("div");
div.className = "cell" + (i === selected ? " selected" : "");
div.setAttribute("data-index", i);
div.innerHTML = '<div class="num">' + (i + 1) + '</div>' + makeTile(cells[i]);
div.addEventListener("click", function () {
selected = Number(this.getAttribute("data-index"));
render();
});
grid.appendChild(div);
}
var current = cells[selected];
document.getElementById("status").innerHTML =
"Cell " + (selected + 1) + "<br>Design " + current.design + "<br>Rotation " + current.rot + "°";
document.getElementById("designA").className = current.design === "A" ? "active" : "";
document.getElementById("designB").className = current.design === "B" ? "active" : "";
var rotButtons = document.querySelectorAll(".rot");
for (var r = 0; r < rotButtons.length; r++) {
var val = Number(rotButtons[r].getAttribute("data-rot"));
rotButtons[r].className = "rot" + (val === current.rot ? " active" : "");
}
document.getElementById("dataBox").value = JSON.stringify(cells, null, 2);
}
document.getElementById("designA").addEventListener("click", function () {
cells[selected].design = "A";
render();
});
document.getElementById("designB").addEventListener("click", function () {
cells[selected].design = "B";
render();
});
var rotButtons = document.querySelectorAll(".rot");
for (var r = 0; r < rotButtons.length; r++) {
rotButtons[r].addEventListener("click", function () {
cells[selected].rot = Number(this.getAttribute("data-rot"));
render();
});
}
document.getElementById("turn").addEventListener("click", function () {
cells[selected].rot = (cells[selected].rot + 90) % 360;
render();
});
document.getElementById("selectData").addEventListener("click", function () {
var box = document.getElementById("dataBox");
box.focus();
box.select();
});
document.getElementById("reset").addEventListener("click", function () {
cells = [
{design:"A", rot:0}, {design:"B", rot:90}, {design:"A", rot:90},
{design:"B", rot:0}, {design:"A", rot:0}, {design:"B", rot:180},
{design:"A", rot:90}, {design:"B", rot:270}, {design:"A", rot:0}
];
selected = 0;
render();
});
render();
})();
</script>
</body>
</html>