File size: 6,488 Bytes
8b1d6da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!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>