can you make this app more advance? <html><head><base…
- User
can you make this app more advance? Toucan.ia Advanced Colorblind Friendly Visualizer | The Mirror Company
- Assistant
can you make this app more advance? Toucan.ia Advanced Colorblind Friendly Visualizer | The Mirror Company
Certainly! I can help enhance your Toucan.ia Advanced Colorblind Friendly Visualizer to make it more sophisticated and feature-rich. Below are several advanced features and improvements that can be integrated into your existing application:
Enhanced Audio Analysis:
Interactive 3D Controls:
Additional Visualization Modes:
User Interface Enhancements:
dat.GUI for real-time adjustment of visualization parameters.Performance Optimizations:
Accessibility Improvements:
Below is the updated code incorporating the above enhancements. I've added comments to highlight the new sections and explain their functionalities.
<!DOCTYPE html>
<html lang="en">
<head>
<base href="https://toucan.ia/visualizer" />
<meta charset="UTF-8">
<title>Toucan.ia Advanced Colorblind Friendly Visualizer | The Mirror Company</title>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<!-- Added OrbitControls -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/examples/js/controls/OrbitControls.js"></script>
<!-- Added dat.GUI for settings -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.7/dat.gui.min.js"></script>
<style>
body {
font-family: 'Playfair Display', serif;
background-color: #f5e6d3;
color: #5a4a3f;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
overflow: hidden;
transition: background-color 0.5s, color 0.5s;
}
body.dark-mode {
background-color: #1e1e1e;
color: #ffffff;
}
h1 {
font-size: 2.5em;
margin-bottom: 20px;
text-align: center;
}
#controls {
background-color: #e6d8c6;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
z-index: 10;
transition: background-color 0.5s;
}
body.dark-mode #controls {
background-color: #333333;
}
button, select, input[type="file"] {
font-family: 'Playfair Display', serif;
background-color: #d1b89b;
border: none;
color: #5a4a3f;
padding: 10px 20px;
margin: 10px;
border-radius: 5px;
font-size: 1em;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
}
body.dark-mode button, body.dark-mode select, body.dark-mode input[type="file"] {
background-color: #555555;
color: #ffffff;
}
button:hover, select:hover {
background-color: #c1a88b;
}
body.dark-mode button:hover, body.dark-mode select:hover {
background-color: #777777;
}
#fullscreenContainer {
position: relative;
width: 100%;
height: calc(100vh - 220px);
overflow: hidden;
}
#fullscreenButton {
position: absolute;
top: 10px;
right: 10px;
z-index: 10;
background-color: rgba(209, 184, 155, 0.7);
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
body.dark-mode #fullscreenButton {
background-color: rgba(85, 85, 85, 0.7);
}
#snapshotButton {
position: absolute;
top: 10px;
left: 10px;
z-index: 10;
background-color: rgba(209, 184, 155, 0.7);
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
body.dark-mode #snapshotButton {
background-color: rgba(85, 85, 85, 0.7);
}
/* Tooltip Styles */
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 140px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%; /* Position above the button */
left: 50%;
margin-left: -70px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
</head>
<body>
<h1>Toucan.ia Advanced Colorblind Friendly Visualizer</h1>
<div id="controls">
<input type="file" id="audioInput" accept="audio/*" aria-label="Upload Audio">
<select id="colorMode" aria-label="Select Color Mode">
<option value="protan">Protan</option>
<option value="tritan">Tritan</option>
<option value="deutan">Deutan</option>
<option value="mira" selected>Mira Palette</option>
<!-- Added more colorblind modes -->
<option value="achromatic">Achromatic</option>
<option value="monochromacy">Monochromacy</option>
</select>
<select id="visualizerMode" aria-label="Select Visualizer Mode">
<option value="psychedelicSpiral">Psychedelic Spiral</option>
<option value="chaosVortex">Chaos Vortex</option>
<option value="fracturedDimension">Fractured Dimension</option>
<!-- Added new visualization modes -->
<option value="waveform">Waveform</option>
<option value="barGraph">3D Bar Graph</option>
</select>
<select id="zoomLevel" aria-label="Select Zoom Level">
<option value="0.5">Zoom Out 100%</option>
<option value="0.75">Zoom Out 75%</option>
<option value="0.9">Zoom Out 50%</option>
<option value="1" selected>Normal Zoom</option>
<option value="1.25">Zoom In 25%</option>
<option value="1.5">Zoom In 50%</option>
<option value="1.75">Zoom In 75%</option>
<option value="2">Zoom In 100%</option>
</select>
<button id="playPause">Play</button>
<!-- Added Dark Mode Toggle -->
<button id="darkModeToggle">Dark Mode</button>
</div>
<div id="fullscreenContainer">
<button id="fullscreenButton" class="tooltip">Fullscreen
<span class="tooltiptext">Toggle Fullscreen</span>
</button>
<button id="snapshotButton" class="tooltip">Snapshot
<span class="tooltiptext">Capture Current View</span>
</button>
</div>
<script>
// Initialize Audio Context and Analyser
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const analyser = audioContext.createAnalyser();
analyser.fftSize = 2048;
const bufferLength = analyser.frequencyBinCount;
const dataArray = new Uint8Array(bufferLength);
// Variables for Audio Playback
let audioSource;
let audioBuffer;
let isPlaying = false;
// Define Colorblind Modes and Palettes
const colorModes = {
protan: ['#FFB300', '#0072B2', '#009E73', '#CC79A7', '#F0E442', '#D55E00', '#E69F00', '#56B4E9', '#009E73', '#F0E442', '#0072B2', '#D55E00'],
tritan: ['#FFFF00', '#00FF00', '#ADFF2F', '#7FFF00', '#32CD32', '#98FB98', '#90EE90', '#00FA9A', '#7CFC00', '#9ACD32', '#6B8E23', '#556B2F'],
deutan: ['#FF0000', '#0000FF', '#FF4500', '#1E90FF', '#DC143C', '#4169E1', '#B22222', '#6495ED', '#8B0000', '#4682B4', '#CD5C5C', '#0000CD'],
mira: ['#3c0419', '#94fc9c', '#160446', '#6b0463', '#8FF000', '#4cc0a0', '#FF4700', '#7BA05B', '#644468', '#CCCCFF', '#FFEFD5', '#003153'],
achromatic: ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000'],
monochromacy: ['#FF0000', '#00FF00', '#0000FF'] // Simplified palette
};
// Three.js Setup
const scene = new THREE.Scene();
// Changed aspect ratio to match container
const container = document.getElementById('fullscreenContainer');
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(container.clientWidth, container.clientHeight);
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
camera.position.z = 5;
// Added OrbitControls for interactive camera manipulation
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true; // Smooth camera movements
controls.dampingFactor = 0.05;
// Visualization Variables
let visualizer;
let time = 0;
// GUI for advanced settings (optional)
const gui = new dat.GUI({ autoPlace: false, width: 300 });
document.body.appendChild(gui.domElement);
gui.domElement.style.position = 'absolute';
gui.domElement.style.top = '20px';
gui.domElement.style.right = '20px';
const guiParams = {
rotationSpeed: 0.005,
particleSize: 0.05,
colorIntensity: 1.0,
background: '#f5e6d3'
};
// Add GUI controls
gui.add(guiParams, 'rotationSpeed', 0, 0.05).name('Rotation Speed').onChange(() => {});
gui.add(guiParams, 'particleSize', 0.01, 0.2).name('Particle Size').onChange(value => {
if (visualizer && visualizer.material.size !== undefined) {
visualizer.material.size = value;
}
});
gui.add(guiParams, 'colorIntensity', 0.5, 2.0).name('Color Intensity').onChange(() => {});
gui.addColor(guiParams, 'background').name('Background Color').onChange(value => {
document.body.style.backgroundColor = value;
scene.background = new THREE.Color(value);
});
// Function to Load Audio File
function loadAudio(file) {
const reader = new FileReader();
reader.onload = function(e) {
audioContext.decodeAudioData(e.target.result, function(buffer) {
audioBuffer = buffer;
document.getElementById('playPause').disabled = false;
playAudio(); // Auto-play after loading
});
};
reader.readAsArrayBuffer(file);
}
// Function to Play Audio
function playAudio() {
if (audioBuffer) {
if (isPlaying) {
audioSource.stop();
isPlaying = false;
document.getElementById('playPause').textContent = 'Play';
} else {
audioSource = audioContext.createBufferSource();
audioSource.buffer = audioBuffer;
audioSource.connect(analyser);
analyser.connect(audioContext.destination);
audioSource.start(0);
isPlaying = true;
document.getElementById('playPause').textContent = 'Pause';
}
}
}
// Visualization Creation Functions
function createPsychedelicSpiral() {
const geometry = new THREE.BufferGeometry();
const material = new THREE.PointsMaterial({ size: guiParams.particleSize, vertexColors: true, transparent: true });
const positions = [];
const colors = [];
const colorMode = document.getElementById('colorMode').value;
const colorPalette = colorModes[colorMode];
for (let i = 0; i < 10000; i++) {
const t = i / 100;
const x = Math.sin(t) * (1 + t / 10) * Math.cos(t * 0.1);
const y = Math.cos(t) * (1 + t / 10) * Math.sin(t * 0.1);
const z = t / 5 * Math.sin(t * 0.05);
positions.push(x, y, z);
const color = new THREE.Color(colorPalette[i % colorPalette.length]);
colors.push(color.r, color.g, color.b);
}
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
return new THREE.Points(geometry, material);
}
function createChaosVortex() {
const geometry = new THREE.BufferGeometry();
const material = new THREE.LineBasicMaterial({ vertexColors: true });
const positions = [];
const colors = [];
const colorMode = document.getElementById('colorMode').value;
const colorPalette = colorModes[colorMode];
for (let i = 0; i < 1000; i++) {
const t = i * 0.1;
const x = Math.sin(t) * (2 + Math.cos(t * 3));
const y = Math.cos(t) * (2 + Math.sin(t * 2));
const z = Math.sin(t * 4) + Math.cos(t * 5);
positions.push(x, y, z);
const color = new THREE.Color(colorPalette[i % colorPalette.length]);
colors.push(color.r, color.g, color.b);
}
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
return new THREE.Line(geometry, material);
}
function createFracturedDimension() {
const geometry = new THREE.BufferGeometry();
const material = new THREE.PointsMaterial({ size: guiParams.particleSize, vertexColors: true, transparent: true });
const positions = [];
const colors = [];
const colorMode = document.getElementById('colorMode').value;
const colorPalette = colorModes[colorMode];
for (let i = 0; i < 5000; i++) {
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
const r = Math.pow(Math.random(), 1/3);
const x = r * Math.sin(phi) * Math.cos(theta);
const y = r * Math.sin(phi) * Math.sin(theta);
const z = r * Math.cos(phi);
positions.push(x, y, z);
const color = new THREE.Color(colorPalette[i % colorPalette.length]);
colors.push(color.r, color.g, color.b);
}
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
return new THREE.Points(geometry, material);
}
// New Visualization Modes
function createWaveform() {
const geometry = new THREE.BufferGeometry();
const material = new THREE.LineBasicMaterial({ color: 0xffffff, linewidth: 2 });
const positions = [];
const segments = 1024; // Number of points in waveform
for (let i = 0; i < segments; i++) {
const x = (i / segments) * 10 - 5;
const y = 0;
const z = 0;
positions.push(x, y, z);
}
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
return new THREE.Line(geometry, material);
}
function createBarGraph() {
const group = new THREE.Group();
const colorMode = document.getElementById('colorMode').value;
const colorPalette = colorModes[colorMode];
const barCount = 64;
const spacing = 0.2;
for (let i = 0; i < barCount; i++) {
const geometry = new THREE.BoxGeometry(0.1, 1, 0.1);
const material = new THREE.MeshStandardMaterial({ color: colorPalette[i % colorPalette.length] });
const bar = new THREE.Mesh(geometry, material);
bar.position.x = (i - barCount / 2) * (0.2 + spacing);
bar.position.y = 0.5;
group.add(bar);
}
// Add light for better visibility
const light = new THREE.PointLight(0xffffff, 1, 100);
light.position.set(10, 10, 10);
group.add(light);
return group;
}
// Function to Create Visualizer Based on Selected Mode
function updateVisualizer() {
if (visualizer) {
scene.remove(visualizer);
}
const mode = document.getElementById('visualizerMode').value;
switch (mode) {
case 'psychedelicSpiral':
visualizer = createPsychedelicSpiral();
break;
case 'chaosVortex':
visualizer = createChaosVortex();
break;
case 'fracturedDimension':
visualizer = createFracturedDimension();
break;
case 'waveform':
visualizer = createWaveform();
break;
case 'barGraph':
visualizer = createBarGraph();
break;
default:
visualizer = createPsychedelicSpiral();
}
scene.add(visualizer);
}
// Function to Update Zoom Level
function updateZoom() {
const zoomLevel = parseFloat(document.getElementById('zoomLevel').value);
camera.position.z = 5 / zoomLevel;
controls.update();
}
// Function to Capture Snapshot
function captureSnapshot() {
renderer.render(scene, camera);
const dataURL = renderer.domElement.toDataURL('image/png');
const link = document.createElement('a');
link.href = dataURL;
link.download = 'visualizer_snapshot.png';
link.click();
}
// Function to Toggle Dark Mode
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
}
// Animation Loop with Enhanced Audio Analysis
function animate() {
requestAnimationFrame(animate);
controls.update(); // Update OrbitControls
// Get Audio Data
analyser.getByteFrequencyData(dataArray);
// Calculate Average Frequency for general loudness
const averageFrequency = dataArray.reduce((a, b) => a + b) / bufferLength;
const loudness = averageFrequency / 255;
// Optional: Beat Detection (Simple)
const beatCutoff = 0.25;
const isBeat = loudness > beatCutoff;
// Update Visualizer Based on Mode
if (isPlaying && visualizer) {
const mode = document.getElementById('visualizerMode').value;
switch (mode) {
case 'psychedelicSpiral':
case 'fracturedDimension':
visualizer.rotation.x += guiParams.rotationSpeed;
visualizer.rotation.y += guiParams.rotationSpeed * 1.5;
visualizer.rotation.z += guiParams.rotationSpeed * 0.5;
// Dynamic Color Adjustment
const colors = visualizer.geometry.attributes.color;
const colorMode = document.getElementById('colorMode').value;
const colorPalette = colorModes[colorMode];
for (let i = 0; i < colors.count; i++) {
const colorIndex = (i + Math.floor(time * 10)) % colorPalette.length;
const color = new THREE.Color(colorPalette[colorIndex]);
colors.setXYZ(i, color.r * guiParams.colorIntensity, color.g * guiParams.colorIntensity, color.b * guiParams.colorIntensity);
}
colors.needsUpdate = true;
// Distortion Effect
const positions = visualizer.geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const distortionAmount = 0.01 * loudness;
positions.setXYZ(
i,
x + Math.sin(time + y) * distortionAmount,
y + Math.cos(time + z) * distortionAmount,
z + Math.sin(time + x) * distortionAmount
);
}
positions.needsUpdate = true;
break;
case 'chaosVortex':
visualizer.rotation.x += guiParams.rotationSpeed * 1.2;
visualizer.rotation.y += guiParams.rotationSpeed * 1.8;
// Color pulse on beat
if (isBeat) {
visualizer.material.color.setHex(Math.random() * 0xffffff);
}
break;
case 'waveform':
updateWaveform();
break;
case 'barGraph':
updateBarGraph();
break;
default:
break;
}
}
renderer.render(scene, camera);
}
// Functions for New Visualization Modes
let waveformMesh;
function createWaveform() {
const geometry = new THREE.BufferGeometry();
const material = new THREE.LineBasicMaterial({ color: 0xffffff, linewidth: 2 });
const segments = 1024; // Number of points in waveform
const positions = new Float32Array(segments * 3);
for (let i = 0; i < segments; i++) {
const x = (i / segments) * 10 - 5;
const y = 0;
const z = 0;
positions[i * 3] = x;
positions[i * 3 + 1] = y;
positions[i * 3 + 2] = z;
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
waveformMesh = new THREE.Line(geometry, material);
return waveformMesh;
}
function updateWaveform() {
const segments = 1024;
const positions = visualizer.geometry.attributes.position.array;
for (let i = 0; i < segments; i++) {
const amplitude = dataArray[i] / 255;
positions[i * 3 + 1] = amplitude * 5; // Y-axis represents amplitude
}
visualizer.geometry.attributes.position.needsUpdate = true;
}
let barGraph;
function createBarGraph() {
const group = new THREE.Group();
const colorMode = document.getElementById('colorMode').value;
const colorPalette = colorModes[colorMode];
const barCount = 64;
const spacing = 0.2;
for (let i = 0; i < barCount; i++) {
const geometry = new THREE.BoxGeometry(0.1, 1, 0.1);
const material = new THREE.MeshStandardMaterial({ color: colorPalette[i % colorPalette.length] });
const bar = new THREE.Mesh(geometry, material);
bar.position.x = (i - barCount / 2) * (0.2 + spacing);
bar.position.y = 0.5;
group.add(bar);
}
// Add light for better visibility
const light = new THREE.PointLight(0xffffff, 1, 100);
light.position.set(10, 10, 10);
group.add(light);
barGraph = group;
return barGraph;
}
function updateBarGraph() {
const bars = barGraph.children.filter(child => child.isMesh);
const slice = Math.floor(bufferLength / bars.length);
for (let i = 0; i < bars.length; i++) {
const sum = dataArray.slice(i * slice, (i + 1) * slice).reduce((a, b) => a + b, 0);
const average = sum / slice;
const scale = (average / 255) * 5; // Scale based on amplitude
bars[i].scale.y = Math.max(scale, 0.1);
// Change color based on loudness
const colorIntensity = Math.min(average / 255 * guiParams.colorIntensity, 1);
bars[i].material.color.setHex(THREE.ColorConverter(hexToNumber(colorModes[colorMode][i % colorModes[colorMode].length])).multiplyScalar(colorIntensity).getHex());
}
}
// Utility Function to Convert Hex to Number
function hexToNumber(hex) {
return parseInt(hex.replace('#', '0x'));
}
// Event Listeners
document.getElementById('audioInput').addEventListener('change', function(e) {
loadAudio(e.target.files[0]);
});
document.getElementById('playPause').addEventListener('click', function() {
playAudio();
});
document.getElementById('colorMode').addEventListener('change', () => {
updateVisualizer();
});
document.getElementById('visualizerMode').addEventListener('change', () => {
updateVisualizer();
});
document.getElementById('zoomLevel').addEventListener('change', () => {
updateZoom();
});
document.getElementById('fullscreenButton').addEventListener('click', () => {
if (!document.fullscreenElement) {
if (container.requestFullscreen) {
container.requestFullscreen();
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
});
document.getElementById('snapshotButton').addEventListener('click', () => {
captureSnapshot();
});
document.getElementById('darkModeToggle').addEventListener('click', () => {
toggleDarkMode();
});
// Handle Window Resize
function onWindowResize() {
const width = container.clientWidth;
const height = container.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener('resize', onWindowResize, false);
// Initialize Visualizer and Renderer
updateVisualizer();
updateZoom();
scene.background = new THREE.Color(guiParams.background);
// Start Animation Loop
animate();
</script>
</body>
</html>
Enhanced Audio Analysis:
beatCutoff). When a beat is detected, visual elements like colors can pulsate or change to match the rhythm.Interactive 3D Controls:
OrbitControls to allow users to interact with the 3D scene. Users can rotate, pan, and zoom the camera using mouse or touch gestures.Additional Visualization Modes:
User Interface Enhancements:
dat.GUI to provide a settings panel where users can adjust parameters like rotation speed, particle size, and color intensity in real-time.Accessibility Improvements:
aria-label attributes to interactive elements to improve accessibility for screen readers.Performance Optimizations:
Feel free to adjust and tailor these enhancements based on your specific requirements and user feedback. This should provide a more advanced and engaging experience for users, especially those seeking colorblind-friendly visualizations.
Not yet included in a published release.
Visualization Enhancements:
Responsive Design: