AI Skill Report Card

Drawing Pixel Art

A-83·Nov 21, 2026·Source: Web

Drawing Pixel Art

Creates 8-bit style pixel art using only vanilla JavaScript and the Canvas API. No libraries, no build tools, no dependencies — just a <canvas> element and code.

15 / 15
JavaScript
// Minimal setup: a scalable pixel grid renderer const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); ctx.imageSmoothingEnabled = false; // crisp pixels, no blur const PIXEL_SIZE = 10; // each "pixel" is rendered as a 10x10 block const GRID = 16; // 16x16 sprite grid canvas.width = GRID * PIXEL_SIZE; canvas.height = GRID * PIXEL_SIZE; function drawPixel(x, y, color) { ctx.fillStyle = color; ctx.fillRect(x * PIXEL_SIZE, y * PIXEL_SIZE, PIXEL_SIZE, PIXEL_SIZE); } // Draw a simple heart sprite using a 2D array (0 = transparent, 1 = color) const heart = [ [0,1,1,0,1,1,0], [1,1,1,1,1,1,1], [1,1,1,1,1,1,1], [0,1,1,1,1,1,0], [0,0,1,1,1,0,0], [0,0,0,1,0,0,0], ]; heart.forEach((row, y) => { row.forEach((val, x) => { if (val) drawPixel(x, y, '#e63946'); }); });
Recommendation▾
Add a bad-output example (e.g., blurry canvas from missing imageSmoothingEnabled) to contrast with good results
15 / 15

Progress:

  • Step 1: Set up canvas with disabled image smoothing
  • Step 2: Define a pixel grid (2D array or sprite map)
  • Step 3: Choose a limited color palette (true 8-bit uses 4-16 colors)
  • Step 4: Write a drawPixel(x, y, color) helper that scales logical pixels to canvas blocks
  • Step 5: Render the sprite by iterating the grid
  • Step 6: (Optional) Add animation via requestAnimationFrame swapping frames/grids
  • Step 7: (Optional) Export as PNG via canvas.toDataURL()

1. Canvas setup (always do this first)

JavaScript
ctx.imageSmoothingEnabled = false; ctx.webkitImageSmoothingEnabled = false; // legacy Safari

This is the single most important line — without it, scaled pixel art looks blurry instead of crisp.

2. Represent sprites as data, not draw calls

Use arrays of indices mapped to a palette. This separates art data from rendering logic and makes sprites easy to edit, mirror, or animate.

JavaScript
const palette = { 0: null, // transparent 1: '#000000', // outline 2: '#ffcc99', // skin 3: '#5555ff', // clothes }; const sprite = [ [0,1,1,1,1,0], [1,2,2,2,2,1], [1,2,1,2,1,1], [0,1,3,3,1,0], [0,1,3,3,1,0], [0,0,1,1,0,0], ]; function drawSprite(grid, paletteMap, offsetX = 0, offsetY = 0) { grid.forEach((row, y) => { row.forEach((idx, x) => { const color = paletteMap[idx]; if (color) drawPixel(x + offsetX, y + offsetY, color); }); }); }

3. Animate with frame arrays

JavaScript
const frames = [frame1Grid, frame2Grid, frame3Grid]; let frameIndex = 0; function animate() { ctx.clearRect(0, 0, canvas.width, canvas.height); drawSprite(frames[frameIndex], palette); frameIndex = (frameIndex + 1) % frames.length; setTimeout(() => requestAnimationFrame(animate), 200); // ~5 fps, classic 8-bit feel } animate();

4. Mirror sprites (save half the data)

JavaScript
function mirrorGrid(grid) { return grid.map(row => [...row].reverse()); }
Recommendation▾
Include an example of reading/generating pixel grids from an image or text-based ASCII pattern for more complex sprites
16 / 20

Example 1: Input: "Draw an 8-bit style coin icon" Output:

JavaScript
const coin = [ [0,0,1,1,1,1,0,0], [0,1,2,2,2,2,1,0], [1,2,2,3,2,2,2,1], [1,2,3,3,3,2,2,1], [1,2,2,3,2,2,2,1], [1,2,2,2,2,2,2,1], [0,1,2,2,2,2,1,0], [0,0,1,1,1,1,0,0], ]; const palette = { 0: null, 1: '#7a5c00', 2: '#ffd700', 3: '#fff3b0' }; drawSprite(coin, palette);

Example 2: Input: "Make a walk-cycle animation for a tiny character" Output: Define 2-4 grids with leg/arm positions shifted, store in frames[], call the animate() loop pattern shown above at 150-250ms per frame.

Example 3: Input: "Export the pixel art as a downloadable image" Output:

JavaScript
const link = document.createElement('a'); link.download = 'sprite.png'; link.href = canvas.toDataURL('image/png'); link.click();
Recommendation▾
Add a brief note on performance for larger canvases or many simultaneous sprites (e.g., offscreen canvas caching)
  • Disable smoothing always — this is non-negotiable for the 8-bit look.
  • Keep palettes small (4-16 colors) for authenticity; store as a lookup object, not raw hex scattered in code.
  • Use power-of-two grid sizes (8x8, 16x16, 32x32) matching classic sprite conventions.
  • Separate data from rendering — grids/palettes are pure data; drawPixel/drawSprite are the only functions touching canvas.
  • Scale via integer PIXEL_SIZE only — non-integer scaling reintroduces blur/artifacts.
  • For transparency, use null/0 in the grid and skip fillRect rather than drawing white.
  • For sprite sheets, pack multiple grids into one canvas using offsetX/offsetY rather than multiple canvases.
  • Forgetting imageSmoothingEnabled = false — results in blurry, non-pixelated output defeating the entire aesthetic.
  • Using CSS width/height to scale canvas without also setting matching canvas width/height attributes — causes blurry stretching. Scale via PIXEL_SIZE in drawing logic instead, or if scaling via CSS, also set image-rendering: pixelated in CSS.
  • Hardcoding colors directly in draw calls instead of a palette object — makes recoloring/theming painful.
  • Redrawing the entire canvas unnecessarily every frame when only part of the sprite changes — fine for small sprites, but inefficient for larger scenes.
  • Non-square pixels from mismatched width/height scale factors — always use one PIXEL_SIZE for both axes unless intentionally distorting.
0
Grade A-AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
15/15
Workflow
15/15
Examples
16/20
Completeness
17/20
Format
14/15
Conciseness
14/15