Week 15 - Tips and Tricks, Contributing to Open Source

Date: 2026-11-30

Agenda

Tips and Tricks

There are a number of algorithms, tips and tricks in creative coding.

Some of these can be found in the L5 examples page.

Storing Input

Move the mouse across the screen to change the position of the circles. The positions of the mouse are recorded into an array and played back every frame. Between each frame, the newest value are added to the end of each array and the oldest value is deleted.

animation of mouse trail showing translucent circles
animation of mouse trail showing translucent circles
require("L5")

local num = 60
local mx
local my

function setup()
    size(640, 360)
    windowTitle("Storing Input")
    describe(" Move the mouse across the screen to change the position of the circles and store them")

    noStroke()

    mx = {}
    my = {}

    for i = 0, num - 1 do
        mx[i] = 0
        my[i] = 0
    end

    fill(255, 153)
end

function draw()
    background(51)

    -- Cycle through the array, using a different entry on each frame.
    -- Using modulo (%) like this is faster than moving all the values over
    local which = frameCount % num
    mx[which] = mouseX
    my[which] = mouseY

    for i = 0, num - 1 do
        -- which+1 is the smallest (the oldest in the array)
        local index = (which + 1 + i) % num
        ellipse(mx[index], my[index], i, i)
    end
end

createGraphics Offscreen

Sometimes you may find a need for creating an offscreen canvas and drawing graphics to this hidden screen. For that we have the createGraphics() function.

In this example, a type of drawing program, dragging with the mouse across the window will draw tiny photos wherever our mouse is located. If this was the entirety of the program, we’d have no need for createGraphics. A minimal implementation of this follows:

require("L5")

function setup()
  -- initalize a global array of images
  img = {}
  
  -- load all of our images
  for i=1,9 do
    img[i] = loadImage("assets/"..i..".png")
  end
  
  describe("Draws random images at mouse position when dragged in the window.")
end

function mouseDragged()
  image(random(img),mouseX, mouseY, 50, 50)
end

This program is fine, but what happens if we want a new color background each time we press down to draw a line or lay down photos? If we added background() to the mouseDragged() function than we would cover all of our previous drawing. To prevent this problem, we use an offscreen canvas.

In our setup() we load in photos to an array img. And we initialize our offscreenCanvas as a new graphics buffer for drawing with createGraphics().

As draw runs continously, it grabs the offscreen canvas. We’ll come back to that. In the mouseDragged event, as long as we are dragging the mouse we start drawing to the offscreen buffer, leaving a randomly-selected image at the equivalent of the mouse X and Y positions, but in the offscreen canvas. As we press down on the mouse, we draw a random color on the entire visible fullscreen. Then in draw, we take the offscreen graphics canvas and draw it as an image, starting at the top left 0, 0 position, effectively applying this offscreen doodle of images with transparent background on top of the color background. This allows us to maintain the design of drawing photos on a colored canvas without overwriting the entire window’s contents.

Drawing with photos on a colored background that changes on mouse press
Drawing with photos on a colored background that changes on mouse press
require("L5")

function setup()
  fullscreen()
  windowTitle("Quick Pic Draw")
  img = {}
  for i = 1, 9 do
   img[i] = loadImage("assets/"..i..".png")
  end

  background(0)
  describe("Draw with pictures.")

  -- Create offscreen canvas
  offscreenCanvas = createGraphics(800, 600)
end

function draw()
  image(offscreenCanvas:getCanvas(), 0, 0)
end

function mouseDragged()
  offscreenCanvas:beginDraw()

  image(random(img),mouseX,mouseY,50,50)

  offscreenCanvas:endDraw()
end

function mousePressed()
  background(random(255),random(255),random(255))
end

adapted from L5 examples - CC BY-NC-SA

Easing

Move the mouse across the screen and the symbol will follow. Between drawing each frame of the animation, the program calculates the difference between the position of the symbol and the cursor. If the distance is larger than 1 pixel, the symbol moves part of the distance (0.05) from its current position toward the cursor.

animation of a circle smoothly following the mouse cursor
animation of a circle smoothly following the mouse cursor
require("L5")

local x = 0
local y = 0
local easing = 0.05

function setup()
    size(640, 360)
    windowTitle("Easing")
    describe(" Move the mouse across the screen and the symbol will follow.")

    noStroke()
end

function draw()
    background(51)

    -- Change the position of the drawn ellipse to the position of the mouse with easing

    targetX = mouseX
    dx = targetX - x
    x = x + dx * easing

    targetY = mouseY
    dy = targetY - y
    y = y + dy * easing

    ellipse(x, y, 66)
end

adapted from L5 example “easing” CC BY-NC-SA

Contributing to open source software

Some ways to Help with L5

We follow the All Contributors philosophy:

Our community values contributions of all forms and seeks to expand the meaning of the word contributor.

Step 1: Decide what you want to contribute

L5 has two main repositories. Which one you use depends on what you’re working on.

L5 - The library itself

Use this repository if you want to:

Repository: https://github.com/L5lua/L5

L5 Website - The documentation site

Use this repository if you want to:

Repository: https://github.com/L5lua/L5-website

Step 2: Start with an issue

Before writing code or documentation, we recommend opening an issue to describe:

This helps avoid duplicated work and gives you a place to ask questions.

Where to file issues

Library issues: https://github.com/L5lua/L5/issues

Website issues: https://github.com/L5lua/L5-website/issues

Step 3: Fork the repository

If you want to make changes:

  1. Fork the repository you’re contributing to
    (either L5 or L5-website)
  2. Clone your fork to your computer
  3. Make your changes
  4. Open a Pull Request back to the main repository

You do not need special permission to fork, and you do not need to create a branch in the main repository.

L5 and Permacomputing Survey

Final Project guidelines

Your final project is a project that makes use of procedural generation. It can be a procedurally-generated game, story, art toy or other digital media.

It is permitted to include ‘hand-crafted’ content as well as procedurally-generated content.

The final project should be a compelling work that is complete on its own and produces different meaningful results each time it is run.

Write a proposal for your final project. Includes screenshots of other media that has influenced your thinking, and any thoughts, techniques for building, or questions that you have at this time.

High level idea: You are worldbuilding, creating an ecosystem of characters, a world with varied terrain or environment, and procedurally generated objects in that world and text.

Be sure to reference ideas from Ten Questions Concerning Generative Computer Art (pdf )

Deliverables: * a character that a player can play * procedurally generate a terrain or environment * procedurally generate characters in the world * procedurally generate text that meaningfully flavors the world, its characters or environment

Optional: * procedurally generated music * playable with win/lose states