VisionART / index.html
kolaslab's picture
Update index.html
8b1d6da verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Art Generator</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #0f0f1a;
color: #fff;
font-family: 'Segoe UI', sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 2rem;
}
.container {
max-width: 1200px;
width: 100%;
}
.camera-container {
position: relative;
width: 640px;
height: 480px;
margin: 2rem auto;
border-radius: 15px;
overflow: hidden;
box-shadow: 0 0 20px rgba(0,0,255,0.3);
}
#video {
width: 100%;
height: 100%;
object-fit: cover;
transform: scaleX(-1);
}
#canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
mix-blend-mode: difference;
}
.controls {
display: flex;
gap: 1rem;
justify-content: center;
margin: 2rem 0;
}
button {
background: #4a4af0;
color: white;
border: none;
padding: 1rem 2rem;
border-radius: 25px;
cursor: pointer;
font-size: 1rem;
transition: all 0.3s ease;
}
button:hover {
background: #2a2ad0;
transform: translateY(-2px);
}
.art-gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 2rem;
margin-top: 3rem;
}
.art-piece {
position: relative;
border-radius: 10px;
overflow: hidden;
transition: transform 0.3s ease;
}
.art-piece:hover {
transform: scale(1.05);
}
.art-piece canvas {
width: 100%;
height: 300px;
object-fit: cover;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.generating {
animation: pulse 2s infinite;
}
</style>
</head>
<body>
<div class="container">
<div class="camera-container">
<video id="video" autoplay></video>
<canvas id="canvas"></canvas>
</div>
<div class="controls">
<button id="generateBtn">Generate Art</button>
<button id="saveBtn">Save Artwork</button>
</div>
<div class="art-gallery" id="artGallery"></div>
</div>
<script>
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const generateBtn = document.getElementById('generateBtn');
const saveBtn = document.getElementById('saveBtn');
const artGallery = document.getElementById('artGallery');
// Set canvas dimensions
canvas.width = 640;
canvas.height = 480;
// Access webcam
async function initCamera() {
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
video.srcObject = stream;
} catch (err) {
console.error('Error accessing camera:', err);
}
}
// Boltzmann machine simulation (simplified)
function boltzmannGeneration(imageData) {
const data = imageData.data;
for (let i = 0; i < data.length; i += 4) {
// Add random noise and artistic effects
const noise = Math.random() * 50 - 25;
data[i] = Math.min(255, Math.max(0, data[i] + noise)); // Red
data[i + 1] = Math.min(255, Math.max(0, data[i + 1] + noise)); // Green
data[i + 2] = Math.min(255, Math.max(0, data[i + 2] + noise)); // Blue
// Add some artistic patterns
if (Math.random() > 0.99) {
data[i] = 255 - data[i];
data[i + 1] = 255 - data[i + 1];
data[i + 2] = 255 - data[i + 2];
}
}
return imageData;
}
function generateArt() {
generateBtn.classList.add('generating');
// Capture video frame
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
// Get image data and apply Boltzmann machine effects
let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
imageData = boltzmannGeneration(imageData);
// Apply additional artistic effects
ctx.putImageData(imageData, 0, 0);
ctx.globalCompositeOperation = 'overlay';
ctx.fillStyle = `hsla(${Math.random() * 360}, 50%, 50%, 0.3)`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
generateBtn.classList.remove('generating');
}
function saveArtwork() {
const artPiece = document.createElement('div');
artPiece.className = 'art-piece';
const artCanvas = document.createElement('canvas');
artCanvas.width = canvas.width;
artCanvas.height = canvas.height;
const artCtx = artCanvas.getContext('2d');
artCtx.drawImage(canvas, 0, 0);
artPiece.appendChild(artCanvas);
artGallery.insertBefore(artPiece, artGallery.firstChild);
}
// Event listeners
generateBtn.addEventListener('click', generateArt);
saveBtn.addEventListener('click', saveArtwork);
// Start camera
initCamera();
// Continuous drawing
function draw() {
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
</script>
</body>
</html>