genart is my Scala 3 library for making art with code. It provides a common API for sketches that run in a desktop window using Processing or in the browser using p5.js, compiled through Scala.js; this allows me to write Generative Artwork using a simple, high-level API in a functional language with an expressive typesystem, without having to worry too much about how the internals work.

Here’s a small diagram illustrating how this project’s architecture works (at a high level).

genart architecturegenart interacts with a shared Scala API. The API compiles to the JVM or JavaScript. The JVM code interacts with Processing's Java APIs, which communicate with the operating system through java.awt. The JavaScript code interacts with p5.js and directly with the DOM; p5.js also interacts with the DOM.

via java.awt

genart

Scala API

Compiled to JVM

Compiled to JS

Processing Java APIs

p5.js

OS

DOM

Drawing and animation

genart exposes APIs for setup, updates, drawing, and event handling for keyboard and pointer input; its canvas APIs support basic polygons, Bézier paths, gradients, text, images, and complicated clipping/blending.

Sketches

Here are a few sketches from the repository, compiled from Scala to run in your browser. Choose an example below and press Run sketch to try it.

There are more examples.