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

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
alphabetr
Prole
Posts: 6
Joined: Fri Jun 08, 2018 8:40 pm

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

Post 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
alphabetr
Prole
Posts: 6
Joined: Fri Jun 08, 2018 8:40 pm

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

Post 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)
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

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

Post by Ulydev »

Great work! :-)
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post by yetneverdone »

Awesome! Making roguelike now is easier!
alphabetr
Prole
Posts: 6
Joined: Fri Jun 08, 2018 8:40 pm

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

Post by alphabetr »

Thanks both, I hope it comes in useful!
alphabetr
Prole
Posts: 6
Joined: Fri Jun 08, 2018 8:40 pm

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

Post 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:
alphabetr
Prole
Posts: 6
Joined: Fri Jun 08, 2018 8:40 pm

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

Post 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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest