Visual Effects
Pixelated Canvas
Interactive pixelated image rendering with distortion effects and customizable cell sizes.
The PixelatedCanvas component creates an interactive pixelated rendering of images with distortion effects that respond to mouse movement. It features customizable cell sizes, shapes, colors, and interactive behaviors.
Usage
Pixelated Canvas
<template>
<div class="p-4 bg-elevated rounded-lg">
<h3 class="text-lg font-bold mb-4 text-highlighted">
Pixelated Canvas
</h3>
<MPixelatedCanvas
src="https://picsum.photos/400/300"
:width="400"
:height="300"
:cell-size="8"
class="rounded-lg"
/>
</div>
</template>
Examples
Basic Pixelated Canvas
Pixelated Canvas
Retro-style pixelated images with customizable pixel sizes for nostalgic effects
<template>
<div class="p-6 bg-gradient-to-br from-blue-50 to-indigo-50 dark:from-gray-800 dark:to-gray-900 rounded-xl max-w-2xl mx-auto">
<div class="text-center mb-6">
<h3 class="text-2xl font-bold mb-3 text-highlighted">
Pixelated Canvas
</h3>
<p class="text-muted">
Retro-style pixelated images with customizable pixel sizes for nostalgic effects
</p>
</div>
<div class="bg-default rounded-lg p-4 shadow flex justify-center">
<MPixelatedCanvas
src="https://picsum.photos/400/300"
:width="400"
:height="300"
:cell-size="6"
class="rounded-lg"
/>
</div>
<div class="mt-6 grid grid-cols-3 gap-3">
<UButton
v-for="size in [2, 4, 6]"
:key="size"
:color="size === 6 ? 'primary' : 'gray'"
variant="solid"
size="sm"
@click="updatePixelSize(size)"
>
{{ size }}px Pixels
</UButton>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
const pixelSize = ref(6)
const updatePixelSize = (size) => {
pixelSize.value = size
}
</script>
Customize
Customize
Srchttps://picsum.photos/seed/pixelated/400/500
Width400
Height500
Cell Size3
Dot Scale0.9
Shapesquare
Background Color
Grayscale
Responsive
Dropout Strength0.4
Interactive
Distortion Strength3
Distortion Radius80
Distortion Modeswirl
Follow Speed0.2
Sample Average
Tint Color
Tint Strength0.2
Max Fps60
Object Fitcover
Jitter Strength4
Jitter Speed4
Fade On Leave
Fade Speed0.1
Props
| Prop | Type | Default | Description |
|---|---|---|---|
srcrequired | string | - | Source URL of the image to pixelate. |
width | number | 400 | Width of the canvas in pixels. |
height | number | 500 | Height of the canvas in pixels. |
cellSize | number | 3 | Size of each pixelated cell in pixels. |
dotScale | number | 0.9 | Scale factor for the dots within cells (0-1). |
shape | string | 'square' | Shape of the pixels: 'circle' or 'square'. |
backgroundColor | string | '#000000' | Background color of the canvas. Accepts a Nuxt UI color token (e.g. primary) or any CSS color. |
grayscale | boolean | false | Whether to render the image in grayscale. |
class | string | '' | CSS classes to apply to the canvas element. |
responsive | boolean | false | Whether the canvas should resize with its container. |
dropoutStrength | number | 0.4 | Strength of edge dropout effect (0-1). |
interactive | boolean | true | Whether the canvas should respond to mouse interactions. |
distortionStrength | number | 3 | Strength of the distortion effect. |
distortionRadius | number | 80 | Radius of the distortion effect in pixels. |
distortionMode | string | 'swirl' | Type of distortion: 'repel', 'attract', or 'swirl'. |
followSpeed | number | 0.2 | Speed at which the effect follows the cursor (0-1). |
sampleAverage | boolean | true | Whether to average neighboring pixels for smoother results. |
tintColor | string | '#FFFFFF' | Color to tint the image with. Accepts a Nuxt UI color token (e.g. primary) or any CSS color. |
tintStrength | number | 0.2 | Strength of the tint effect (0-1). |
maxFps | number | 60 | Maximum frames per second for animation. |
objectFit | string | 'cover' | How the image should fit within the canvas: 'cover', 'contain', 'fill', or 'none'. |
jitterStrength | number | 4 | Strength of the jitter effect. |
jitterSpeed | number | 4 | Speed of the jitter effect. |
fadeOnLeave | boolean | true | Whether the effect should fade out when the cursor leaves. |
fadeSpeed | number | 0.1 | Speed of the fade effect (0-1). |
UI
This component's theme exposes the slots below. Override any of them per instance with the ui prop, or app-wide under ui.pixelatedCanvas in app.config.ts.
| Prop | Type | Default | Description |
|---|---|---|---|
ui | object | - | Per-slot classes merged over the theme defaults. |
| Slot | Props | Description |
|---|---|---|
root | - |