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: 4
Joined: Fri Jun 08, 2018 8:40 pm

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

Post by alphabetr » Fri Jun 08, 2018 9:05 pm

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: 4
Joined: Fri Jun 08, 2018 8:40 pm

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

Post by alphabetr » Sun Jul 15, 2018 10:39 am

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: 428
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 » Mon Jul 16, 2018 10:02 am

Great work! :-)

User avatar
yetneverdone
Party member
Posts: 302
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 » Mon Jul 16, 2018 10:09 am

Awesome! Making roguelike now is easier!

alphabetr
Prole
Posts: 4
Joined: Fri Jun 08, 2018 8:40 pm

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

Post by alphabetr » Wed Jul 18, 2018 11:28 pm

Thanks both, I hope it comes in useful!

alphabetr
Prole
Posts: 4
Joined: Fri Jun 08, 2018 8:40 pm

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

Post by alphabetr » Sat Aug 11, 2018 12:34 am

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:

User avatar
yetneverdone
Party member
Posts: 302
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 » Sat Aug 11, 2018 12:49 am

Awesome! Keep up the good work!

Post Reply

Who is online

Users browsing this forum: Exabot [Bot] and 5 guests