rubix-cube-solver / index.html
seannyboy's picture
create a rubix cube 3x3 solver website - Initial Deployment
a659e74 verified
Raw History Blame Contribute Delete
30.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3x3 Rubik's Cube Solver</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.cube-face {
width: 100px;
height: 100px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 2px;
padding: 5px;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0,0,0,0.2);
}
.cube-sticker {
border-radius: 3px;
box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
}
.cube-container {
perspective: 1000px;
width: 300px;
height: 300px;
margin: 0 auto;
}
.cube {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 1s;
}
.cube-side {
position: absolute;
width: 100px;
height: 100px;
border: 2px solid #333;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
}
@keyframes rotateAnimation {
0% { transform: rotateX(0) rotateY(0); }
100% { transform: rotateX(360deg) rotateY(360deg); }
}
.animate-rotate {
animation: rotateAnimation 8s infinite linear;
}
.solution-step {
transition: all 0.3s;
}
.solution-step:hover {
transform: scale(1.05);
background-color: #f0f0f0;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-8">
<header class="text-center mb-8">
<h1 class="text-4xl font-bold text-blue-600 mb-2">3x3 Rubik's Cube Solver</h1>
<p class="text-gray-600">Enter your cube configuration and get the solution!</p>
</header>
<div class="flex flex-col lg:flex-row gap-8">
<!-- Cube Input Section -->
<div class="lg:w-1/2 bg-white rounded-lg shadow-lg p-6">
<h2 class="text-2xl font-semibold mb-4 text-blue-600">Cube Configuration</h2>
<div class="grid grid-cols-3 gap-4 mb-6">
<!-- Up Face -->
<div class="flex flex-col items-center">
<label class="text-sm font-medium mb-1">Up (White)</label>
<div class="cube-face bg-gray-200" id="up-face">
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="0" data-col="0"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="0" data-col="1"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="0" data-col="2"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="1" data-col="0"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="1" data-col="1"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="1" data-col="2"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="2" data-col="0"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="2" data-col="1"></div>
<div class="cube-sticker bg-white" data-color="white" data-face="up" data-row="2" data-col="2"></div>
</div>
</div>
<!-- Empty space -->
<div></div>
<!-- Color Picker -->
<div class="flex flex-col">
<label class="text-sm font-medium mb-1">Select Color</label>
<div class="grid grid-cols-3 gap-2">
<button class="w-8 h-8 rounded bg-white border border-gray-300" data-color="white"></button>
<button class="w-8 h-8 rounded bg-yellow-400 border border-gray-300" data-color="yellow"></button>
<button class="w-8 h-8 rounded bg-red-600 border border-gray-300" data-color="red"></button>
<button class="w-8 h-8 rounded bg-blue-600 border border-gray-300" data-color="blue"></button>
<button class="w-8 h-8 rounded bg-green-600 border border-gray-300" data-color="green"></button>
<button class="w-8 h-8 rounded bg-orange-500 border border-gray-300" data-color="orange"></button>
</div>
<div class="mt-4">
<button id="clear-face" class="px-3 py-1 bg-gray-200 rounded text-sm">Clear Face</button>
<button id="clear-all" class="px-3 py-1 bg-gray-200 rounded text-sm ml-2">Clear All</button>
</div>
</div>
</div>
<div class="grid grid-cols-3 gap-4">
<!-- Left Face -->
<div class="flex flex-col items-center">
<label class="text-sm font-medium mb-1">Left (Orange)</label>
<div class="cube-face bg-gray-200" id="left-face">
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="0" data-col="0"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="0" data-col="1"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="0" data-col="2"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="1" data-col="0"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="1" data-col="1"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="1" data-col="2"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="2" data-col="0"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="2" data-col="1"></div>
<div class="cube-sticker bg-orange-500" data-color="orange" data-face="left" data-row="2" data-col="2"></div>
</div>
</div>
<!-- Front Face -->
<div class="flex flex-col items-center">
<label class="text-sm font-medium mb-1">Front (Green)</label>
<div class="cube-face bg-gray-200" id="front-face">
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="0" data-col="0"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="0" data-col="1"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="0" data-col="2"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="1" data-col="0"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="1" data-col="1"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="1" data-col="2"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="2" data-col="0"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="2" data-col="1"></div>
<div class="cube-sticker bg-green-600" data-color="green" data-face="front" data-row="2" data-col="2"></div>
</div>
</div>
<!-- Right Face -->
<div class="flex flex-col items-center">
<label class="text-sm font-medium mb-1">Right (Red)</label>
<div class="cube-face bg-gray-200" id="right-face">
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="0" data-col="0"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="0" data-col="1"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="0" data-col="2"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="1" data-col="0"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="1" data-col="1"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="1" data-col="2"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="2" data-col="0"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="2" data-col="1"></div>
<div class="cube-sticker bg-red-600" data-color="red" data-face="right" data-row="2" data-col="2"></div>
</div>
</div>
</div>
<div class="grid grid-cols-3 gap-4 mt-4">
<!-- Down Face -->
<div class="flex flex-col items-center">
<label class="text-sm font-medium mb-1">Down (Yellow)</label>
<div class="cube-face bg-gray-200" id="down-face">
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="0" data-col="0"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="0" data-col="1"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="0" data-col="2"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="1" data-col="0"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="1" data-col="1"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="1" data-col="2"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="2" data-col="0"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="2" data-col="1"></div>
<div class="cube-sticker bg-yellow-400" data-color="yellow" data-face="down" data-row="2" data-col="2"></div>
</div>
</div>
<!-- Back Face -->
<div class="flex flex-col items-center">
<label class="text-sm font-medium mb-1">Back (Blue)</label>
<div class="cube-face bg-gray-200" id="back-face">
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="0" data-col="0"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="0" data-col="1"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="0" data-col="2"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="1" data-col="0"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="1" data-col="1"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="1" data-col="2"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="2" data-col="0"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="2" data-col="1"></div>
<div class="cube-sticker bg-blue-600" data-color="blue" data-face="back" data-row="2" data-col="2"></div>
</div>
</div>
</div>
<div class="mt-6 flex justify-center">
<button id="solve-btn" class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">
<i class="fas fa-magic mr-2"></i> Solve Cube
</button>
<button id="scramble-btn" class="px-6 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition ml-4">
<i class="fas fa-random mr-2"></i> Scramble
</button>
</div>
</div>
<!-- Solution Section -->
<div class="lg:w-1/2 bg-white rounded-lg shadow-lg p-6">
<h2 class="text-2xl font-semibold mb-4 text-blue-600">Solution</h2>
<div class="cube-container mb-6">
<div class="cube" id="cube-3d">
<div class="cube-side bg-white" style="transform: rotateX(90deg) translateZ(50px);">U</div>
<div class="cube-side bg-yellow-400" style="transform: rotateX(-90deg) translateZ(50px);">D</div>
<div class="cube-side bg-orange-500" style="transform: rotateY(-90deg) translateZ(50px);">L</div>
<div class="cube-side bg-red-600" style="transform: rotateY(90deg) translateZ(50px);">R</div>
<div class="cube-side bg-green-600" style="transform: rotateY(0deg) translateZ(50px);">F</div>
<div class="cube-side bg-blue-600" style="transform: rotateY(180deg) translateZ(50px);">B</div>
</div>
</div>
<div class="flex justify-between mb-4">
<button id="rotate-left" class="px-4 py-2 bg-gray-200 rounded">
<i class="fas fa-undo"></i> Rotate Left
</button>
<button id="toggle-animation" class="px-4 py-2 bg-blue-100 text-blue-600 rounded">
<i class="fas fa-play"></i> Play Animation
</button>
<button id="rotate-right" class="px-4 py-2 bg-gray-200 rounded">
<i class="fas fa-redo"></i> Rotate Right
</button>
</div>
<div class="bg-gray-100 rounded-lg p-4 mb-4">
<div class="flex justify-between items-center mb-2">
<h3 class="font-medium">Solution Steps</h3>
<span id="step-count" class="text-sm text-gray-600">0 moves</span>
</div>
<div id="solution-steps" class="grid grid-cols-4 gap-2">
<!-- Solution steps will appear here -->
</div>
</div>
<div class="bg-blue-50 rounded-lg p-4">
<h3 class="font-medium text-blue-600 mb-2">Solution Details</h3>
<div id="solution-details" class="text-sm text-gray-700">
<p>Enter your cube configuration and click "Solve Cube" to get the solution.</p>
</div>
</div>
</div>
</div>
<!-- Instructions Section -->
<div class="mt-8 bg-white rounded-lg shadow-lg p-6">
<h2 class="text-2xl font-semibold mb-4 text-blue-600">How to Use</h2>
<div class="grid md:grid-cols-3 gap-4">
<div class="bg-gray-50 p-4 rounded-lg">
<h3 class="font-medium mb-2"><i class="fas fa-paint-brush text-blue-500 mr-2"></i> Color Selection</h3>
<p class="text-sm text-gray-600">Click on a color button to select it, then click on any sticker to change its color.</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<h3 class="font-medium mb-2"><i class="fas fa-magic text-blue-500 mr-2"></i> Solving</h3>
<p class="text-sm text-gray-600">After configuring your cube, click "Solve Cube" to generate the solution steps.</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<h3 class="font-medium mb-2"><i class="fas fa-random text-blue-500 mr-2"></i> Scrambling</h3>
<p class="text-sm text-gray-600">Click "Scramble" to generate a random cube configuration to practice with.</p>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Color selection
let selectedColor = 'white';
const colorButtons = document.querySelectorAll('[data-color]');
colorButtons.forEach(button => {
button.addEventListener('click', function() {
selectedColor = this.getAttribute('data-color');
// Highlight selected color
colorButtons.forEach(btn => btn.classList.remove('ring-2', 'ring-blue-500'));
this.classList.add('ring-2', 'ring-blue-500');
});
});
// Sticker click handler
const stickers = document.querySelectorAll('.cube-sticker');
stickers.forEach(sticker => {
sticker.addEventListener('click', function() {
const face = this.getAttribute('data-face');
const colorClass = {
'white': 'bg-white',
'yellow': 'bg-yellow-400',
'red': 'bg-red-600',
'blue': 'bg-blue-600',
'green': 'bg-green-600',
'orange': 'bg-orange-500'
}[selectedColor];
// Remove all color classes
this.classList.remove('bg-white', 'bg-yellow-400', 'bg-red-600', 'bg-blue-600', 'bg-green-600', 'bg-orange-500');
// Add selected color class
this.classList.add(colorClass);
this.setAttribute('data-color', selectedColor);
// Update 3D cube visualization
update3DCube();
});
});
// Clear buttons
document.getElementById('clear-face').addEventListener('click', function() {
const activeFace = document.querySelector('.cube-face:hover');
if (activeFace) {
const stickers = activeFace.querySelectorAll('.cube-sticker');
stickers.forEach(sticker => {
sticker.classList.remove('bg-white', 'bg-yellow-400', 'bg-red-600', 'bg-blue-600', 'bg-green-600', 'bg-orange-500');
sticker.classList.add('bg-gray-200');
sticker.setAttribute('data-color', '');
});
}
update3DCube();
});
document.getElementById('clear-all').addEventListener('click', function() {
const stickers = document.querySelectorAll('.cube-sticker');
stickers.forEach(sticker => {
sticker.classList.remove('bg-white', 'bg-yellow-400', 'bg-red-600', 'bg-blue-600', 'bg-green-600', 'bg-orange-500');
sticker.classList.add('bg-gray-200');
sticker.setAttribute('data-color', '');
});
update3DCube();
document.getElementById('solution-steps').innerHTML = '';
document.getElementById('solution-details').innerHTML =
'<p>Enter your cube configuration and click "Solve Cube" to get the solution.</p>';
document.getElementById('step-count').textContent = '0 moves';
});
// Solve button
document.getElementById('solve-btn').addEventListener('click', function() {
// In a real app, this would send the cube state to a solver algorithm
// For this demo, we'll simulate a solution
// Check if all stickers have colors
let isValid = true;
document.querySelectorAll('.cube-sticker').forEach(sticker => {
if (!sticker.getAttribute('data-color')) {
isValid = false;
}
});
if (!isValid) {
document.getElementById('solution-details').innerHTML =
'<p class="text-red-500">Please fill in all stickers with colors before solving.</p>';
return;
}
// Simulate solving
document.getElementById('solution-details').innerHTML =
'<p class="text-green-600"><i class="fas fa-check-circle mr-2"></i> Cube configuration valid. Solving...</p>';
// Generate random solution steps for demo
const moves = ["U", "U'", "D", "D'", "L", "L'", "R", "R'", "F", "F'", "B", "B'"];
const solutionSteps = [];
const stepCount = Math.floor(Math.random() * 10) + 15; // 15-25 moves
for (let i = 0; i < stepCount; i++) {
const randomMove = moves[Math.floor(Math.random() * moves.length)];
solutionSteps.push(randomMove);
}
// Display solution
const solutionContainer = document.getElementById('solution-steps');
solutionContainer.innerHTML = '';
solutionSteps.forEach((step, index) => {
const stepElement = document.createElement('div');
stepElement.className = 'solution-step bg-white p-2 rounded text-center font-mono cursor-pointer hover:bg-blue-100';
stepElement.textContent = step;
stepElement.addEventListener('click', function() {
// Highlight the step
document.querySelectorAll('.solution-step').forEach(el => {
el.classList.remove('bg-blue-100', 'text-blue-600');
});
this.classList.add('bg-blue-100', 'text-blue-600');
// Show explanation (simulated)
document.getElementById('solution-details').innerHTML = `
<p><strong>Step ${index + 1}:</strong> ${step}</p>
<p class="mt-2">This move ${step.includes("'") ? 'counter-' : ''}rotates the ${step[0]} face ${step.includes("'") ? 'counter-clockwise' : 'clockwise'}.</p>
`;
});
solutionContainer.appendChild(stepElement);
});
document.getElementById('step-count').textContent = `${stepCount} moves`;
// After a delay, show completion message
setTimeout(() => {
document.getElementById('solution-details').innerHTML = `
<p class="text-green-600"><i class="fas fa-check-circle mr-2"></i> Solution found!</p>
<p class="mt-2">Follow the steps above to solve your cube. Click on any step for more details.</p>
<p class="mt-2 text-sm">Note: This is a demo. A real solver would use algorithms like CFOP or Roux.</p>
`;
}, 1500);
});
// Scramble button
document.getElementById('scramble-btn').addEventListener('click', function() {
const colors = ['white', 'yellow', 'red', 'blue', 'green', 'orange'];
const stickers = document.querySelectorAll('.cube-sticker');
stickers.forEach(sticker => {
const randomColor = colors[Math.floor(Math.random() * colors.length)];
const colorClass = {
'white': 'bg-white',
'yellow': 'bg-yellow-400',
'red': 'bg-red-600',
'blue': 'bg-blue-600',
'green': 'bg-green-600',
'orange': 'bg-orange-500'
}[randomColor];
// Remove all color classes
sticker.classList.remove('bg-white', 'bg-yellow-400', 'bg-red-600', 'bg-blue-600', 'bg-green-600', 'bg-orange-500');
// Add random color class
sticker.classList.add(colorClass);
sticker.setAttribute('data-color', randomColor);
});
update3DCube();
document.getElementById('solution-steps').innerHTML = '';
document.getElementById('solution-details').innerHTML =
'<p class="text-blue-600"><i class="fas fa-info-circle mr-2"></i> Cube scrambled! Click "Solve Cube" to get the solution.</p>';
document.getElementById('step-count').textContent = '0 moves';
});
// 3D Cube Controls
const cube3D = document.getElementById('cube-3d');
let rotateX = 0;
let rotateY = 0;
let isAnimating = false;
document.getElementById('rotate-left').addEventListener('click', function() {
rotateY -= 90;
updateCubeRotation();
});
document.getElementById('rotate-right').addEventListener('click', function() {
rotateY += 90;
updateCubeRotation();
});
document.getElementById('toggle-animation').addEventListener('click', function() {
isAnimating = !isAnimating;
if (isAnimating) {
cube3D.classList.add('animate-rotate');
this.innerHTML = '<i class="fas fa-pause mr-2"></i> Pause Animation';
this.classList.remove('bg-blue-100', 'text-blue-600');
this.classList.add('bg-blue-600', 'text-white');
} else {
cube3D.classList.remove('animate-rotate');
this.innerHTML = '<i class="fas fa-play mr-2"></i> Play Animation';
this.classList.remove('bg-blue-600', 'text-white');
this.classList.add('bg-blue-100', 'text-blue-600');
}
});
function updateCubeRotation() {
if (isAnimating) {
isAnimating = false;
cube3D.classList.remove('animate-rotate');
document.getElementById('toggle-animation').innerHTML = '<i class="fas fa-play mr-2"></i> Play Animation';
document.getElementById('toggle-animation').classList.remove('bg-blue-600', 'text-white');
document.getElementById('toggle-animation').classList.add('bg-blue-100', 'text-blue-600');
}
cube3D.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
}
// Update 3D cube visualization based on 2D input
function update3DCube() {
// In a real app, this would update the 3D cube visualization
// For this demo, we'll just rotate it slightly to show it's updating
rotateX = 20;
rotateY = -30;
updateCubeRotation();
}
// Initialize
colorButtons[0].classList.add('ring-2', 'ring-blue-500');
updateCubeRotation();
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=seannyboy/rubix-cube-solver" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>