You've already forked computing-box
Addition of increment/decrement buttons, addition of Auto Random button
Signed-off-by: Alexander Lyall <alex@adcm.uk>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "computing-box",
|
"name": "Computing:Box",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.0.1",
|
"version": "2.0.0 Alpha",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "astro dev",
|
"dev": "astro dev",
|
||||||
"build": "astro build",
|
"build": "astro build",
|
||||||
|
|||||||
@@ -1,263 +0,0 @@
|
|||||||
const bitsRows = document.getElementById("bitsRows");
|
|
||||||
const denaryEl = document.getElementById("denaryNumber");
|
|
||||||
const binaryEl = document.getElementById("binaryNumber");
|
|
||||||
|
|
||||||
const modeToggle = document.getElementById("modeToggle");
|
|
||||||
const modeHint = document.getElementById("modeHint");
|
|
||||||
|
|
||||||
const bitsInput = document.getElementById("bitsInput");
|
|
||||||
const btnBitsUp = document.getElementById("btnBitsUp");
|
|
||||||
const btnBitsDown = document.getElementById("btnBitsDown");
|
|
||||||
|
|
||||||
const btnShiftLeft = document.getElementById("btnShiftLeft");
|
|
||||||
const btnShiftRight = document.getElementById("btnShiftRight");
|
|
||||||
const btnCustomBinary = document.getElementById("btnCustomBinary");
|
|
||||||
const btnCustomDenary = document.getElementById("btnCustomDenary");
|
|
||||||
|
|
||||||
let bitCount = clampInt(Number(bitsInput.value || 8), 1, 64);
|
|
||||||
let bits = new Array(bitCount).fill(false); // index 0 = MSB
|
|
||||||
|
|
||||||
function clampInt(n, min, max){
|
|
||||||
n = Number(n);
|
|
||||||
if (!Number.isFinite(n)) n = min;
|
|
||||||
n = Math.floor(n);
|
|
||||||
return Math.max(min, Math.min(max, n));
|
|
||||||
}
|
|
||||||
|
|
||||||
function isTwos(){
|
|
||||||
return !!modeToggle.checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
function msbValue(){
|
|
||||||
return 2 ** (bitCount - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function unsignedValueAt(i){
|
|
||||||
// i=0 is MSB
|
|
||||||
return 2 ** (bitCount - 1 - i);
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeUnsigned(){
|
|
||||||
let sum = 0;
|
|
||||||
for (let i = 0; i < bitCount; i++){
|
|
||||||
if (bits[i]) sum += unsignedValueAt(i);
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeDenary(){
|
|
||||||
const u = computeUnsigned();
|
|
||||||
if (!isTwos()) return u;
|
|
||||||
|
|
||||||
// Two's complement:
|
|
||||||
// if MSB is 1, value = unsigned - 2^n
|
|
||||||
if (bits[0]) return u - (2 ** bitCount);
|
|
||||||
return u;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bitsToString(){
|
|
||||||
return bits.map(b => (b ? "1" : "0")).join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateModeHint(){
|
|
||||||
if (isTwos()){
|
|
||||||
modeHint.textContent = "Tip: In two's complement, the left-most bit (MSB) represents a negative value.";
|
|
||||||
} else {
|
|
||||||
modeHint.textContent = "Tip: In unsigned binary, all bits represent positive values.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildBitsUI(){
|
|
||||||
bitsRows.innerHTML = "";
|
|
||||||
|
|
||||||
// Build rows of 8 bits
|
|
||||||
const rowCount = Math.ceil(bitCount / 8);
|
|
||||||
|
|
||||||
for (let r = 0; r < rowCount; r++){
|
|
||||||
const row = document.createElement("div");
|
|
||||||
row.className = "byteRow";
|
|
||||||
|
|
||||||
const start = r * 8;
|
|
||||||
const end = Math.min(start + 8, bitCount);
|
|
||||||
|
|
||||||
for (let i = start; i < end; i++){
|
|
||||||
const bitEl = document.createElement("div");
|
|
||||||
bitEl.className = "bit";
|
|
||||||
|
|
||||||
// label: show -MSB in two's complement
|
|
||||||
const labelVal = (isTwos() && i === 0) ? -msbValue() : unsignedValueAt(i);
|
|
||||||
|
|
||||||
bitEl.innerHTML = `
|
|
||||||
<span class="bulb" id="bulb-${i}" aria-hidden="true">💡</span>
|
|
||||||
<div class="bitVal">${labelVal}</div>
|
|
||||||
<label class="switch" aria-label="Toggle bit ${labelVal}">
|
|
||||||
<input type="checkbox" data-index="${i}">
|
|
||||||
<span class="slider"></span>
|
|
||||||
</label>
|
|
||||||
`;
|
|
||||||
|
|
||||||
row.appendChild(bitEl);
|
|
||||||
}
|
|
||||||
|
|
||||||
bitsRows.appendChild(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hook switches
|
|
||||||
bitsRows.querySelectorAll('input[type="checkbox"][data-index]').forEach(input => {
|
|
||||||
input.addEventListener("change", () => {
|
|
||||||
const i = Number(input.dataset.index);
|
|
||||||
bits[i] = input.checked;
|
|
||||||
updateReadout();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
syncUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
function syncUI(){
|
|
||||||
// sync inputs
|
|
||||||
bitsRows.querySelectorAll('input[type="checkbox"][data-index]').forEach(input => {
|
|
||||||
const i = Number(input.dataset.index);
|
|
||||||
input.checked = !!bits[i];
|
|
||||||
});
|
|
||||||
|
|
||||||
// sync bulbs
|
|
||||||
for (let i = 0; i < bitCount; i++){
|
|
||||||
const bulb = document.getElementById(`bulb-${i}`);
|
|
||||||
if (bulb) bulb.classList.toggle("on", !!bits[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateReadout();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateReadout(){
|
|
||||||
denaryEl.textContent = String(computeDenary());
|
|
||||||
binaryEl.textContent = bitsToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setFromBinary(bin){
|
|
||||||
const clean = String(bin).replace(/\s+/g, "");
|
|
||||||
if (!/^[01]+$/.test(clean)) return false;
|
|
||||||
|
|
||||||
const padded = clean.slice(-bitCount).padStart(bitCount, "0");
|
|
||||||
for (let i = 0; i < bitCount; i++){
|
|
||||||
bits[i] = padded[i] === "1";
|
|
||||||
}
|
|
||||||
|
|
||||||
syncUI();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setFromDenary(n){
|
|
||||||
n = Number(n);
|
|
||||||
if (!Number.isInteger(n)) return false;
|
|
||||||
|
|
||||||
if (!isTwos()){
|
|
||||||
// unsigned: 0 .. (2^n - 1)
|
|
||||||
const max = (2 ** bitCount) - 1;
|
|
||||||
if (n < 0 || n > max) return false;
|
|
||||||
|
|
||||||
for (let i = 0; i < bitCount; i++){
|
|
||||||
const v = unsignedValueAt(i);
|
|
||||||
if (n >= v){
|
|
||||||
bits[i] = true;
|
|
||||||
n -= v;
|
|
||||||
} else {
|
|
||||||
bits[i] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
syncUI();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// two's complement: -(2^(n-1)) .. (2^(n-1)-1)
|
|
||||||
const min = -(2 ** (bitCount - 1));
|
|
||||||
const max = (2 ** (bitCount - 1)) - 1;
|
|
||||||
if (n < min || n > max) return false;
|
|
||||||
|
|
||||||
// convert to unsigned representation
|
|
||||||
let u = n;
|
|
||||||
if (u < 0) u = (2 ** bitCount) + u; // wrap
|
|
||||||
|
|
||||||
for (let i = 0; i < bitCount; i++){
|
|
||||||
const v = unsignedValueAt(i);
|
|
||||||
if (u >= v){
|
|
||||||
bits[i] = true;
|
|
||||||
u -= v;
|
|
||||||
} else {
|
|
||||||
bits[i] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
syncUI();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function shiftLeft(){
|
|
||||||
bits.shift(); // drop MSB
|
|
||||||
bits.push(false); // add LSB
|
|
||||||
syncUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
function shiftRight(){
|
|
||||||
bits.pop(); // drop LSB
|
|
||||||
bits.unshift(false); // add MSB
|
|
||||||
syncUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBitCount(newCount){
|
|
||||||
newCount = clampInt(newCount, 4, 64);
|
|
||||||
if (newCount === bitCount) return;
|
|
||||||
|
|
||||||
// preserve right-most bits (LSB side) when resizing
|
|
||||||
const old = bits.slice();
|
|
||||||
const next = new Array(newCount).fill(false);
|
|
||||||
|
|
||||||
const copy = Math.min(old.length, next.length);
|
|
||||||
for (let k = 0; k < copy; k++){
|
|
||||||
// copy from end (LSB)
|
|
||||||
next[newCount - 1 - k] = old[old.length - 1 - k];
|
|
||||||
}
|
|
||||||
|
|
||||||
bitCount = newCount;
|
|
||||||
bits = next;
|
|
||||||
|
|
||||||
bitsInput.value = String(bitCount);
|
|
||||||
buildBitsUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------- events -------------------- */
|
|
||||||
|
|
||||||
modeToggle.addEventListener("change", () => {
|
|
||||||
updateModeHint();
|
|
||||||
buildBitsUI(); // rebuild labels (MSB becomes negative/positive)
|
|
||||||
});
|
|
||||||
|
|
||||||
btnBitsUp.addEventListener("click", () => setBitCount(bitCount + 1));
|
|
||||||
btnBitsDown.addEventListener("click", () => setBitCount(bitCount - 1));
|
|
||||||
|
|
||||||
bitsInput.addEventListener("change", () => setBitCount(Number(bitsInput.value)));
|
|
||||||
|
|
||||||
btnShiftLeft.addEventListener("click", shiftLeft);
|
|
||||||
btnShiftRight.addEventListener("click", shiftRight);
|
|
||||||
|
|
||||||
btnCustomBinary.addEventListener("click", () => {
|
|
||||||
const v = prompt(`Enter ${bitCount}-bit binary:`);
|
|
||||||
if (v === null) return;
|
|
||||||
if (!setFromBinary(v)) alert("Invalid binary. Use only 0 and 1.");
|
|
||||||
});
|
|
||||||
|
|
||||||
btnCustomDenary.addEventListener("click", () => {
|
|
||||||
const min = isTwos() ? -(2 ** (bitCount - 1)) : 0;
|
|
||||||
const max = isTwos() ? (2 ** (bitCount - 1)) - 1 : (2 ** bitCount) - 1;
|
|
||||||
|
|
||||||
const v = prompt(`Enter a denary number (${min} to ${max}):`);
|
|
||||||
if (v === null) return;
|
|
||||||
if (!setFromDenary(Number(v))) alert("Invalid denary for current mode/bit width.");
|
|
||||||
});
|
|
||||||
|
|
||||||
/* -------------------- init -------------------- */
|
|
||||||
|
|
||||||
bitsInput.value = String(bitCount);
|
|
||||||
updateModeHint();
|
|
||||||
buildBitsUI();
|
|
||||||
@@ -1,7 +1,29 @@
|
|||||||
<footer class="siteFooter">
|
<footer class="siteFooter">
|
||||||
<div class="siteFooter__inner">
|
<div class="inner">
|
||||||
<div>Computer Science Concept Simulators</div>
|
<div class="title">Computer Science Concept Simulators</div>
|
||||||
<div>© 2025 Computing:Box · Created with ❤️ by Mr Lyall</div>
|
<div class="meta">
|
||||||
<div>Powered by ADCM Networks</div>
|
© 2025 Computing:Box · Created with 💗 by Mr Lyall<br />
|
||||||
|
Powered by ADCM Networks
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.siteFooter{
|
||||||
|
border-top: 1px solid rgba(255,255,255,.10);
|
||||||
|
background: rgba(0,0,0,.10);
|
||||||
|
}
|
||||||
|
.inner{
|
||||||
|
max-width:1200px;
|
||||||
|
margin:0 auto;
|
||||||
|
padding: 18px 20px;
|
||||||
|
color: rgba(255,255,255,.65);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.title{
|
||||||
|
color: rgba(255,255,255,.80);
|
||||||
|
font-weight: 800;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,13 +1,57 @@
|
|||||||
<header class="siteHeader">
|
<header class="siteHeader">
|
||||||
<div class="siteHeader__inner">
|
<div class="inner">
|
||||||
<a class="brand" href="/">Computing:Box</a>
|
<div class="brand">
|
||||||
|
<a href="/">Computing:Box</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<a class="nav__link" href="/binary">Binary</a>
|
<a href="/binary">Binary</a>
|
||||||
<a class="nav__link" href="/hexadecimal">Hexadecimal</a>
|
<a href="/hexadecimal">Hexadecimal</a>
|
||||||
<a class="nav__link" href="/hex-colours">Hex Colours</a>
|
<a href="/hex-colours">Hex Colours</a>
|
||||||
<a class="nav__link" href="/logic-gates">Logic Gates</a>
|
<a href="/logic-gates">Logic Gates</a>
|
||||||
<a class="nav__link" href="/about">About</a>
|
<a href="/about">About</a>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.siteHeader{
|
||||||
|
height: 64px;
|
||||||
|
display:flex;
|
||||||
|
align-items:center;
|
||||||
|
border-bottom: 1px solid rgba(255,255,255,.10);
|
||||||
|
background: rgba(0,0,0,.10);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
}
|
||||||
|
.inner{
|
||||||
|
max-width: 1200px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0 20px;
|
||||||
|
display:flex;
|
||||||
|
align-items:center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 18px;
|
||||||
|
}
|
||||||
|
.brand a{
|
||||||
|
color:#fff;
|
||||||
|
text-decoration:none;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: .02em;
|
||||||
|
}
|
||||||
|
.nav{
|
||||||
|
display:flex;
|
||||||
|
gap: 16px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.nav a{
|
||||||
|
color: rgba(255,255,255,.78);
|
||||||
|
text-decoration:none;
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 13px;
|
||||||
|
letter-spacing:.02em;
|
||||||
|
}
|
||||||
|
.nav a:hover{
|
||||||
|
color:#fff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,381 +0,0 @@
|
|||||||
---
|
|
||||||
const { mode = "unsigned", defaultBits = 8 } = Astro.props;
|
|
||||||
|
|
||||||
// For unsigned: min 1 bit, max 16 bits (tweak if you want)
|
|
||||||
const minBits = 4;
|
|
||||||
const maxBits = 16;
|
|
||||||
const initialBits = Math.min(Math.max(defaultBits, minBits), maxBits);
|
|
||||||
---
|
|
||||||
|
|
||||||
<section class="binary-sim" data-mode={mode} data-bits={initialBits}>
|
|
||||||
<div class="top">
|
|
||||||
<div class="left-brand">
|
|
||||||
<!-- Replace with your logo/img -->
|
|
||||||
<div class="brand-box" aria-hidden="true">Computing:Box</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="display" aria-live="polite">
|
|
||||||
<div class="label">DENARY</div>
|
|
||||||
<div id="denaryNumber" class="value">0</div>
|
|
||||||
|
|
||||||
<div class="label">BINARY</div>
|
|
||||||
<div id="binaryNumber" class="value mono">00000000</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="actions">
|
|
||||||
<button class="btn" type="button" data-action="custom-binary">Custom Binary</button>
|
|
||||||
<button class="btn" type="button" data-action="custom-denary">Custom Denary</button>
|
|
||||||
<button class="btn" type="button" data-action="shift-left">Left Shift</button>
|
|
||||||
<button class="btn" type="button" data-action="shift-right">Right Shift</button>
|
|
||||||
|
|
||||||
<div class="bits-control">
|
|
||||||
<div class="bits-title">Bits</div>
|
|
||||||
<div class="bits-buttons">
|
|
||||||
<button class="btn small" type="button" data-action="bits-minus" aria-label="Decrease bits">−</button>
|
|
||||||
<span id="bitsCount" class="bits-count">{initialBits}</span>
|
|
||||||
<button class="btn small" type="button" data-action="bits-plus" aria-label="Increase bits">+</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="bitsRow" class="bits-row" aria-label="Binary bit switches"></div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<script is:inline>
|
|
||||||
(() => {
|
|
||||||
const root = document.currentScript.closest(".binary-sim");
|
|
||||||
const bitsRow = root.querySelector("#bitsRow");
|
|
||||||
const binaryEl = root.querySelector("#binaryNumber");
|
|
||||||
const denaryEl = root.querySelector("#denaryNumber");
|
|
||||||
const bitsCountEl = root.querySelector("#bitsCount");
|
|
||||||
|
|
||||||
let bitCount = parseInt(root.dataset.bits || "8", 10);
|
|
||||||
const minBits = 4;
|
|
||||||
const maxBits = 16;
|
|
||||||
|
|
||||||
// state: array of 0/1, MSB at index 0
|
|
||||||
let bits = new Array(bitCount).fill(0);
|
|
||||||
|
|
||||||
function placeValues(n) {
|
|
||||||
// unsigned place values: [2^(n-1), ..., 2^0]
|
|
||||||
return Array.from({ length: n }, (_, i) => 2 ** (n - 1 - i));
|
|
||||||
}
|
|
||||||
|
|
||||||
function bitsToDenary(bitsArr) {
|
|
||||||
const pv = placeValues(bitsArr.length);
|
|
||||||
return bitsArr.reduce((acc, b, i) => acc + (b ? pv[i] : 0), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function render() {
|
|
||||||
const binaryStr = bits.join("");
|
|
||||||
binaryEl.textContent = binaryStr;
|
|
||||||
denaryEl.textContent = String(bitsToDenary(bits));
|
|
||||||
bitsCountEl.textContent = String(bitCount);
|
|
||||||
|
|
||||||
const pv = placeValues(bitCount);
|
|
||||||
|
|
||||||
bitsRow.innerHTML = pv.map((value, i) => {
|
|
||||||
const id = `bit_${bitCount}_${i}`;
|
|
||||||
const checked = bits[i] === 1 ? "checked" : "";
|
|
||||||
return `
|
|
||||||
<div class="bit-col">
|
|
||||||
<div class="bulb ${bits[i] ? "on" : "off"}" aria-hidden="true"></div>
|
|
||||||
<div class="place">${value}</div>
|
|
||||||
|
|
||||||
<label class="switch" for="${id}">
|
|
||||||
<input id="${id}" type="checkbox" ${checked} data-index="${i}">
|
|
||||||
<span class="slider" aria-hidden="true"></span>
|
|
||||||
<span class="sr-only">Toggle bit value ${value}</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}).join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBitsFromBinaryString(str) {
|
|
||||||
// allow shorter input; pad left
|
|
||||||
const clean = (str || "").trim();
|
|
||||||
if (!/^[01]+$/.test(clean) || clean.length > bitCount) return false;
|
|
||||||
const padded = clean.padStart(bitCount, "0");
|
|
||||||
bits = padded.split("").map(c => c === "1" ? 1 : 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBitsFromDenary(num) {
|
|
||||||
if (!Number.isInteger(num)) return false;
|
|
||||||
const max = (2 ** bitCount) - 1;
|
|
||||||
if (num < 0 || num > max) return false;
|
|
||||||
|
|
||||||
const bin = num.toString(2).padStart(bitCount, "0");
|
|
||||||
bits = bin.split("").map(c => c === "1" ? 1 : 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function shiftLeft() {
|
|
||||||
bits = bits.slice(1).concat(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shiftRight() {
|
|
||||||
bits = [0].concat(bits.slice(0, -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function resizeBits(newCount) {
|
|
||||||
const clamped = Math.max(minBits, Math.min(maxBits, newCount));
|
|
||||||
if (clamped === bitCount) return;
|
|
||||||
|
|
||||||
// keep value as best as possible: preserve LSBs when resizing
|
|
||||||
const currentBinary = bits.join("");
|
|
||||||
bitCount = clamped;
|
|
||||||
bits = new Array(bitCount).fill(0);
|
|
||||||
|
|
||||||
const take = currentBinary.slice(-bitCount);
|
|
||||||
setBitsFromBinaryString(take);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Switch input handler
|
|
||||||
bitsRow.addEventListener("change", (e) => {
|
|
||||||
const input = e.target;
|
|
||||||
if (!(input instanceof HTMLInputElement)) return;
|
|
||||||
const idx = parseInt(input.dataset.index || "-1", 10);
|
|
||||||
if (idx < 0) return;
|
|
||||||
bits[idx] = input.checked ? 1 : 0;
|
|
||||||
render();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Button actions
|
|
||||||
root.querySelector(".actions").addEventListener("click", (e) => {
|
|
||||||
const btn = e.target.closest("button[data-action]");
|
|
||||||
if (!btn) return;
|
|
||||||
|
|
||||||
const action = btn.dataset.action;
|
|
||||||
|
|
||||||
if (action === "custom-binary") {
|
|
||||||
const entered = prompt(`Enter a ${bitCount}-bit binary value (0s and 1s):`, bits.join(""));
|
|
||||||
if (entered === null) return;
|
|
||||||
if (!setBitsFromBinaryString(entered)) {
|
|
||||||
alert(`Invalid binary. Use only 0 and 1, up to ${bitCount} digits.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action === "custom-denary") {
|
|
||||||
const max = (2 ** bitCount) - 1;
|
|
||||||
const entered = prompt(`Enter a denary value (0 to ${max}):`, String(bitsToDenary(bits)));
|
|
||||||
if (entered === null) return;
|
|
||||||
const num = Number.parseInt(entered, 10);
|
|
||||||
if (!setBitsFromDenary(num)) {
|
|
||||||
alert(`Invalid denary. Enter a whole number from 0 to ${max}.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action === "shift-left") { shiftLeft(); render(); }
|
|
||||||
if (action === "shift-right") { shiftRight(); render(); }
|
|
||||||
|
|
||||||
if (action === "bits-minus") { resizeBits(bitCount - 1); render(); }
|
|
||||||
if (action === "bits-plus") { resizeBits(bitCount + 1); render(); }
|
|
||||||
});
|
|
||||||
|
|
||||||
// initial
|
|
||||||
render();
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
/* Layout */
|
|
||||||
.binary-sim {
|
|
||||||
padding: 2rem 1rem 3rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 260px 1fr 220px;
|
|
||||||
gap: 1.5rem;
|
|
||||||
align-items: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 980px) {
|
|
||||||
.top {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
.actions {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Brand placeholder */
|
|
||||||
.brand-box {
|
|
||||||
width: 180px;
|
|
||||||
height: 180px;
|
|
||||||
border-radius: 12px;
|
|
||||||
display: grid;
|
|
||||||
place-items: center;
|
|
||||||
font-weight: 700;
|
|
||||||
opacity: 0.9;
|
|
||||||
border: 1px solid rgba(255,255,255,0.08);
|
|
||||||
background: rgba(255,255,255,0.04);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Display */
|
|
||||||
.display {
|
|
||||||
text-align: center;
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.label {
|
|
||||||
letter-spacing: 0.12em;
|
|
||||||
opacity: 0.85;
|
|
||||||
margin-top: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.value {
|
|
||||||
font-size: 3rem;
|
|
||||||
line-height: 1.1;
|
|
||||||
margin: 0.25rem 0 0.75rem;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mono {
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Buttons */
|
|
||||||
.actions {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
border: 0;
|
|
||||||
border-radius: 10px;
|
|
||||||
padding: 0.75rem 1rem;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
background: rgba(255,255,255,0.08);
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn:hover { background: rgba(255,255,255,0.12); }
|
|
||||||
|
|
||||||
.btn.small {
|
|
||||||
padding: 0.45rem 0.75rem;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bits-control {
|
|
||||||
margin-top: 0.25rem;
|
|
||||||
padding-top: 0.5rem;
|
|
||||||
border-top: 1px solid rgba(255,255,255,0.08);
|
|
||||||
}
|
|
||||||
|
|
||||||
.bits-title { opacity: 0.8; margin-bottom: 0.35rem; }
|
|
||||||
|
|
||||||
.bits-buttons {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bits-count {
|
|
||||||
min-width: 2ch;
|
|
||||||
text-align: center;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bits row */
|
|
||||||
.bits-row {
|
|
||||||
margin-top: 2rem;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
|
|
||||||
gap: 1.25rem;
|
|
||||||
align-items: end;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bit-col {
|
|
||||||
text-align: center;
|
|
||||||
padding: 0.5rem 0.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.place {
|
|
||||||
margin: 0.5rem 0 0.5rem;
|
|
||||||
font-size: 2rem;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bulb */
|
|
||||||
.bulb {
|
|
||||||
width: 26px;
|
|
||||||
height: 26px;
|
|
||||||
margin: 0 auto 0.25rem;
|
|
||||||
border-radius: 50%;
|
|
||||||
border: 1px solid rgba(255,255,255,0.15);
|
|
||||||
}
|
|
||||||
.bulb.off { opacity: 0.15; }
|
|
||||||
.bulb.on { opacity: 1; }
|
|
||||||
|
|
||||||
/* Light switch (accessible checkbox) */
|
|
||||||
.switch {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 64px;
|
|
||||||
height: 36px;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.switch input {
|
|
||||||
position: absolute;
|
|
||||||
opacity: 0;
|
|
||||||
width: 1px;
|
|
||||||
height: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider {
|
|
||||||
width: 64px;
|
|
||||||
height: 36px;
|
|
||||||
border-radius: 999px;
|
|
||||||
background: rgba(255,255,255,0.10);
|
|
||||||
border: 1px solid rgba(255,255,255,0.14);
|
|
||||||
position: relative;
|
|
||||||
transition: transform 120ms ease, background 120ms ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider::after {
|
|
||||||
content: "";
|
|
||||||
position: absolute;
|
|
||||||
top: 4px;
|
|
||||||
left: 4px;
|
|
||||||
width: 28px;
|
|
||||||
height: 28px;
|
|
||||||
border-radius: 999px;
|
|
||||||
background: rgba(255,255,255,0.85);
|
|
||||||
transition: transform 120ms ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.switch input:checked + .slider {
|
|
||||||
background: rgba(255,255,255,0.18);
|
|
||||||
}
|
|
||||||
|
|
||||||
.switch input:checked + .slider::after {
|
|
||||||
transform: translateX(28px);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* focus */
|
|
||||||
.switch input:focus-visible + .slider {
|
|
||||||
outline: 3px solid rgba(255,255,255,0.35);
|
|
||||||
outline-offset: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden; clip: rect(0,0,0,0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -11,12 +11,6 @@ const { title = "Computing:Box" } = Astro.props;
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
|
|
||||||
<!-- Global site styling -->
|
|
||||||
<link rel="stylesheet" href="/styles/site.css" />
|
|
||||||
|
|
||||||
<!-- Page specific styles can be added by each page -->
|
|
||||||
<slot name="head" />
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -27,3 +21,15 @@ const { title = "Computing:Box" } = Astro.props;
|
|||||||
<Footer />
|
<Footer />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:global(html, body) {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
:global(body) {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.page {
|
||||||
|
min-height: calc(100vh - 64px - 120px); /* header + footer-ish */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,37 +1,75 @@
|
|||||||
---
|
---
|
||||||
import BaseLayout from "../layouts/BaseLayout.astro";
|
import "../styles/binary.css";
|
||||||
|
|
||||||
|
// keeps JS in src/ and lets Vite/Astro bundle it properly
|
||||||
|
const scriptUrl = Astro.resolve("../scripts/binary.js");
|
||||||
---
|
---
|
||||||
|
|
||||||
<BaseLayout title="Binary | Computing:Box">
|
<!doctype html>
|
||||||
<link rel="stylesheet" href="/styles/binary.css" />
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
<title>Binary | Computing:Box</title>
|
||||||
|
|
||||||
<section class="binaryWrap">
|
<script type="module" src={scriptUrl}></script>
|
||||||
<div class="topGrid">
|
</head>
|
||||||
<!-- LEFT -->
|
|
||||||
|
<body>
|
||||||
|
<!-- Your site header/footer are already present in your layout/screenshots.
|
||||||
|
If this page is wrapped by a global Layout, leave it there.
|
||||||
|
If not, keep your existing header/footer includes here. -->
|
||||||
|
|
||||||
|
<main class="wrap">
|
||||||
|
<section class="topGrid">
|
||||||
|
<!-- LEFT: readout + buttons -->
|
||||||
<div>
|
<div>
|
||||||
<div class="readout">
|
<div class="readout">
|
||||||
<div class="label">Denary</div>
|
<div class="label">Denary</div>
|
||||||
<div id="denaryNumber" class="num denary">0</div>
|
<div id="denaryNumber" class="num denaryValue">0</div>
|
||||||
|
|
||||||
<div class="label">Binary</div>
|
<div class="label">Binary</div>
|
||||||
<div id="binaryNumber" class="num binary">00000000</div>
|
<div id="binaryNumber" class="num binaryValue">0</div>
|
||||||
|
|
||||||
|
<!-- Orange box: custom on one row, shift on next row -->
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<button class="btn" id="btnCustomBinary" type="button">Custom Binary</button>
|
<div class="controlRow">
|
||||||
<button class="btn" id="btnCustomDenary" type="button">Custom Denary</button>
|
<button class="btn btnPrimary" id="btnCustomBinary" type="button">Custom Binary</button>
|
||||||
|
<button class="btn btnPrimary" id="btnCustomDenary" type="button">Custom Denary</button>
|
||||||
|
</div>
|
||||||
|
<div class="controlRow">
|
||||||
<button class="btn" id="btnShiftLeft" type="button">Left Shift</button>
|
<button class="btn" id="btnShiftLeft" type="button">Left Shift</button>
|
||||||
<button class="btn" id="btnShiftRight" type="button">Right Shift</button>
|
<button class="btn" id="btnShiftRight" type="button">Right Shift</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
|
|
||||||
<!-- Bit rows injected by JS -->
|
<!-- Bits render here -->
|
||||||
<section id="bitsRows" class="bitsRows" aria-label="Bit switches"></section>
|
<section class="bits" id="bitsGrid" aria-label="Bit switches"></section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- RIGHT -->
|
<!-- RIGHT: actions + mode + bit width -->
|
||||||
<aside class="panelCol">
|
<aside class="panelCol">
|
||||||
|
<!-- Red box: move these buttons to the panel -->
|
||||||
|
<div class="card">
|
||||||
|
<div class="cardTitle">Actions</div>
|
||||||
|
|
||||||
|
<div class="actionGrid">
|
||||||
|
<button class="btn" id="btnClear" type="button">Clear</button>
|
||||||
|
|
||||||
|
<button class="btn btnSpin" id="btnDec1" type="button" aria-label="Decrease by 1">−1</button>
|
||||||
|
<button class="btn btnSpin" id="btnInc1" type="button" aria-label="Increase by 1">+1</button>
|
||||||
|
|
||||||
|
<button class="btn" id="btnAutoRandom" type="button">Auto Random</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hint">
|
||||||
|
−1/+1 steps the current value by one. Auto Random runs briefly then stops automatically.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="cardTitle">Mode</div>
|
<div class="cardTitle">Mode</div>
|
||||||
|
|
||||||
@@ -43,7 +81,7 @@ import BaseLayout from "../layouts/BaseLayout.astro";
|
|||||||
<span class="slider"></span>
|
<span class="slider"></span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="toggleLabel" id="lblTwos">Two's complement</div>
|
<div class="toggleLabel" id="lblTwos">Two’s complement</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hint" id="modeHint">
|
<div class="hint" id="modeHint">
|
||||||
@@ -59,17 +97,26 @@ import BaseLayout from "../layouts/BaseLayout.astro";
|
|||||||
|
|
||||||
<div class="bitInputWrap">
|
<div class="bitInputWrap">
|
||||||
<div class="bitInputLabel">Bits</div>
|
<div class="bitInputLabel">Bits</div>
|
||||||
<input id="bitsInput" class="bitInput" type="number" inputmode="numeric" min="4" max="64" step="1" value="8" />
|
<input
|
||||||
|
id="bitsInput"
|
||||||
|
class="bitInput"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
min="1"
|
||||||
|
max="64"
|
||||||
|
step="1"
|
||||||
|
value="8"
|
||||||
|
aria-label="Number of bits"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="miniBtn" id="btnBitsUp" type="button" aria-label="Increase bits">+</button>
|
<button class="miniBtn" id="btnBitsUp" type="button" aria-label="Increase bits">+</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hint">Minimum 4 bits, maximum 64 bits.</div>
|
<div class="hint">Minimum 1 bit, maximum 64 bits.</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
</main>
|
||||||
<script type="module" src="/scripts/binary.js"></script>
|
</body>
|
||||||
</BaseLayout>
|
</html>
|
||||||
|
|||||||
390
src/scripts/binary.js
Normal file
390
src/scripts/binary.js
Normal file
@@ -0,0 +1,390 @@
|
|||||||
|
/* Binary simulator (Unsigned + Two's complement)
|
||||||
|
- bits 1..64
|
||||||
|
- wrap bits every 8 visually (CSS), no scrollbars
|
||||||
|
- bulbs always update in BOTH modes
|
||||||
|
- MSB label shows negative weight in two's complement (e.g. -128)
|
||||||
|
*/
|
||||||
|
|
||||||
|
const bitsGrid = document.getElementById("bitsGrid");
|
||||||
|
const denaryEl = document.getElementById("denaryNumber");
|
||||||
|
const binaryEl = document.getElementById("binaryNumber");
|
||||||
|
|
||||||
|
const modeToggle = document.getElementById("modeToggle");
|
||||||
|
const modeHint = document.getElementById("modeHint");
|
||||||
|
|
||||||
|
const bitsInput = document.getElementById("bitsInput");
|
||||||
|
const btnBitsUp = document.getElementById("btnBitsUp");
|
||||||
|
const btnBitsDown = document.getElementById("btnBitsDown");
|
||||||
|
|
||||||
|
const btnShiftLeft = document.getElementById("btnShiftLeft");
|
||||||
|
const btnShiftRight = document.getElementById("btnShiftRight");
|
||||||
|
const btnCustomBinary = document.getElementById("btnCustomBinary");
|
||||||
|
const btnCustomDenary = document.getElementById("btnCustomDenary");
|
||||||
|
|
||||||
|
const btnClear = document.getElementById("btnClear");
|
||||||
|
const btnDec1 = document.getElementById("btnDec1");
|
||||||
|
const btnInc1 = document.getElementById("btnInc1");
|
||||||
|
const btnAutoRandom = document.getElementById("btnAutoRandom");
|
||||||
|
|
||||||
|
let bitCount = clampInt(Number(bitsInput?.value ?? 8), 1, 64);
|
||||||
|
|
||||||
|
// state is MSB -> LSB
|
||||||
|
let bits = new Array(bitCount).fill(false);
|
||||||
|
|
||||||
|
let autoTimer = null;
|
||||||
|
|
||||||
|
function clampInt(n, min, max){
|
||||||
|
n = Number(n);
|
||||||
|
if (!Number.isFinite(n)) return min;
|
||||||
|
n = Math.floor(n);
|
||||||
|
if (n < min) return min;
|
||||||
|
if (n > max) return max;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
function pow2Big(n){
|
||||||
|
// n is number (0..63)
|
||||||
|
return 1n << BigInt(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isTwos(){
|
||||||
|
return !!modeToggle?.checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRange(){
|
||||||
|
// returns { min: BigInt, max: BigInt, mod: BigInt }
|
||||||
|
const n = bitCount;
|
||||||
|
const mod = pow2Big(n);
|
||||||
|
if (!isTwos()){
|
||||||
|
return { min: 0n, max: mod - 1n, mod };
|
||||||
|
}
|
||||||
|
// two's: [-2^(n-1), 2^(n-1)-1]
|
||||||
|
if (n === 1){
|
||||||
|
return { min: -1n, max: 0n, mod };
|
||||||
|
}
|
||||||
|
const half = pow2Big(n - 1);
|
||||||
|
return { min: -half, max: half - 1n, mod };
|
||||||
|
}
|
||||||
|
|
||||||
|
function currentValueBig(){
|
||||||
|
// interpret current bits as unsigned or two's complement signed
|
||||||
|
let unsigned = 0n;
|
||||||
|
for (let i = 0; i < bitCount; i++){
|
||||||
|
if (!bits[i]) continue;
|
||||||
|
const shift = BigInt(bitCount - 1 - i);
|
||||||
|
unsigned += 1n << shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isTwos()){
|
||||||
|
return unsigned;
|
||||||
|
}
|
||||||
|
|
||||||
|
// signed decode
|
||||||
|
const signBit = bits[0];
|
||||||
|
if (!signBit) return unsigned;
|
||||||
|
|
||||||
|
const { mod } = getRange();
|
||||||
|
return unsigned - mod; // two's complement negative
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFromUnsignedBig(u){
|
||||||
|
// u in [0, 2^n-1]
|
||||||
|
const n = bitCount;
|
||||||
|
for (let i = 0; i < n; i++){
|
||||||
|
const shift = BigInt(n - 1 - i);
|
||||||
|
bits[i] = ((u >> shift) & 1n) === 1n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFromValueBig(v){
|
||||||
|
// v is signed depending on mode. We convert to bit pattern.
|
||||||
|
const { min, max, mod } = getRange();
|
||||||
|
|
||||||
|
if (v < min) v = min;
|
||||||
|
if (v > max) v = max;
|
||||||
|
|
||||||
|
if (!isTwos()){
|
||||||
|
setFromUnsignedBig(v);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// two's: if negative, add 2^n
|
||||||
|
let u = v;
|
||||||
|
if (u < 0n) u = u + mod;
|
||||||
|
setFromUnsignedBig(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildBits(){
|
||||||
|
bitsGrid.innerHTML = "";
|
||||||
|
|
||||||
|
for (let i = 0; i < bitCount; i++){
|
||||||
|
const placePow = bitCount - 1 - i;
|
||||||
|
const unsignedWeight = pow2Big(placePow);
|
||||||
|
|
||||||
|
// label weight depends on mode (MSB negative in two's)
|
||||||
|
let label = unsignedWeight.toString();
|
||||||
|
if (isTwos() && i === 0){
|
||||||
|
label = "-" + unsignedWeight.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const bit = document.createElement("div");
|
||||||
|
bit.className = "bit";
|
||||||
|
bit.innerHTML = `
|
||||||
|
<div class="bulb" id="bulb-${i}" aria-hidden="true">💡</div>
|
||||||
|
<div class="bitVal">${label}</div>
|
||||||
|
<label class="switch" aria-label="Toggle bit ${label}">
|
||||||
|
<input type="checkbox" data-index="${i}">
|
||||||
|
<span class="slider"></span>
|
||||||
|
</label>
|
||||||
|
`;
|
||||||
|
|
||||||
|
bitsGrid.appendChild(bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// hook switches
|
||||||
|
bitsGrid.querySelectorAll('input[type="checkbox"][data-index]').forEach((input) => {
|
||||||
|
input.addEventListener("change", () => {
|
||||||
|
const idx = Number(input.dataset.index);
|
||||||
|
bits[idx] = input.checked;
|
||||||
|
updateReadout();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function binaryStringGrouped(){
|
||||||
|
const raw = bits.map(b => (b ? "1" : "0")).join("");
|
||||||
|
// group every 8 from the RIGHT (LSB side) so long widths look sane
|
||||||
|
// Example: 11 bits -> 00000000 000 (as in your screenshot)
|
||||||
|
const groups = [];
|
||||||
|
for (let end = raw.length; end > 0; end -= 8){
|
||||||
|
const start = Math.max(0, end - 8);
|
||||||
|
groups.unshift(raw.slice(start, end));
|
||||||
|
}
|
||||||
|
return groups.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateModeHint(){
|
||||||
|
if (!modeHint) return;
|
||||||
|
if (isTwos()){
|
||||||
|
modeHint.textContent = "Tip: In two’s complement, the left-most bit (MSB) represents a negative value.";
|
||||||
|
} else {
|
||||||
|
modeHint.textContent = "Tip: In unsigned binary, all bits represent positive values.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateReadout(){
|
||||||
|
const v = currentValueBig();
|
||||||
|
|
||||||
|
// display
|
||||||
|
denaryEl.textContent = v.toString();
|
||||||
|
binaryEl.textContent = binaryStringGrouped();
|
||||||
|
|
||||||
|
// bulbs update ALWAYS (mode should not affect bulb on/off)
|
||||||
|
for (let i = 0; i < bitCount; i++){
|
||||||
|
const bulb = document.getElementById(`bulb-${i}`);
|
||||||
|
if (bulb) bulb.classList.toggle("on", bits[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncUI(){
|
||||||
|
// sync switch positions
|
||||||
|
bitsGrid.querySelectorAll('input[type="checkbox"][data-index]').forEach((input) => {
|
||||||
|
const idx = Number(input.dataset.index);
|
||||||
|
input.checked = !!bits[idx];
|
||||||
|
});
|
||||||
|
|
||||||
|
updateReadout();
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearBits(){
|
||||||
|
bits = new Array(bitCount).fill(false);
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function shiftLeft(){
|
||||||
|
// logical left shift: drop MSB, add 0 at LSB
|
||||||
|
bits.shift();
|
||||||
|
bits.push(false);
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function shiftRight(){
|
||||||
|
// logical right shift: drop LSB, add 0 at MSB
|
||||||
|
bits.pop();
|
||||||
|
bits.unshift(false);
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFromBinaryPrompt(){
|
||||||
|
const v = prompt(`Enter binary (${bitCount} bits). Spaces allowed:`);
|
||||||
|
if (v === null) return;
|
||||||
|
|
||||||
|
const clean = String(v).replace(/\s+/g, "");
|
||||||
|
if (!/^[01]+$/.test(clean)){
|
||||||
|
alert("Invalid input. Use only 0 and 1 (spaces allowed).");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const padded = clean.slice(-bitCount).padStart(bitCount, "0");
|
||||||
|
bits = [...padded].map(ch => ch === "1");
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFromDenaryPrompt(){
|
||||||
|
const v = prompt(`Enter denary (${isTwos() ? "signed" : "unsigned"}).`);
|
||||||
|
if (v === null) return;
|
||||||
|
|
||||||
|
// BigInt parse (handles negatives)
|
||||||
|
let n;
|
||||||
|
try {
|
||||||
|
n = BigInt(String(v).trim());
|
||||||
|
} catch {
|
||||||
|
alert("Invalid number.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFromValueBig(n);
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function stepBy(delta){
|
||||||
|
const v = currentValueBig();
|
||||||
|
const next = v + BigInt(delta);
|
||||||
|
|
||||||
|
// wrap within valid range
|
||||||
|
const { min, max, mod } = getRange();
|
||||||
|
|
||||||
|
let wrapped = next;
|
||||||
|
if (!isTwos()){
|
||||||
|
// unsigned wrap: modulo 2^n
|
||||||
|
wrapped = ((next % mod) + mod) % mod;
|
||||||
|
} else {
|
||||||
|
// signed wrap across [min..max]
|
||||||
|
const span = max - min + 1n; // equals 2^n
|
||||||
|
wrapped = next;
|
||||||
|
while (wrapped > max) wrapped -= span;
|
||||||
|
while (wrapped < min) wrapped += span;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFromValueBig(wrapped);
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
function autoRandomOnce(){
|
||||||
|
// runs briefly then stops automatically
|
||||||
|
if (autoTimer){
|
||||||
|
clearInterval(autoTimer);
|
||||||
|
autoTimer = null;
|
||||||
|
btnAutoRandom.textContent = "Auto Random";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
btnAutoRandom.textContent = "Auto Random (Running…)";
|
||||||
|
const { min, max, mod } = getRange();
|
||||||
|
|
||||||
|
const start = Date.now();
|
||||||
|
const durationMs = 1800; // short burst
|
||||||
|
const tickMs = 90;
|
||||||
|
|
||||||
|
autoTimer = setInterval(() => {
|
||||||
|
const now = Date.now();
|
||||||
|
if (now - start >= durationMs){
|
||||||
|
clearInterval(autoTimer);
|
||||||
|
autoTimer = null;
|
||||||
|
btnAutoRandom.textContent = "Auto Random";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pick a random unsigned pattern 0..2^n-1 then interpret via mode
|
||||||
|
// (this keeps distribution consistent even for signed mode)
|
||||||
|
const r = randomBigIntBelow(mod);
|
||||||
|
setFromUnsignedBig(r);
|
||||||
|
syncUI();
|
||||||
|
}, tickMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
function randomBigIntBelow(maxExclusive){
|
||||||
|
// maxExclusive up to 2^64
|
||||||
|
// Use crypto if available, otherwise fallback (still fine for teaching tool)
|
||||||
|
const n = bitCount;
|
||||||
|
|
||||||
|
if (globalThis.crypto && crypto.getRandomValues){
|
||||||
|
const bytes = Math.ceil(n / 8);
|
||||||
|
const buf = new Uint8Array(bytes);
|
||||||
|
|
||||||
|
while (true){
|
||||||
|
crypto.getRandomValues(buf);
|
||||||
|
let val = 0n;
|
||||||
|
for (const b of buf){
|
||||||
|
val = (val << 8n) + BigInt(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mask extra bits
|
||||||
|
const extra = BigInt(bytes * 8 - n);
|
||||||
|
if (extra > 0n) val = val & ((1n << BigInt(n)) - 1n);
|
||||||
|
|
||||||
|
if (val < maxExclusive) return val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback
|
||||||
|
const maxNum = Number.MAX_SAFE_INTEGER;
|
||||||
|
let val = BigInt(Math.floor(Math.random() * maxNum));
|
||||||
|
return val % maxExclusive;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setBitCount(nextCount){
|
||||||
|
nextCount = clampInt(nextCount, 1, 64);
|
||||||
|
bitCount = nextCount;
|
||||||
|
bitsInput.value = String(bitCount);
|
||||||
|
|
||||||
|
// preserve current value if possible by re-encoding it into new width
|
||||||
|
const v = currentValueBig();
|
||||||
|
bits = new Array(bitCount).fill(false);
|
||||||
|
setFromValueBig(v);
|
||||||
|
|
||||||
|
buildBits();
|
||||||
|
updateModeHint();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onModeChange(){
|
||||||
|
updateModeHint();
|
||||||
|
|
||||||
|
// rebuild labels so MSB shows negative weight in two's mode
|
||||||
|
// preserve current *bit pattern* (not numeric), because students are toggling interpretation
|
||||||
|
const currentPattern = bits.slice();
|
||||||
|
|
||||||
|
buildBits();
|
||||||
|
bits = currentPattern.slice(0, bitCount);
|
||||||
|
|
||||||
|
// if length changed (shouldn't), pad
|
||||||
|
if (bits.length < bitCount){
|
||||||
|
bits = bits.concat(new Array(bitCount - bits.length).fill(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// rebuild labels again (already done), then resync
|
||||||
|
syncUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------- Hooks ----------------- */
|
||||||
|
btnShiftLeft?.addEventListener("click", shiftLeft);
|
||||||
|
btnShiftRight?.addEventListener("click", shiftRight);
|
||||||
|
btnCustomBinary?.addEventListener("click", setFromBinaryPrompt);
|
||||||
|
btnCustomDenary?.addEventListener("click", setFromDenaryPrompt);
|
||||||
|
|
||||||
|
btnClear?.addEventListener("click", clearBits);
|
||||||
|
btnDec1?.addEventListener("click", () => stepBy(-1));
|
||||||
|
btnInc1?.addEventListener("click", () => stepBy(+1));
|
||||||
|
btnAutoRandom?.addEventListener("click", autoRandomOnce);
|
||||||
|
|
||||||
|
btnBitsUp?.addEventListener("click", () => setBitCount(bitCount + 1));
|
||||||
|
btnBitsDown?.addEventListener("click", () => setBitCount(bitCount - 1));
|
||||||
|
bitsInput?.addEventListener("change", () => setBitCount(Number(bitsInput.value)));
|
||||||
|
|
||||||
|
modeToggle?.addEventListener("change", onModeChange);
|
||||||
|
|
||||||
|
/* ----------------- Init ----------------- */
|
||||||
|
updateModeHint();
|
||||||
|
buildBits();
|
||||||
@@ -1,7 +1,20 @@
|
|||||||
/* Font */
|
:root{
|
||||||
|
--bg: #1f2027;
|
||||||
|
--panel: #22242d;
|
||||||
|
--panel2: rgba(255,255,255,.04);
|
||||||
|
--text: #e8e8ee;
|
||||||
|
--muted: #a9acb8;
|
||||||
|
|
||||||
|
--accent: #33ff7a;
|
||||||
|
--accent-dim: rgba(51,255,122,.15);
|
||||||
|
|
||||||
|
--line: rgba(255,255,255,.12);
|
||||||
|
}
|
||||||
|
|
||||||
@font-face{
|
@font-face{
|
||||||
font-family: "DSEG7ClassicRegular";
|
font-family: "DSEG7ClassicRegular";
|
||||||
src:
|
src:
|
||||||
|
url("/fonts/DSEG7Classic-Regular.woff2") format("woff2"),
|
||||||
url("/fonts/DSEG7Classic-Regular.woff") format("woff"),
|
url("/fonts/DSEG7Classic-Regular.woff") format("woff"),
|
||||||
url("/fonts/DSEG7Classic-Regular.ttf") format("truetype");
|
url("/fonts/DSEG7Classic-Regular.ttf") format("truetype");
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
@@ -9,8 +22,17 @@
|
|||||||
font-display: swap;
|
font-display: swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.binaryWrap{
|
body{
|
||||||
padding-top: 8px;
|
margin:0;
|
||||||
|
font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrap{
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 32px 20px 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.topGrid{
|
.topGrid{
|
||||||
@@ -21,6 +43,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.readout{
|
.readout{
|
||||||
|
background: transparent;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
padding: 10px 10px 0;
|
padding: 10px 10px 0;
|
||||||
}
|
}
|
||||||
@@ -41,25 +64,32 @@
|
|||||||
text-shadow: 0 0 18px var(--accent-dim);
|
text-shadow: 0 0 18px var(--accent-dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
.denary{
|
.denaryValue{
|
||||||
font-size: 70px; /* smaller than before */
|
font-size: 72px;
|
||||||
line-height: 1;
|
line-height: 1.0;
|
||||||
margin: 6px 0 10px;
|
margin: 6px 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.binary{
|
.binaryValue{
|
||||||
font-size: 54px; /* smaller than before */
|
font-size: 52px;
|
||||||
letter-spacing: .12em;
|
letter-spacing: .10em;
|
||||||
line-height: 1;
|
line-height: 1.0;
|
||||||
margin: 6px 0 16px;
|
margin: 6px 0 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.controls{
|
.controls{
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
|
display:flex;
|
||||||
|
flex-direction:column;
|
||||||
|
gap: 10px;
|
||||||
|
align-items:center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controlRow{
|
||||||
display:flex;
|
display:flex;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
justify-content:center;
|
justify-content:center;
|
||||||
flex-wrap:wrap;
|
flex-wrap:nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn{
|
.btn{
|
||||||
@@ -68,22 +98,33 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
padding: 12px 14px;
|
padding: 12px 14px;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
font-weight: 700;
|
font-weight: 800;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
min-width: 160px;
|
min-width: 160px;
|
||||||
}
|
}
|
||||||
.btn:active{ transform: translateY(1px); }
|
.btn:active{ transform: translateY(1px); }
|
||||||
|
|
||||||
|
.btnPrimary{
|
||||||
|
background: rgba(51,255,122,.18);
|
||||||
|
border-color: rgba(51,255,122,.45);
|
||||||
|
box-shadow: 0 0 0 1px rgba(51,255,122,.10) inset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btnSpin{
|
||||||
|
min-width: 120px;
|
||||||
|
font-size: 18px;
|
||||||
|
padding: 12px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.divider{
|
.divider{
|
||||||
margin-top: 26px;
|
margin-top: 26px;
|
||||||
border-top: 1px solid var(--line);
|
border-top: 1px solid var(--line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Right-side cards */
|
|
||||||
.panelCol{
|
.panelCol{
|
||||||
display:flex;
|
display:flex;
|
||||||
flex-direction:column;
|
flex-direction:column;
|
||||||
gap: 14px;
|
gap:14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card{
|
.card{
|
||||||
@@ -113,7 +154,7 @@
|
|||||||
display:flex;
|
display:flex;
|
||||||
align-items:center;
|
align-items:center;
|
||||||
justify-content:space-between;
|
justify-content:space-between;
|
||||||
gap: 10px;
|
gap:10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggleLabel{
|
.toggleLabel{
|
||||||
@@ -122,7 +163,6 @@
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switch (reused for mode + bits) */
|
|
||||||
.switch{
|
.switch{
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 56px;
|
width: 56px;
|
||||||
@@ -131,7 +171,6 @@
|
|||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
.switch input{
|
.switch input{
|
||||||
position:absolute;
|
|
||||||
opacity:0;
|
opacity:0;
|
||||||
width:0;
|
width:0;
|
||||||
height:0;
|
height:0;
|
||||||
@@ -164,7 +203,6 @@
|
|||||||
background: var(--accent);
|
background: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bit-width control */
|
|
||||||
.bitWidthRow{
|
.bitWidthRow{
|
||||||
display:grid;
|
display:grid;
|
||||||
grid-template-columns: 44px 1fr 44px;
|
grid-template-columns: 44px 1fr 44px;
|
||||||
@@ -173,13 +211,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.miniBtn{
|
.miniBtn{
|
||||||
height: 44px;
|
height:44px;
|
||||||
width: 44px;
|
width:44px;
|
||||||
border-radius: 12px;
|
border-radius:12px;
|
||||||
background: rgba(255,255,255,.06);
|
background: rgba(255,255,255,.06);
|
||||||
border: 1px solid rgba(255,255,255,.14);
|
border: 1px solid rgba(255,255,255,.14);
|
||||||
color: #fff;
|
color:#fff;
|
||||||
cursor: pointer;
|
cursor:pointer;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
@@ -215,70 +253,83 @@
|
|||||||
}
|
}
|
||||||
.bitInput::-webkit-outer-spin-button,
|
.bitInput::-webkit-outer-spin-button,
|
||||||
.bitInput::-webkit-inner-spin-button{
|
.bitInput::-webkit-inner-spin-button{
|
||||||
-webkit-appearance:none;
|
-webkit-appearance: none;
|
||||||
margin:0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bits: wrap every 8 (rows built in JS) */
|
.actionGrid{
|
||||||
.bitsRows{
|
display:grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.actionGrid .btn{
|
||||||
|
min-width: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------- Bits grid: wrap every 8, centered when <8, no scrollbar -------- */
|
||||||
|
.bits{
|
||||||
margin-top: 22px;
|
margin-top: 22px;
|
||||||
display:flex;
|
padding-top: 18px;
|
||||||
flex-direction:column;
|
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(8, 92px);
|
||||||
gap: 18px;
|
gap: 18px;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
width: fit-content;
|
||||||
|
max-width: 100%;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A row of up to 8 bits */
|
|
||||||
.byteRow{
|
|
||||||
display:flex;
|
|
||||||
justify-content:center;
|
|
||||||
gap: 18px;
|
|
||||||
flex-wrap:nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A single bit */
|
|
||||||
.bit{
|
.bit{
|
||||||
width: 110px;
|
|
||||||
display:flex;
|
display:flex;
|
||||||
flex-direction:column;
|
flex-direction:column;
|
||||||
align-items:center;
|
align-items:center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
padding: 6px 4px;
|
padding: 8px 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bulb emoji: bigger */
|
/* Bulb: emoji 💡 larger, grey when off, glowing when on */
|
||||||
.bulb{
|
.bulb{
|
||||||
font-size: 30px;
|
font-size: 28px; /* bigger bulb */
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
opacity: .20;
|
filter: grayscale(100%) brightness(.85);
|
||||||
filter: grayscale(1);
|
opacity: .65;
|
||||||
transform: translateY(2px);
|
transform: translateY(2px);
|
||||||
|
user-select: none;
|
||||||
}
|
}
|
||||||
.bulb.on{
|
.bulb.on{
|
||||||
|
filter: none;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
filter: grayscale(0);
|
text-shadow: 0 0 18px rgba(255, 216, 107, .55);
|
||||||
text-shadow: 0 0 16px rgba(255,216,107,.65);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Bit place value */
|
||||||
.bitVal{
|
.bitVal{
|
||||||
font-family: "DSEG7ClassicRegular", ui-monospace, monospace;
|
font-family: "DSEG7ClassicRegular", ui-monospace, monospace;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
opacity: .92;
|
opacity: .95;
|
||||||
|
line-height: 1;
|
||||||
min-height: 34px;
|
min-height: 34px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Responsiveness */
|
/* Per-bit switch */
|
||||||
|
.bit .switch{
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 980px){
|
@media (max-width: 980px){
|
||||||
.topGrid{ grid-template-columns: 1fr; }
|
.topGrid{ grid-template-columns: 1fr; }
|
||||||
.denary{ font-size: 62px; }
|
.denaryValue{ font-size: 64px; }
|
||||||
.binary{ font-size: 48px; }
|
.binaryValue{ font-size: 46px; }
|
||||||
.bit{ width: 96px; }
|
.btn{ min-width: 140px; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 520px){
|
@media (max-width: 520px){
|
||||||
.denary{ font-size: 56px; }
|
.bits{
|
||||||
.binary{ font-size: 42px; }
|
grid-template-columns: repeat(4, 92px);
|
||||||
.btn{ min-width: 140px; }
|
}
|
||||||
.byteRow{ gap: 12px; }
|
|
||||||
.bit{ width: 86px; }
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
:root{
|
:root{
|
||||||
--bg: #1f2027;
|
--bg: #1f2027;
|
||||||
--panel: rgba(255,255,255,.04);
|
--panel: #22242d;
|
||||||
|
--panel2: rgba(255,255,255,.04);
|
||||||
--text: #e8e8ee;
|
--text: #e8e8ee;
|
||||||
--muted: #a9acb8;
|
--muted: #a9acb8;
|
||||||
--line: rgba(255,255,255,.12);
|
|
||||||
--accent: #33ff7a;
|
--accent: #33ff7a;
|
||||||
--accent-dim: rgba(51,255,122,.15);
|
--accent-dim: rgba(51,255,122,.15);
|
||||||
|
--line: rgba(255,255,255,.12);
|
||||||
}
|
}
|
||||||
|
|
||||||
*{ box-sizing: border-box; }
|
*{ box-sizing:border-box; }
|
||||||
|
|
||||||
body{
|
body{
|
||||||
margin:0;
|
margin:0;
|
||||||
@@ -17,62 +18,68 @@ body{
|
|||||||
color: var(--text);
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
.page{
|
|
||||||
min-height: calc(100vh - 120px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.siteHeader{
|
.siteHeader{
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
background: rgba(0,0,0,.15);
|
background: rgba(0,0,0,.15);
|
||||||
border-bottom: 1px solid var(--line);
|
backdrop-filter: blur(8px);
|
||||||
backdrop-filter: blur(10px);
|
border-bottom: 1px solid rgba(255,255,255,.06);
|
||||||
}
|
}
|
||||||
|
|
||||||
.siteHeader__inner{
|
.siteHeaderInner{
|
||||||
max-width: 1200px;
|
max-width: 1200px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 14px 20px;
|
padding: 14px 20px;
|
||||||
display: flex;
|
display:flex;
|
||||||
align-items: center;
|
align-items:center;
|
||||||
justify-content: space-between;
|
justify-content:space-between;
|
||||||
gap: 18px;
|
gap: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.brand{
|
.brand{
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
text-decoration: none;
|
text-decoration:none;
|
||||||
font-weight: 800;
|
font-weight: 900;
|
||||||
letter-spacing: .02em;
|
letter-spacing:.02em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav{
|
.nav{
|
||||||
display: flex;
|
display:flex;
|
||||||
gap: 14px;
|
gap: 14px;
|
||||||
flex-wrap: wrap;
|
flex-wrap:wrap;
|
||||||
justify-content: flex-end;
|
justify-content:flex-end;
|
||||||
}
|
}
|
||||||
|
.nav a{
|
||||||
.nav__link{
|
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
text-decoration: none;
|
text-decoration:none;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
.nav__link:hover{ color: var(--text); }
|
.nav a:hover{ color: var(--text); }
|
||||||
|
|
||||||
|
.siteMain{
|
||||||
|
min-height: calc(100vh - 140px);
|
||||||
|
}
|
||||||
|
|
||||||
.siteFooter{
|
.siteFooter{
|
||||||
border-top: 1px solid var(--line);
|
border-top: 1px solid rgba(255,255,255,.08);
|
||||||
|
margin-top: 32px;
|
||||||
background: rgba(0,0,0,.10);
|
background: rgba(0,0,0,.10);
|
||||||
}
|
}
|
||||||
|
|
||||||
.siteFooter__inner{
|
.siteFooterInner{
|
||||||
max-width: 1200px;
|
max-width: 1200px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 18px 20px;
|
padding: 18px 20px 26px;
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
display: grid;
|
line-height: 1.6;
|
||||||
gap: 6px;
|
}
|
||||||
|
|
||||||
|
.footerTitle{
|
||||||
|
color: var(--text);
|
||||||
|
opacity:.9;
|
||||||
|
font-weight: 800;
|
||||||
|
margin-bottom: 6px;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user