Page 1 of 1

forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Fri Jun 08, 2018 9:05 pm
by alphabetr
Hi all,

Long time lurker here but this is my first post.

I've been working for a while on a little toolkit, something I've mainly been using for roguelike map generation.
It's a library in pure lua 5.1 for the manipulation of shapes and patterns on a 2D grid.

You can see it on github: https://github.com/nhartland/forma.
With documentation at: https://nhartland.github.io/forma/.

It's a bit niche, but provides some handy stuff with (I hope) a reasonably natural API. Some examples of what it includes:

Basic features
  • A 'cell' class with normal (integer) vector operations
  • A 'pattern' class which holds a set of cells
  • A bunch of pattern primitives, for drawing circles, lines, squares etc
  • A bunch of basic manipulating functions, for shifting, enlarging, reflecting patterns.
A basic but flexible Cellular Automata implementation
  • Custom CA neighbourhoods and update rules
  • Synchronous and asynchronous updates
  • CA patterns can be 'nested' or generating inside the results of previous patterns
Helpers for generating 'subpatterns'
  • Flood-filling to determine contiguous areas (according to custom definitions of contiguous)
  • Voronoi tessellation
  • Binary space partitioning
  • Finding the largest contiguous rectangle in a pattern
  • Finding points on the inner/outer surface of patterns
I hope this can be useful for somebody, and please let me know if you have any feedback! There are examples on the github page, but here are some game specific applications where I have used forma for map/level design and generation.
  • [ASCII/Terminal] Golf course layout generation using nested CA.
Image
  • [ASCII/Terminal] Building layout generation.
Image
  • [Tiles/Love2D]] Building layout generation.
Image

Re: forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Sun Jul 15, 2018 10:39 am
by alphabetr
Yesterday I pushed a new version of forma, including a few performance enhancements and
several new features.

There is now an examples gallery at
https://github.com/nhartland/forma/tree/master/examples

New features
  • Implemented a 'mask' subpattern that masks out cells according to a provided function
  • Added Voronoi relaxation via Lloyd's algorithm
  • Added pattern.cells: an iterator over the constituent cells in a pattern
  • Added cell_coordinates iterator, returning an (x,y) pair rather than a cell
  • Added shuffled_cells iterator, similar to cells but in a randomised order
  • Added centroid and medoid (with general distance measure) methods and tests
  • Added a Poisson-disc sampling subpattern
  • Added Mitchell's Best-Candidate sampling (approximate Poisson-Disc)

Re: forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Mon Jul 16, 2018 10:02 am
by Ulydev
Great work! :-)

Re: forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Mon Jul 16, 2018 10:09 am
by yetneverdone
Awesome! Making roguelike now is easier!

Re: forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Wed Jul 18, 2018 11:28 pm
by alphabetr
Thanks both, I hope it comes in useful!

Re: forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Sat Aug 11, 2018 12:34 am
by alphabetr
Hi everyone,

Keeping up with the so-far once monthly updates (not sure how long I can maintain that! :D).
I've pushed a new version (0.3) of forma to the GitHub page. You can see a detailed changelog here: Mostly under the hood stuff, I think I'm as far as my Lua skills can take me in terms of optimisation without breaking
the generality of the library (any suggestions for improvement in this regard would be gratefully welcomed!).

As an example of an application of forma, I've been working on a little golf-themed roguelike, with terminal and love2d versions available here:

Re: forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Sat Aug 11, 2018 12:49 am
by yetneverdone
Awesome! Keep up the good work!

Re: forma: a toolkit for the manipulation of shapes on a 2D grid

Posted: Fri Apr 10, 2020 11:55 am
by alphabetr
Hi everyone,

It’s been a while since I last needed to make an update to forma,
but I’ve now accumulated enough changes to merit a new little release.

Since the last time I posted the key updates have been:
  • You can now generate patterns using Perlin noise and thresholds.
  • In addition to the standard primitives (line, square, circle) I’ve added quadratic Bezier curve rasterisation.
  • The convex hull of a pattern can now be computed and rasterised.
  • I’ve added a method for computing the edit distance between two patterns on the grid.
As always you can get hold of the code at GitHub:
https://github.com/nhartland/forma
and please do take a look at the example gallery (including Perlin Noise and convex hull examples)
https://github.com/nhartland/forma/tree/master/examples

Cheers!