-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter-showcase.html
More file actions
820 lines (697 loc) · 27.5 KB
/
Copy pathcharacter-showcase.html
File metadata and controls
820 lines (697 loc) · 27.5 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Character Animation Showcase</title>
<style>
body {
font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
background-color: #2D3748;
color: #E2E8F0;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
margin-bottom: 10px;
color: #63B3ED;
}
.subtitle {
text-align: center;
margin-bottom: 30px;
color: #A0AEC0;
font-size: 16px;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
max-width: 1000px;
margin: 0 auto;
}
.main-canvas-container {
background-color: #4A5568;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 600px;
}
#main-canvas {
background-color: #718096;
border-radius: 4px;
width: 100%;
height: 300px;
}
.controls {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 15px;
margin-top: 20px;
width: 100%;
}
.control-button {
background-color: #2D3748;
color: #E2E8F0;
border: 2px solid #63B3ED;
border-radius: 4px;
padding: 10px 15px;
font-family: inherit;
font-size: 14px;
cursor: pointer;
transition: all 0.3s ease;
}
.control-button:hover {
background-color: #63B3ED;
color: #1A202C;
}
.control-button.active {
background-color: #63B3ED;
color: #1A202C;
}
.animation-grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 15px;
margin-top: 30px;
width: 100%;
}
.animation-card {
background-color: #4A5568;
border-radius: 8px;
padding: 15px;
width: 150px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
transition: transform 0.3s ease;
}
.animation-card:hover {
transform: translateY(-5px);
}
.animation-card.active {
border: 2px solid #63B3ED;
}
.animation-title {
font-size: 16px;
margin-bottom: 10px;
text-align: center;
}
.mini-canvas {
background-color: #718096;
border-radius: 4px;
width: 120px;
height: 120px;
}
.options-panel {
background-color: #4A5568;
border-radius: 8px;
padding: 15px;
margin-top: 20px;
width: 100%;
max-width: 600px;
}
.option-group {
margin-bottom: 15px;
}
.option-label {
display: block;
margin-bottom: 5px;
font-size: 14px;
}
.slider-container {
display: flex;
align-items: center;
gap: 10px;
}
input[type="range"] {
flex-grow: 1;
}
.value-display {
width: 40px;
text-align: center;
font-size: 14px;
}
.checkbox-container {
display: flex;
align-items: center;
gap: 10px;
}
.color-picker-container {
display: flex;
align-items: center;
gap: 10px;
}
input[type="color"] {
border: none;
width: 30px;
height: 30px;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Interactive Character Showcase</h1>
<div class="subtitle">Explore character animations</div>
<div class="container">
<div class="main-canvas-container">
<canvas id="main-canvas"></canvas>
<div class="controls">
<button class="control-button active" data-phase="waiting">Waiting</button>
<button class="control-button" data-phase="coding">Coding</button>
<button class="control-button" data-phase="deploying">Deploying</button>
<button class="control-button" data-phase="running">Running</button>
<button class="control-button" data-phase="crashing">Crashing</button>
<button class="control-button" id="play-all-btn">Play All</button>
</div>
</div>
<div class="options-panel">
<div class="option-group">
<label class="option-label">Scale</label>
<div class="slider-container">
<input type="range" id="scale-slider" min="0.5" max="5" step="0.1" value="3">
<span class="value-display" id="scale-value">3.0</span>
</div>
</div>
<div class="option-group">
<label class="option-label">Background Color</label>
<div class="color-picker-container">
<input type="color" id="bg-color-picker" value="#718096">
<span id="bg-color-value">#718096</span>
</div>
</div>
<div class="option-group">
<div class="checkbox-container">
<input type="checkbox" id="show-grid-checkbox">
<label for="show-grid-checkbox">Show Grid</label>
</div>
</div>
</div>
<div class="animation-grid">
<div class="animation-card active" data-phase="waiting">
<div class="animation-title">Waiting</div>
<canvas class="mini-canvas" id="mini-waiting-canvas" width="120" height="120"></canvas>
</div>
<div class="animation-card" data-phase="coding">
<div class="animation-title">Coding</div>
<canvas class="mini-canvas" id="mini-coding-canvas" width="120" height="120"></canvas>
</div>
<div class="animation-card" data-phase="deploying">
<div class="animation-title">Deploying</div>
<canvas class="mini-canvas" id="mini-deploying-canvas" width="120" height="120"></canvas>
</div>
<div class="animation-card" data-phase="running">
<div class="animation-title">Running</div>
<canvas class="mini-canvas" id="mini-running-canvas" width="120" height="120"></canvas>
</div>
<div class="animation-card" data-phase="crashing">
<div class="animation-title">Crashing</div>
<canvas class="mini-canvas" id="mini-crashing-canvas" width="120" height="120"></canvas>
</div>
</div>
</div>
<script src="./js/character-reference.js"></script>
<script>
// Main canvas setup
const mainCanvas = document.getElementById('main-canvas');
const mainCtx = mainCanvas.getContext('2d');
// Set canvas dimensions based on its display size
function resizeMainCanvas() {
const displayWidth = mainCanvas.clientWidth;
const displayHeight = mainCanvas.clientHeight;
if (mainCanvas.width !== displayWidth || mainCanvas.height !== displayHeight) {
mainCanvas.width = displayWidth;
mainCanvas.height = displayHeight;
}
}
// Call once to set initial size
resizeMainCanvas();
// Call again if window is resized
window.addEventListener('resize', resizeMainCanvas);
// Mini canvases setup
const miniCanvasIds = [
'mini-waiting-canvas',
'mini-coding-canvas',
'mini-deploying-canvas',
'mini-running-canvas',
'mini-crashing-canvas'
];
const phases = ['waiting', 'coding', 'deploying', 'running', 'crashing'];
const miniCanvasContexts = [];
// Set up each mini canvas
miniCanvasIds.forEach((id, index) => {
const canvas = document.getElementById(id);
const ctx = canvas.getContext('2d');
miniCanvasContexts.push({
ctx: ctx,
phase: phases[index]
});
});
// Animation state
let currentPhase = 'waiting';
let scale = 3.0;
let bgColor = '#718096';
let showGrid = false;
let playAllMode = false;
let playAllIndex = 0;
let playAllTimer = null;
// Custom blink animation implementation
let customBlinkState = 'open'; // 'open', 'closing', 'closed', 'opening'
let customBlinkTimer = 0;
let lastCustomBlinkTime = Date.now();
let customBlinkDuration = 600; // Duration of a complete blink in ms
let timeBetweenCustomBlinks = 3000; // Time between blinks in ms
// Control buttons
const controlButtons = document.querySelectorAll('.control-button[data-phase]');
controlButtons.forEach(button => {
button.addEventListener('click', () => {
// Stop play all mode if active
if (playAllMode) {
stopPlayAll();
}
// Update active button
controlButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
// Update current phase
currentPhase = button.getAttribute('data-phase');
// Update active animation card
updateActiveAnimationCard();
});
});
// Animation cards
const animationCards = document.querySelectorAll('.animation-card');
animationCards.forEach(card => {
card.addEventListener('click', () => {
// Stop play all mode if active
if (playAllMode) {
stopPlayAll();
}
// Update active card
animationCards.forEach(c => c.classList.remove('active'));
card.classList.add('active');
// Update current phase
currentPhase = card.getAttribute('data-phase');
// Update active control button
updateActiveControlButton();
});
});
// Play All button
const playAllBtn = document.getElementById('play-all-btn');
playAllBtn.addEventListener('click', togglePlayAll);
function togglePlayAll() {
if (playAllMode) {
stopPlayAll();
} else {
startPlayAll();
}
}
function startPlayAll() {
playAllMode = true;
playAllBtn.textContent = 'Stop';
playAllBtn.classList.add('active');
// Start from the first phase
playAllIndex = 0;
currentPhase = phases[playAllIndex];
// Update UI
updateActiveControlButton();
updateActiveAnimationCard();
// Set timer to cycle through phases
playAllTimer = setInterval(() => {
playAllIndex = (playAllIndex + 1) % phases.length;
currentPhase = phases[playAllIndex];
// Update UI
updateActiveControlButton();
updateActiveAnimationCard();
}, 2000); // Change every 2 seconds
}
function stopPlayAll() {
playAllMode = false;
playAllBtn.textContent = 'Play All';
playAllBtn.classList.remove('active');
if (playAllTimer) {
clearInterval(playAllTimer);
playAllTimer = null;
}
}
function updateActiveControlButton() {
controlButtons.forEach(btn => {
if (btn.getAttribute('data-phase') === currentPhase) {
btn.classList.add('active');
} else {
btn.classList.remove('active');
}
});
}
function updateActiveAnimationCard() {
animationCards.forEach(card => {
if (card.getAttribute('data-phase') === currentPhase) {
card.classList.add('active');
} else {
card.classList.remove('active');
}
});
}
// Options panel controls
const scaleSlider = document.getElementById('scale-slider');
const scaleValue = document.getElementById('scale-value');
scaleSlider.addEventListener('input', () => {
scale = parseFloat(scaleSlider.value);
scaleValue.textContent = scale.toFixed(1);
});
const bgColorPicker = document.getElementById('bg-color-picker');
const bgColorValue = document.getElementById('bg-color-value');
bgColorPicker.addEventListener('input', () => {
bgColor = bgColorPicker.value;
bgColorValue.textContent = bgColor;
});
const showGridCheckbox = document.getElementById('show-grid-checkbox');
showGridCheckbox.addEventListener('change', () => {
showGrid = showGridCheckbox.checked;
});
// Draw grid on canvas
function drawGrid(ctx, width, height, cellSize = 10) {
ctx.save();
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
ctx.lineWidth = 0.5;
// Draw vertical lines
for (let x = 0; x <= width; x += cellSize) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, height);
ctx.stroke();
}
// Draw horizontal lines
for (let y = 0; y <= height; y += cellSize) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
// Draw center lines
ctx.strokeStyle = 'rgba(255, 255, 255, 0.3)';
ctx.lineWidth = 1;
// Vertical center line
ctx.beginPath();
ctx.moveTo(width / 2, 0);
ctx.lineTo(width / 2, height);
ctx.stroke();
// Horizontal center line
ctx.beginPath();
ctx.moveTo(0, height / 2);
ctx.lineTo(width, height / 2);
ctx.stroke();
ctx.restore();
}
// Custom function to update blink state
function updateCustomBlinkState() {
const currentTime = Date.now();
// Only update blink state for waiting phase
if (currentPhase !== 'waiting') {
customBlinkState = 'open';
customBlinkTimer = 0;
return;
}
// Check if it's time to start a new blink
if (customBlinkState === 'open' && currentTime - lastCustomBlinkTime > timeBetweenCustomBlinks) {
customBlinkState = 'closing';
customBlinkTimer = 0;
return;
}
// Update ongoing blink animation
if (customBlinkState !== 'open') {
// Use a fixed time step for more consistent animation
const timeStep = 16; // 16ms is approximately 60fps
customBlinkTimer += timeStep;
const closingThreshold = customBlinkDuration / 3;
const closedDuration = customBlinkDuration / 4;
const openingThreshold = customBlinkDuration / 3;
if (customBlinkState === 'closing' && customBlinkTimer >= closingThreshold) {
// Eyes closed
customBlinkState = 'closed';
customBlinkTimer = 0;
} else if (customBlinkState === 'closed' && customBlinkTimer >= closedDuration) {
// Start opening eyes
customBlinkState = 'opening';
customBlinkTimer = 0;
} else if (customBlinkState === 'opening' && customBlinkTimer >= openingThreshold) {
// Eyes fully open
customBlinkState = 'open';
customBlinkTimer = 0;
lastCustomBlinkTime = currentTime;
}
}
}
// Custom function to draw eyes with blinking
function drawCustomEyes(ctx) {
ctx.fillStyle = "white";
// Default eye size
let eyeHeight = 3;
let eyeWidth = 3;
// Calculate eye height based on blink state
if (customBlinkState === 'closing') {
// Gradually close eyes
const progress = customBlinkTimer / (customBlinkDuration / 3);
eyeHeight = 3 * (1 - progress);
// Slightly widen eyes as they close for cartoon effect
eyeWidth = 3 + progress * 0.7;
} else if (customBlinkState === 'closed') {
// Eyes almost closed
eyeHeight = 0.2;
eyeWidth = 3.7;
} else if (customBlinkState === 'opening') {
// Gradually open eyes
const progress = customBlinkTimer / (customBlinkDuration / 3);
eyeHeight = 0.2 + (3 - 0.2) * progress;
// Return to normal width
eyeWidth = 3.7 - progress * 0.7;
}
// Draw right eye
ctx.beginPath();
if (eyeHeight < 3) {
// Draw as ellipse when blinking
ctx.ellipse(3, -7, eyeWidth, eyeHeight, 0, 0, Math.PI * 2);
} else {
// Draw as circle when fully open
ctx.arc(3, -7, 3, 0, Math.PI * 2, false);
}
ctx.fill();
// Draw left eye
ctx.beginPath();
if (eyeHeight < 3) {
// Draw as ellipse when blinking
ctx.ellipse(-3, -7, eyeWidth, eyeHeight, 0, 0, Math.PI * 2);
} else {
// Draw as circle when fully open
ctx.arc(-3, -7, 3, 0, Math.PI * 2, false);
}
ctx.fill();
}
// Custom function to draw character base with custom eyes
function drawCustomCharacterBase(ctx) {
// Body
ctx.fillStyle = "black";
drawRoundedRect(
ctx,
-8.5,
-15,
17,
26,
5
);
// Legs
const legDistance = 5;
ctx.beginPath();
ctx.arc(legDistance, 11.5, 3, 0, Math.PI * 2, false);
ctx.fill();
ctx.beginPath();
ctx.arc(-legDistance, 11.5, 3, 0, Math.PI * 2, false);
ctx.fill();
// Draw custom eyes with blinking
drawCustomEyes(ctx);
// Glasses frame
ctx.strokeStyle = "#333";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.arc(3, -7, 3.5, 0, Math.PI * 2, false);
ctx.stroke();
ctx.beginPath();
ctx.arc(-3, -7, 3.5, 0, Math.PI * 2, false);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, -7);
ctx.lineTo(-3, -7);
ctx.moveTo(0, -7);
ctx.lineTo(3, -7);
ctx.stroke();
}
// Custom function to draw waiting state
function drawCustomWaitingState(ctx) {
// Draw character base with custom eyes
drawCustomCharacterBase(ctx);
// Left hand holding laptop
ctx.fillStyle = "black";
ctx.beginPath();
ctx.arc(-8, 5, 2.5, 0, Math.PI * 2, false); // left hand
ctx.fill();
// Folded laptop
const laptopWidth = 10;
const laptopHeight = 7;
// Laptop base (bottom part)
ctx.fillStyle = "#4A5568"; // Dark gray
ctx.fillRect(-13, 5, laptopWidth, laptopHeight / 2);
// Laptop screen (top part)
ctx.fillStyle = "#2D3748"; // Darker gray
ctx.fillRect(-13, 5 - laptopHeight / 2, laptopWidth, laptopHeight / 2);
// Screen inner part
ctx.fillStyle = "#1A202C"; // Almost black
ctx.fillRect(
-12,
5 - laptopHeight / 2 + 1,
laptopWidth - 2,
laptopHeight / 2 - 2
);
// Laptop logo
ctx.fillStyle = "#63B3ED"; // Light blue
ctx.beginPath();
ctx.arc(-8, 5 - laptopHeight / 4, 1, 0, Math.PI * 2, false);
ctx.fill();
}
// Helper function to draw a rounded rectangle
function drawRoundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
ctx.fill();
}
// Trigger a custom blink
function triggerCustomBlink() {
customBlinkState = 'closing';
customBlinkTimer = 0;
}
// Main animation function
function animate() {
// Get current time for animation timing
const currentTime = Date.now();
// Set documentation mode on first animation frame
if (!window.documentationModeSet) {
CharacterReference.setDocumentationMode(true);
window.documentationModeSet = true;
}
// Clear main canvas
mainCtx.fillStyle = bgColor;
mainCtx.fillRect(0, 0, mainCanvas.width, mainCanvas.height);
// Draw grid if enabled
if (showGrid) {
drawGrid(mainCtx, mainCanvas.width, mainCanvas.height);
}
// Draw platform on main canvas
const platformHeight = 50;
mainCtx.fillStyle = "#2D3748";
mainCtx.fillRect(0, mainCanvas.height - platformHeight, mainCanvas.width, platformHeight);
// Update custom blink state
updateCustomBlinkState();
// Draw character on main canvas with scaling
// Create an offscreen canvas to draw the character at normal scale
const offscreenCanvas = document.createElement('canvas');
const offscreenCtx = offscreenCanvas.getContext('2d', { alpha: true });
// Make the offscreen canvas large enough
// Using a higher resolution for better scaling quality
const resolutionMultiplier = 5; // Higher resolution for better quality
offscreenCanvas.width = 100 * resolutionMultiplier;
offscreenCanvas.height = 100 * resolutionMultiplier;
// Clear the offscreen canvas with a transparent background
offscreenCtx.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
// Draw a platform on the offscreen canvas
const offscreenPlatformHeight = 20 * resolutionMultiplier;
offscreenCtx.fillStyle = "#2D3748";
offscreenCtx.fillRect(0, offscreenCanvas.height - offscreenPlatformHeight, offscreenCanvas.width, offscreenPlatformHeight);
// Draw the character centered on the offscreen canvas
// Scale up the drawing for higher resolution
offscreenCtx.save();
offscreenCtx.scale(resolutionMultiplier, resolutionMultiplier);
// Use custom drawing for waiting state with blinking
if (currentPhase === 'waiting') {
offscreenCtx.translate(
offscreenCanvas.width / (2 * resolutionMultiplier),
offscreenCanvas.height / resolutionMultiplier - offscreenPlatformHeight / resolutionMultiplier - 15
);
drawCustomWaitingState(offscreenCtx);
} else {
// Use the library's drawing for other states
CharacterReference.drawCharacter(
offscreenCtx,
currentPhase,
offscreenCanvas.width / (2 * resolutionMultiplier) + 8.5,
0,
offscreenCanvas.height / resolutionMultiplier,
offscreenPlatformHeight / resolutionMultiplier
);
}
offscreenCtx.restore();
// Now draw the scaled offscreen canvas to the main canvas
const scaledWidth = (offscreenCanvas.width / resolutionMultiplier) * scale;
const scaledHeight = (offscreenCanvas.height / resolutionMultiplier) * scale;
// Position so the character is centered horizontally
const destX = mainCanvas.width / 2 - scaledWidth / 2;
// Position so the bottom of the scaled canvas aligns with the platform
const destY = mainCanvas.height - platformHeight - scaledHeight + (offscreenPlatformHeight / resolutionMultiplier) * scale;
// Enable image smoothing for better quality
mainCtx.imageSmoothingEnabled = true;
mainCtx.imageSmoothingQuality = 'high';
mainCtx.drawImage(
offscreenCanvas,
0, 0, offscreenCanvas.width, offscreenCanvas.height,
destX, destY, scaledWidth, scaledHeight
);
// Draw mini canvases
miniCanvasContexts.forEach(({ ctx, phase }) => {
// Clear mini canvas
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, 120, 120);
// Draw platform
const miniPlatformHeight = 30;
ctx.fillStyle = "#2D3748";
ctx.fillRect(0, 120 - miniPlatformHeight, 120, miniPlatformHeight);
// Draw character
if (phase === 'waiting') {
// Use custom drawing for waiting state with blinking
ctx.save();
ctx.translate(60, 120 - miniPlatformHeight - 15);
drawCustomWaitingState(ctx);
ctx.restore();
} else {
// Use the library's drawing for other states
CharacterReference.drawCharacter(ctx, phase, 60 + 8.5, 0, 120, miniPlatformHeight);
}
});
// Continue animation loop
requestAnimationFrame(animate);
}
// Add a click handler to trigger blinks manually
mainCanvas.addEventListener('click', () => {
if (currentPhase === 'waiting') {
triggerCustomBlink();
}
});
// Start animation
animate();
// Trigger an initial blink after a short delay
setTimeout(triggerCustomBlink, 1000);
</script>
</body>
</html>