Pixel Painter

Kieran
Sagar
Parikh

date
fall 2023
tech
GLSL, P5.js

Pixel Painter is both an experimental art creation tool and a series of animated pixel artworks. A kernel fixed at the center of the screen paints on a blank canvas while the canvas moves beneath it. This platform leverages a GLSL shader, so that each frame is defined in terms of the previous frame and a series of boolean inputs.

Motivation

Imagine a pen held in a fixed position with a paper moved under it. The pen can be raised and lowered independently of paper movement. This simple idea was the basis for this digital exploration.

Initial Approach

Moving a piece of paper under a pen is analogous to translating all the pixels in a digital image. Therefore, I set out to build a system where each frame is calculated based on the previous frame and a series of user inputs.


At the heart of this system is a GLSL shader. The shader generates a new frame by translating all the pixels from the previous frame based on the boolean input and drawing the kernel at the center. For example, if up is true, then the value for pixel x,y in the current frame would be the value for pixel x,y-1 in the previous frame.

Translating the pixels in a 6x6 image down 1 pixel.

For initial experimentation, I wired up the boolean shader inputs to the WASD keys on my keyboard, allowing me to move around the canvas like a game of snake.

Additional Features

With the basic mechanism in place, I added additional features to enable creative art-making with Pixel Painter.

Kernels

Kernel color and design can be changed.

square

Square

dots

Dots

triangle

Triangle

Speed

The speed of the animation can be changed by increasing the number of pixels we translate each frame.


1px/frame

5px/frame

10px/frame

Pen up/down

The pen can be raised and lowered so that we can navigate the canvas without drawing on it.

Color Inversion

All colors on the canvas can be inverted while leaving the kernel unchanged.

Manual Mode


For initial experimentation, I wired up each of the features to keys on the keyboard to create a manual mode for artwork creation.

The experience of creating an artwork in manual mode is across between playing an instrument and playing a video game. A combination of timing, dexterity, and technical mastery is necessary to execute an exciting artwork.


.

Pixel Painter Command Language (PPCL)

I found that it could be difficult to create sophisticated artworks in manual mode, so I developed a simple scripting language to define pixel painter artwork. In PPCL, one line defines one frame of the animation.

Commands:

upMove the kernel up one pixel.
downMove the kernel down one pixel.
leftMove the kernel left one pixel.
rightMove the kernel right one pixel.
kernelSize=10 Sets the side length of the kernel.
kernelMode=solid Sets the kernel mode.
kernelParam=2 Sets the optional param for the kernel.
kernelColor=0,0,0 Sets the rgb values for the kernel color.
invert Inverts all colors in the image.
togglePen Toggles the kernel writing on the canvas.
penUp Sets the pen to not write on the canvas.
penDown Sets the pen to write on the canvas.

Control Structures:

Only two simple control structures exist in PPCL: line repetition and block repetition.

Prepend a command line with an integer N to repeat that command N times.

Wrap a block in parens prepended with an integer N to repeat the block N times. Note that the parens MUST have their own lines.

Example:

5 (
frameMultiplier=2
penDown
50 right up
50 left up
50 left down
50 right down
invert penUp
frameMultiplier=5
20 down
)
20 left

This PPCL code draws a simple repeating diamond pattern.

Writing PPCL:

While PPCL can be written manually in a text editor, I've also implemented a mechanism to record commands from manual mode and export the PPCL. In this way, manual mode can be used as a testing/experimentation ground to generate PPCL for use in future artworks.

Infinite Artworks

When Pixel Painter finishes executing a PPCL script, it restarts execution from the beginning of the script without clearing the canvas. As a result, we can use PPCL to create infinite artworks that continue to animate forever, so long as the PPCL script leaves the kernel in a different position than it started and the script will not completely cover the canvas in one color.

Unlike the other artworks on this page (which are video files), the artwork to the right is embedded javascript and will continue generating indefinitely.

Using Javascript to Generate PPCL

We can also use Javascript to generate complex PPCL. This also enables us to use tools like fxhash to generate pixel painter artworks parametrically.

In the artwork to the right, I have used Javascript to generate a new color value for the kernel at each frame, enabling me to create gradients.

Interactive Demo

Click above to start making your own artwork with Pixel Painter. (open in a new window)

Commands:

WASDMove the canvas relative to the Kernel.
ESCOpen the control panel to input PPCL or change parameter values.
EIncrease animation speed.
QDecrease animation speed.
R Invert canvas colors.
FRaise/lower the pen.

Next Project →

Generative Lino