I’m thrilled to share the release of my first PureScript library, purescript-gesso
!
What’s it do?
My goal for Gesso was to create a library that would allow me to open up a brand new project and immediately start writing my render, update, and event handler functions — without having to pause to think about getElementById
, getContext
, requestAnimationFrame
, addEventListener
, or anything else like that.
And I think I succeeded!
(Really! I’ve had to stop myself from making more examples for the documentation, or I won’t get anything else done!)
Launching a Gesso application only requires a couple of choices:
-
Which element to put the canvas in
-
The initial state of your application
-
The size of the canvas: fullscreen, fixed size, or fill container
-
Optionally, a separate viewport for the drawing (like svg:viewBox)
and then you can add functions to:
-
Render on animation frames
-
Update state before rendering
-
Update state at fixed intervals
-
Handle any events on the canvas
You have access to timing information (timestamps and deltas), and if you use a custom viewport, there are some very nice functions for scaling coordinates so you don’t need to worry about the dimensions of the browser or screen (even when the window resizes!)
Compatible with Halogen
Gesso works great for standalone applications, but under the hood it’s a Halogen component, so you can easily slot it into any Halogen application. It even supports queries and output with a parent component, and you can access timing and scaling information in those functions too!
What’s it not do?
I’ve intentionally avoided writing FFI bindings for Context2D
functions. I wanted to leave the option open to use a variety of libraries and try higher or lower level interfaces.
It doesn’t support canvas contexts other than CanvasRenderingContext2D
. I’d like to eventually, but I don’t know anything about them so that was out of scope for now.
Getting started
There’s a Quick-Start Guide, the examples folder has instructions for building and running the examples, and the Gesso Manual covers everything you need to know in detail.
purescript-gesso
is available now, so you can spago init && spago install gesso
right away.
I hope you like it!