-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mawrxyz/colour-bars
Colour bars
- Loading branch information
Showing
12 changed files
with
314 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Melissa Zhu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# RGB Visualisation Web App | ||
|
||
A responsive web application that visualises the red, green, and blue components of an image. Users can toggle between different colour channels (Red, Green, Blue) to see how each contributes to the overall image. It also supports **fullscreen mode** with an intuitive UI optimised for both desktop and mobile screens. | ||
|
||
--- | ||
|
||
## Features | ||
|
||
- **Colour Channel Toggle:** Easily toggle the visibility of red, green, and blue colour channels. | ||
- **Responsive Design:** Automatically adapts to various screen sizes and devices, with optimised mobile support. | ||
- **Fullscreen Mode:** View the application in fullscreen mode with a dedicated fullscreen button. | ||
- **Mix-Blend Mode:** Layers use blend modes for an authentic RGB visualisation. | ||
- **Visible Colour Bars:** At full colour, this section shows white (made of red + green + blue), yellow (red + green), cyan (green + blue), green, magenta (red + blue), red, blue and black (absence of colour/light). Users can see how these colours change when certain colour channels are toggled off and on. | ||
|
||
--- | ||
|
||
## Demo | ||
|
||
Try the live demo here: [Live Demo on GitHub Pages](https://mawrxyz.github.io/rgb-viz/) | ||
|
||
--- | ||
|
||
## How to Use | ||
|
||
1. **Colour Channel Buttons:** | ||
- Click on **Red, Green, or Blue** to toggle the visibility of that colour channel. | ||
- Tooltip on hover tells you whether the button will turn the visibility of that colour channel "on" or "off". | ||
|
||
2. **Fullscreen Mode:** | ||
- Click the fullscreen icon to enter fullscreen mode. | ||
- Click the collapse icon to exit fullscreen mode. | ||
|
||
3. **Mobile Support:** | ||
- On mobile devices, the buttons stack vertically to ensure the UI fits smaller screens. | ||
|
||
--- | ||
|
||
## Acknowledgements | ||
|
||
- **Pixabay / Pexels**: | ||
The main image used in this visualisation was sourced from [Pexels](https://www.pexels.com/photo/red-orange-and-green-leaves-during-daytime-33817/) and is licensed under [CC0](https://creativecommons.org/publicdomain/zero/1.0/). | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for details. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,114 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const layers = { | ||
redLayer: document.getElementById('redLayer'), | ||
greenLayer: document.getElementById('greenLayer'), | ||
blueLayer: document.getElementById('blueLayer') | ||
redLayer: document.querySelectorAll('.redLayer'), | ||
greenLayer: document.querySelectorAll('.greenLayer'), | ||
blueLayer: document.querySelectorAll('.blueLayer') | ||
}; | ||
const allLayers = Object.values(layers); | ||
|
||
const allLayers = [...layers.redLayer, ...layers.greenLayer, ...layers.blueLayer]; | ||
|
||
const fullscreenButton = document.getElementById('fullscreen-button'); | ||
const expandIcon = document.getElementById('expand-icon'); | ||
const collapseIcon = document.getElementById('collapse-icon'); | ||
|
||
// Function to toggle visibility of a layer | ||
function toggleLayer(layer) { | ||
const img = layers[layer]; | ||
if (img.style.display === 'block') { | ||
img.style.display = 'none'; // Hide the layer if it is visible | ||
layers[layer].forEach(img => { | ||
img.style.display = (img.style.display === 'block' || img.style.display === '') | ||
? 'none' : 'block'; // Toggle visibility | ||
}); | ||
} | ||
|
||
// Update tooltips dynamically for layer buttons | ||
function updateTooltip(button) { | ||
const dataLayer = button.getAttribute('data-layer'); | ||
const isActive = button.classList.contains('active'); | ||
const lightColor = dataLayer.replace('Layer', '').toLowerCase(); | ||
const action = isActive ? 'off' : 'on'; | ||
|
||
const tooltipText = `Toggle ${lightColor} visibility ${action}`; | ||
button.setAttribute('title', tooltipText); // Modify the tooltip | ||
} | ||
|
||
// Toggle full-screen mode | ||
function toggleFullscreen() { | ||
if (!document.fullscreenElement) { | ||
enterFullscreen(); | ||
} else { | ||
exitFullscreen(); | ||
} | ||
} | ||
|
||
// Enter full-screen mode | ||
function enterFullscreen() { | ||
const elem = document.documentElement; | ||
if (elem.requestFullscreen) { | ||
elem.requestFullscreen(); | ||
} else if (elem.mozRequestFullScreen) { | ||
elem.mozRequestFullScreen(); | ||
} else if (elem.webkitRequestFullscreen) { | ||
elem.webkitRequestFullscreen(); | ||
} else if (elem.msRequestFullscreen) { | ||
elem.msRequestFullscreen(); | ||
} | ||
toggleIcons(true); | ||
fullscreenButton.setAttribute('title', 'Exit fullscreen'); | ||
} | ||
|
||
// Exit full-screen mode | ||
function exitFullscreen() { | ||
if (document.exitFullscreen) { | ||
document.exitFullscreen(); | ||
} else if (document.mozCancelFullScreen) { | ||
document.mozCancelFullScreen(); | ||
} else if (document.webkitExitFullscreen) { | ||
document.webkitExitFullscreen(); | ||
} else if (document.msExitFullscreen) { | ||
document.msExitFullscreen(); | ||
} | ||
toggleIcons(false); | ||
fullscreenButton.setAttribute('title', 'Fullscreen'); | ||
} | ||
|
||
// Toggle icons based on full-screen state | ||
function toggleIcons(isFullscreen) { | ||
if (isFullscreen) { | ||
expandIcon.style.display = 'none'; | ||
collapseIcon.style.display = 'block'; | ||
} else { | ||
img.style.display = 'block'; // Show the layer if it is hidden | ||
expandIcon.style.display = 'block'; | ||
collapseIcon.style.display = 'none'; | ||
} | ||
} | ||
|
||
// Initially show all layers | ||
// Listen for full-screen changes | ||
document.addEventListener('fullscreenchange', () => { | ||
const isFullscreen = !!document.fullscreenElement; | ||
toggleIcons(isFullscreen); | ||
fullscreenButton.setAttribute('title', isFullscreen ? 'Exit fullscreen' : 'Fullscreen'); | ||
}); | ||
|
||
// Add event listener to full-screen button | ||
fullscreenButton.addEventListener('click', toggleFullscreen); | ||
|
||
// Show all layers on page load | ||
function showAllLayers() { | ||
allLayers.forEach(img => img.style.display = 'block'); | ||
} | ||
|
||
// Add event listeners to toggle buttons | ||
document.querySelectorAll('#toggle div').forEach(button => { | ||
button.addEventListener('click', function() { | ||
// Toggle the active class for the button | ||
button.classList.toggle('active'); | ||
|
||
// Toggle the corresponding layer | ||
const dataLayer = button.getAttribute('data-layer'); | ||
toggleLayer(dataLayer); | ||
button.classList.toggle('active'); // Toggle active class | ||
const dataLayer = button.getAttribute('data-layer'); // Get layer name | ||
toggleLayer(dataLayer); // Toggle the corresponding layer | ||
updateTooltip(button); // Update tooltip after each click | ||
}); | ||
|
||
// Initialize tooltips on page load | ||
updateTooltip(button); | ||
}); | ||
|
||
// On page load, show all layers | ||
// Show all layers on page load | ||
showAllLayers(); | ||
}); |
Oops, something went wrong.