AI Pixel Canvas - Draw Retro Pixel Art

56 views Β· Dec 15, 2025

Create pixel art masterpieces on a 16x16 grid! Click or drag to paint with your selected color. Choose from 8 classic colors in the palette below. Press C to clear and start fresh. Simple, satisfying, and nostalgic. Created with xelsed-alpha6-flash.

#xelsedia#xelsedai#generativeart#p5js#creativecoding#pixelart#retro#drawing#interactive#art
πŸ”€ Remix This πŸ“– View Docs β›Ά Full Screen ← Back to Gallery
πŸ“‹ Embed Code

Copy this code to embed this sketch on your website:

<iframe src="https://p5js.ai/embed/7557f44a-ad78-4c7c-b8b5-3ccf78d3bf58" width="400" height="400" frameborder="0" allow="autoplay" title="AI Pixel Canvas - Draw Retro Pixel Art"></iframe>

Adjust width and height as needed. Preview embed β†’

❓ About This Sketch 3 questions

What kind of visual art can users create with the AI Pixel Canvas sketch?

Users can create retro pixel art masterpieces on a 16x16 grid using a selection of 8 classic colors.

How can users interact with the AI Pixel Canvas to create art?

Users can click or drag to paint on the grid with their selected color and press 'C' to clear the canvas and start anew.

What creative coding concepts does the AI Pixel Canvas sketch showcase?

This sketch demonstrates grid-based drawing techniques, color selection, and mouse interaction in p5.js for a nostalgic pixel art experience.

πŸ’¬ AI Chat History 2 messages
πŸ‘€ You
Create a pixel art drawing canvas. Show a 16x16 grid of squares. Each square is 20x20 pixels. Click or drag to paint squares with the current color. Show a color palette at the bottom with 8 colors (black, white, red, orange, yellow, green, blue, purple). Click a palette color to select it. Current color shown with a border. Press C to clear canvas. Grid lines visible but subtle (light gray). White background. Simple and satisfying to use. Keep code under 50 lines.
πŸ€– AI
Here’s a compact pixel-art editor that matches your specs and stays under 50 lines.

---

### `index.html`
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixel Art Canvas</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.3/lib/p5.min.js"></script>
<script src="sketch.js"></script>
</body>
</html>
```

---

### `sketch.js`
```js
let cols=16, rows=16, cell=20, grid=[], palette=["black","white","red","orange","yellow","green","blue","purple"], cur=0;

function setup(){
createCanvas(cols*cell, rows*cell+40);
for(let i=0;i<rows;i++){ grid[i]=[]; for(let j=0;j<cols;j++) grid[i][j]=color(255); }
noSmooth();
}

function draw(){
background(255);
stroke(220);
for(let i=0;i<rows;i++) for(let j=0;j<cols;j++){
fill(grid[i][j]);
rect(j*cell,i*cell,cell,cell);
}
for(let i=0;i<palette.length;i++){
fill(palette[i]);
stroke(i==cur?0:220);
strokeWeight(i==cur?3:1);
rect(i*width/palette.length,rows*cell,width/palette.length,40);
}
strokeWeight(1);
}

function paint(){
if(mouseY<rows*cell){
let c=floor(mouseX/cell), r=floor(mouseY/cell);
if(c>=0&&c<cols&&r>=0&&r<rows) grid[r][c]=palette[cur];
}else if(mouseY<height){
let i=floor(mouseX/(width/palette.length));
if(i>=0&&i<palette.length) cur=i;
}
}

function mousePressed(){ paint(); }
function mouseDragged(){ paint(); }
function keyPressed(){
if(key=='c'||key=='C')
for(let i=0;i<rows;i++) for(let j=0;j<cols;j++) grid[i][j]=color(255);
}
```

Key details:
- Canvas: `320Γ—360` β†’ 16Γ—16 grid of `20Γ—20` pixels + 40px palette strip.
- Painting: click or drag (`mousePressed` / `mouseDragged`) paints the square under the cursor with the current color ([mouse events ref](https://p5js.org/reference/#/p5/mousePressed)).
- Palette: 8 colors at the bottom; clicking changes `cur` and shows a thicker black border on the selected color.
- Clear: press `C` or `c` to reset all cells to white ([keyPressed ref](https://p5js.org/reference/#/p5/keyPressed)).
- Grid lines: light gray (`stroke(220)`) over a white background.
🎬 Video Preview