Files
CS-Box/Export/assets/js/hexColours.js
Alexander Davis 93b5f11abe Wave 1 Beta Release
# Wave 1 Beta Release

---

## Key Features and Enhancements

### 1. Core Functionality
- Developed and optimized JavaScript functions for binary, hexadecimal, and logic gate simulations, ensuring high performance and compatibility across GCSE and A-Level specifications.
- Introduced dynamic behavior to adapt pages (e.g., GCSE vs A-Level) based on URL or heading context.
- Streamlined reset, toggle, and update functionalities for user inputs and sliders across various simulation pages.

### 2. Hexadecimal Simulator
- Enabled two configurations:
  - 8-bit binary with 2-digit hexadecimal (GCSE).
  - 16-bit binary with 4-digit hexadecimal (A-Level).
- Ensured user input validation for denary and hexadecimal values with robust error handling and feedback.

### 3. Hex Colors Module
- Added dynamic color preview updates for RGB sliders, denary, binary, and hexadecimal values.
- Included an "invert color" feature with corresponding visual updates.

### 4. Logic Gates Module
- Implemented NOT, AND, and OR gates with toggle buttons and live output updates.
- Enhanced reset functionality to initialize states correctly for each gate type.

### 5. Error Handling
- Resolved bugs related to undefined slider properties and invalid binary/hexadecimal inputs.
- Implemented fallback defaults for invalid or canceled inputs.

---

## Visual Enhancements

### 1. Custom Illustrations
- Created custom images for the following sections:
  - **About CS:Box**: A simplistic and educational-themed design.
  - **The Evolution from Bit:Box**: A visual transition from Bit:Box to CS:Box.
  - **Educational Impact**: Vibrant and engaging designs showcasing classroom learning.
- Refined visual hierarchy across all pages for better user experience.

### 2. Navigation Revamp
- Redesigned Bootstrap-based dropdown menus for better usability and accessibility.
- Improved menu hierarchy to align with the UK Computing Curriculum elements.

---

## Documentation

### 1. CS:Box Overview
- Added content explaining the project's evolution from Bit:Box and its educational significance.
- Highlighted key features and their relevance to the UK Computing Curriculum.

### 2. GitHub Repository
- Structured repository with concise descriptions of modules, features, and usage instructions.

---

## Bug Fixes and Optimizations
- Addressed issues with sliders not functioning correctly after reset on hexadecimal pages.
- Fixed error with NOT gate toggling state incorrectly upon reset.
- Streamlined JavaScript logic across all simulations to reduce redundancy and improve maintainability.

---

## Future Scope
- Prepare for **Wave 2 Release** with additional simulations (e.g., XOR gates, floating-point representations).
- Enhance accessibility features for a more inclusive user experience.
- Explore collaborative features for classroom settings.

---

*Wave 1 Beta Release is the foundation of CS:Box, setting the stage for engaging, curriculum-aligned computing education tools.*
2024-12-07 22:49:29 +00:00

114 lines
3.8 KiB
JavaScript

const LIGHT_MULTIPLIER = 100 / 15;
const COLORS = ['R', 'G', 'B'];
const PLACES = [1, 16];
let denary = 0;
let redDenary = 0;
let greenDenary = 0;
let blueDenary = 0;
let redBinary = "";
let greenBinary = "";
let blueBinary = "";
let hexadecimal = "";
const places = {
R16: 0, R1: 0,
G16: 0, G1: 0,
B16: 0, B1: 0
};
function resetColours() {
COLORS.forEach(color => {
PLACES.forEach(place => {
resetPlace(color, place);
});
});
}
function resetPlace(color, place) {
const placeKey = `${color}${place}`;
places[placeKey] = 0;
const light = (LIGHT_MULTIPLIER * places[placeKey]) / 100;
document.getElementById(`blb${placeKey}`).style.opacity = light;
updateColours();
}
function togglePlace(color, place, direction) {
const placeKey = `${color}${place}`;
const currentValue = places[placeKey];
if ((direction === 'up' && currentValue < 15) || (direction === 'down' && currentValue > 0)) {
places[placeKey] += direction === 'up' ? 1 : -1;
const light = (LIGHT_MULTIPLIER * places[placeKey]) / 100;
document.getElementById(`blb${placeKey}`).style.opacity = light;
updateColours();
}
}
function updateColours() {
redDenary = (places.R16 * 16) + places.R1;
greenDenary = (places.G16 * 16) + places.G1;
blueDenary = (places.B16 * 16) + places.B1;
denary = `${redDenary}, ${greenDenary}, ${blueDenary}`;
hexadecimal = `#${convertToHex(places.R16)}${convertToHex(places.R1)}${convertToHex(places.G16)}${convertToHex(places.G1)}${convertToHex(places.B16)}${convertToHex(places.B1)}`;
redBinary = `${convertToBinary(places.R16)}${convertToBinary(places.R1)}`;
greenBinary = `${convertToBinary(places.G16)}${convertToBinary(places.G1)}`;
blueBinary = `${convertToBinary(places.B16)}${convertToBinary(places.B1)}`;
document.getElementById("denaryNumber").innerHTML = denary;
document.getElementById("hexadecimalNumber").innerHTML = hexadecimal;
document.getElementById("colouredHex").style.backgroundColor = hexadecimal;
document.getElementById("invertedHex").style.backgroundColor = invertedHex();
document.getElementById("redBinaryNumber").innerHTML = redBinary;
document.getElementById("blueBinaryNumber").innerHTML = blueBinary;
document.getElementById("greenBinaryNumber").innerHTML = greenBinary;
}
function invertedHex() {
return `#${convertToHex(15 - places.R16)}${convertToHex(15 - places.R1)}${convertToHex(15 - places.G16)}${convertToHex(15 - places.G1)}${convertToHex(15 - places.B16)}${convertToHex(15 - places.B1)}`;
}
function convertToHex(num) {
return num < 10 ? num.toString() : String.fromCharCode(55 + num); // 55 = ASCII offset for A (65) - 10
}
function convertToBinary(num) {
return num.toString(2).padStart(4, '0');
}
function updateHex(customHex) {
if (!customHex) {
resetColours();
} else {
if (customHex.charAt(0) === "#") customHex = customHex.slice(1);
if (isHex(customHex) && customHex.length === 6) {
customHex.split('').forEach((digit, i) => {
const color = COLORS[Math.floor(i / 2)];
const place = i % 2 === 0 ? 16 : 1;
const placeKey = `${color}${place}`;
places[placeKey] = parseInt(digit, 16);
const light = (LIGHT_MULTIPLIER * places[placeKey]) / 100;
document.getElementById(`blb${placeKey}`).style.opacity = light;
});
updateColours();
} else {
alert("Invalid Entry");
resetColours();
}
}
}
function isHex(str) {
return /^[0-9A-Fa-f]+$/.test(str);
}
function requestHex() {
const customHex = prompt("Please enter your Hex Value");
updateHex(customHex);
}
function invertHex() {
updateHex(invertedHex());
}