About openSnippets

Welcome to openSnippets, a platform for sharing and exploring creative code snippets using p5.js!

Please don't break the website!
This is a project by one explorer in the generative art space, not a professional programmer.

What is p5.js?

p5.js is a JavaScript library that starts with the original goals of Processing — to make coding accessible for artists, designers, educators, and beginners — and reinterprets this for today's web. Learn more at p5js.org.

How to Create a Snippet

Each snippet needs to have two main functions:

To ensure your snippet works well on our platform, please use a dynamic canvas size:

function setup() {
  createCanvas(windowWidth, windowHeight);
  // Your setup code here
}

function draw() {
  // Your drawing code here
}

Example Snippet

Here's a simple example to get you started:

function setup() {
  createCanvas(windowWidth, windowHeight);
  background(220);
}

function draw() {
  if (mouseIsPressed) {
    fill(0);
  } else {
    fill(255);
  }
  ellipse(mouseX, mouseY, 80, 80);
}

This snippet does the following:

  1. Creates a canvas that fills the window
  2. Sets a light gray background
  3. Draws a circle at the mouse position
  4. The circle is black when the mouse is pressed, white when it's not

Learn More

Ready to dive deeper? Check out the p5.js tutorials for more in-depth guides and examples.

Tips for Using openSnippets

For the best coding experience, we recommend using the p5.js editor to write your code. You can then paste it here to post your snippet!

When you create a snippet, the app first serves a JPG file as a preview. If you want to see the live canvas, simply click on the preview to load it.

We categorize code lengths into four categories:

Join our community on Discord and Twitter to share and discuss your experiences with openSnippets!