A p5.js starter template for the 128kb Challenge

Published by Tim on Friday June 14, 2024

Last modified on March 4th, 2025 at 20:12

Your 128kb journey starts here!

This is a template you can use to start developing your idea within the 128kb framework. It is based on inline HTML, so everything (the HTML, the CSS and the JS) is included in a single file. That’s a lean an smart way working with simple sketches.

How it works

Simply put this code in your favorite code editor (for example Visual Studio Code) and start sketching. To easiest way to display your running sketch in Visual Studio Code is by using the the “live-server” extension. It adds a button to the UI at the bottom right. When you click that button, it opens up the sketch in your browser.

To start the rendering process of the gif, simply set the variable exportGif to true. Then the gif file will be downloaded autmatically.

Have fun!

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.2/p5.js"></script>
    <script src="https://unpkg.com/p5.createloop@0.3.1/dist/p5.createloop.js"></script>
    <meta charset="utf-8" />
    <link rel="icon" href="data:," />
  </head>
  <body>
    <style>
      html,
      body {
        margin: 0;
        padding: 0;
      }

      main {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100vh;
      }
      canvas {
        display: block;
        image-rendering: pixelated;
        width: 512px !important;
        height: 512px !important;
        display: block;
      }
    </style>
    <main></main>
  </body>

  <script>
    const exportGif = false;

    function setup() {
      createCanvas(128, 128);
      if (exportGif) {
        saveGif("mySketch", 128, { units: "frames", delay: 20 });
      }
    }

    function draw() {
      background("#aaaaaa");
      fill(0);
      circle(width / 2, height / 2, frameCount);
    }
  </script>
</html>

Submit your work to the gallery!

If you want to show what you have done, please feel free to submit it via the form on this page:

Share it on Social Media

To share your work on Instagram or other channels, that do not accept the gif format, you can use this tool to convert your gif to a high resolution mp4 file.

Related

Monthly Newsletter

Reflections on Creative Coding, Design and life with Technology, every first Friday of the month, directly to your inbox.

Bi-Weekly Update

Active patrons in a paid tier get regular updates on new content, lessons and courses. For learners. Every Friday, 4pm CET.

Related

The Story of 128KB

One day in January 2024, I was lethargically scrolling through my Instagram feed on my laptop. And, as so often […]

A 128KB Export Pipeline

With some help by CoPilot I have coded a Bash script that you can use to convert your animations for […]

Lo-Fi Collage Machine

Click here to login or connect!To view this content, you must be a member of Tim's Patreon at €10 or […]

Diogenes meets Demo Festival

Below is the written version of my talk at DEMO Festival in Amsterdam, January 2025. I’ve also recorded an audio […]

A bash script to convert 128KB gifs to mp4

Do you want to share the creations and sketches you’ve developed for the 128KB challenge on Instagram or other social […]

DEMO 2025 – My Submissions

Limitations have always been playing a major role in my creative work; I was only able to develop my best […]

Throwback: My Talk at Demo Festival 2022

The next edition of the DEMO Festival is already approaching and I am currently developing a brand new talk for […]

Powers of Two – 128kb by Lena Weber

20 = 1 21 = 222 = 323 = 824 = 1625 = 3226 = 6427 = 128 … »In […]