-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SequenceSynthesizer.html
276 lines (238 loc) · 10.8 KB
/
SequenceSynthesizer.html
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visual Sequence Synthesizer</title>
<script src="https://cdn.tailwindcss.com"></script>
<!-- Removed Lucide icons as they are not used in this script -->
<style>
/* Additional CSS if needed */
</style>
</head>
<body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen flex items-center justify-center p-6">
<div class="bg-white shadow-xl rounded-lg p-6 w-full max-w-2xl">
<h1 class="text-3xl font-bold mb-4 text-center text-indigo-700">
Visual Sequence Synthesizer
</h1>
<div class="flex space-x-4 mb-4">
<input
type="text"
id="promptInput"
placeholder="Enter a creative prompt"
class="flex-grow p-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500"
/>
<button
id="generateBtn"
class="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700 disabled:opacity-50"
>
Synthesize
</button>
</div>
<div id="styleInfo" class="mb-4 text-sm text-gray-600 hidden">
Style: <span id="styleText"></span>
</div>
<canvas
id="visualCanvas"
class="w-full h-96 bg-gray-100 rounded-lg shadow-md"
></canvas>
<div class="mt-4 flex space-x-4 justify-center">
<button
id="downloadPngBtn"
class="flex items-center bg-green-500 text-white px-4 py-2 rounded-md hover:bg-green-600"
>
PNG
</button>
<button
id="downloadJpegBtn"
class="flex items-center bg-blue-500 text-white px-4 py-2 rounded-md hover:bg-blue-600"
>
JPEG
</button>
</div>
</div>
<script>
// Advanced Sequence Generation Framework
class VisualSequenceSynthesizer {
static STYLE_MAPPINGS = {
nature: {
keywords: ['meadow', 'forest', 'landscape', 'green', 'organic'],
characteristics: {
palette: ['#2ecc71', '#27ae60', '#3498db', '#1abc9c'],
shapes: ['organic', 'flowing', 'fractal'],
animations: ['grow', 'pulse', 'wave']
}
},
urban: {
keywords: ['city', 'architecture', 'metropolitan', 'geometric'],
characteristics: {
palette: ['#34495e', '#2c3e50', '#7f8c8d', '#95a5a6'],
shapes: ['angular', 'grid', 'modular'],
animations: ['grid-shift', 'deconstruct', 'scroll']
}
},
cosmic: {
keywords: ['space', 'galaxy', 'universe', 'stellar'],
characteristics: {
palette: ['#9b59b6', '#8e44ad', '#2980b9', '#3498db'],
shapes: ['spiral', 'radial', 'fractal'],
animations: ['swirl', 'expand', 'nebula-pulse']
}
}
};
static analyzePrompt(prompt) {
const words = prompt.toLowerCase().split(/\s+/);
const styleScores = {};
Object.entries(this.STYLE_MAPPINGS).forEach(([styleName, styleData]) => {
const matchScore = styleData.keywords.reduce((score, keyword) => {
return words.includes(keyword) ? score + 1 : score;
}, 0);
if (matchScore > 0) {
styleScores[styleName] = {
score: matchScore,
style: styleData.characteristics
};
}
});
return Object.keys(styleScores).length > 0
? Object.entries(styleScores).reduce((a, b) => a[1].score > b[1].score ? a : b)[1].style
: this.getDefaultStyle();
}
static getDefaultStyle() {
return {
palette: ['#3498db', '#2ecc71', '#e74c3c'],
shapes: ['organic', 'geometric', 'random'],
animations: ['pulse', 'rotate', 'wave']
};
}
static generateFrameSequence(prompt, style, frameCount = 12) {
const frames = [];
const seed = prompt.split('').reduce((hash, char) => hash + char.charCodeAt(0), 0);
for (let i = 0; i < frameCount; i++) {
frames.push({
render: (ctx) => {
const width = ctx.canvas.width;
const height = ctx.canvas.height;
const gradient = ctx.createRadialGradient(
width / 2, height / 2, 0,
width / 2, height / 2, Math.max(width, height)
);
const palette = style.palette;
gradient.addColorStop(0, palette[i % palette.length]);
gradient.addColorStop(1, palette[(i + 1) % palette.length]);
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, width, height);
this.renderDynamicShape(ctx, style.shapes[i % style.shapes.length], i);
ctx.fillStyle = 'rgba(255,255,255,0.7)';
ctx.font = '16px monospace';
ctx.textAlign = 'center';
ctx.fillText(
`${prompt.slice(0, 20)}${prompt.length > 20 ? '...' : ''}`,
width / 2,
height - 20
);
}
});
}
return frames;
}
static renderDynamicShape(ctx, shapeType, iteration) {
const width = ctx.canvas.width;
const height = ctx.canvas.height;
const centerX = width / 2;
const centerY = height / 2;
ctx.save();
ctx.translate(centerX, centerY);
ctx.rotate(iteration * 0.1);
switch (shapeType) {
case 'organic':
ctx.beginPath();
ctx.moveTo(0, 0);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const radius = 100 + Math.sin(iteration + angle) * 50;
ctx.lineTo(
Math.cos(angle) * radius,
Math.sin(angle) * radius
);
}
ctx.closePath();
ctx.fillStyle = 'rgba(255,255,255,0.2)';
ctx.fill();
break;
case 'geometric':
ctx.beginPath();
ctx.rect(-50, -50, 100, 100);
ctx.fillStyle = 'rgba(255,255,255,0.1)';
ctx.fill();
break;
default:
ctx.beginPath();
ctx.arc(0, 0, 75, 0, Math.PI * 2);
ctx.fillStyle = 'rgba(255,255,255,0.15)';
ctx.fill();
}
ctx.restore();
}
}
// Application Logic
class VisualSequenceSynthesizerApp {
constructor() {
this.promptInput = document.getElementById('promptInput');
this.generateBtn = document.getElementById('generateBtn');
this.canvas = document.getElementById('visualCanvas');
this.ctx = this.canvas.getContext('2d');
this.styleInfo = document.getElementById('styleInfo');
this.styleText = document.getElementById('styleText');
this.downloadPngBtn = document.getElementById('downloadPngBtn');
this.downloadJpegBtn = document.getElementById('downloadJpegBtn');
this.animationFrame = null;
this.setupEventListeners();
}
setupEventListeners() {
this.generateBtn.addEventListener('click', () => this.handleGenerate());
this.downloadPngBtn.addEventListener('click', () => this.handleDownload('png'));
this.downloadJpegBtn.addEventListener('click', () => this.handleDownload('jpeg'));
}
handleGenerate() {
const prompt = this.promptInput.value.trim();
if (!prompt) {
alert('Please enter a creative prompt');
return;
}
if (this.animationFrame) {
cancelAnimationFrame(this.animationFrame);
}
this.canvas.width = 600;
this.canvas.height = 400;
const detectedStyle = VisualSequenceSynthesizer.analyzePrompt(prompt);
this.updateStyleDisplay(detectedStyle);
const frames = VisualSequenceSynthesizer.generateFrameSequence(prompt, detectedStyle);
let currentFrame = 0;
const animate = () => {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
frames[currentFrame].render(this.ctx);
currentFrame = (currentFrame + 1) % frames.length;
this.animationFrame = requestAnimationFrame(animate);
};
animate();
}
updateStyleDisplay(style) {
const styleName = Object.keys(VisualSequenceSynthesizer.STYLE_MAPPINGS)
.find(key => VisualSequenceSynthesizer.STYLE_MAPPINGS[key].characteristics === style) || 'Custom';
this.styleText.textContent = styleName;
this.styleInfo.classList.remove('hidden');
}
handleDownload(type = 'png') {
const link = document.createElement('a');
link.download = `visual-sequence.${type}`;
link.href = this.canvas.toDataURL(`image/${type}`);
link.click();
}
}
document.addEventListener('DOMContentLoaded', () => {
new VisualSequenceSynthesizerApp();
});
</script>
</body>
</html>