Package

purescript-hylograph-isometric

Repository
afcondon/purescript-hylograph-isometric
License
MIT
Uploaded by
pacchettibotti
Published on
2026-11-30T15:27:58Z

An orthographic camera for Hylograph: isometric (and any other axonometric) views of 2D layouts, drawn as keyed SVG.

The idea

An isometric view is a projection, not a layout. A 2D layout (a tree, a treemap, a grid) is put on a plane in the world, given heights, and projected by a camera with two angles, azimuth and elevation. Isometric is one setting of them (azimuth 45°, elevation ≈ 35.26°). Turning the view is changing an angle, so everything stays SVG: keyed, clickable, printable, and animatable by redrawing with HATS. No perspective, deliberately, since an orthographic view keeps lengths along an axis comparable. No WebGL.

The world uses a layout's own coordinates: x and y as the layout gave them (y grows down the page, which on the floor is south), and z up.

Modules

  • Hylograph.Isometric.Camera: Point, Point3, Degrees, Camera (azimuth, elevation, scale), isometric, isometricFrom a Viewpoint (SouthEast | SouthWest | NorthWest | NorthEast), isometricUnit (a unit along any axis drawn so many screen units long), turnedBy, between (for animating), project :: Camera -> Point3 -> Point, depth.
  • Hylograph.Isometric.Plane: floor (at a height, so floors stack), leftWall, rightWall, onPlane :: Plane -> Point -> Point3.
  • Hylograph.Isometric.Outline: Outline = Polygon (Array Point) | Circle, rectangle.
  • Hylograph.Isometric.Prism: box, cylinder; faces (every face in the world, with its outward normal) and visibleFaces (what a camera draws: projected outlines, a Facing of Upward | Leftward | Rightward | Downward | Around for flat three-tone shading, and a Lambert lightness).
  • Hylograph.Isometric.Spike: a thin needle or bar standing on a point, always facing the camera, with an optional drop shadow.
  • Hylograph.Isometric.Painter: paintersOrder :: Camera -> (a -> Outline) -> Array a -> Array a, back to front, for things standing on one floor, from any azimuth (a topological sort of "a horizontal line towards the camera meets this one first", not a sort by distance, which fails as soon as footprints differ in size).
  • Hylograph.Isometric.HATS: pathData, pointsData, prismFaces (a prism's visible faces as keyed paths) and inPaintersOrder (marks joined by key in the painter's order).

Everything but the last module is pure geometry and needs no DOM. Point and Point3 are record synonyms rather than newtypes, so that the positions hylograph-layout produces go straight in.

Example

camera = isometricUnit 30.0
prism  = box { x0: 0.0, y0: 0.0, x1: 1.0, y1: 1.0 } { base: 0.0, height: 2.0 }
faces  = visibleFaces camera prism          -- top, and the sides facing +x, +y
order  = paintersOrder camera prismOutline prisms

Tests

spago test: the isometric axes; a full turn is the identity and a quarter turn maps the grid onto itself; the painter's order checked against an independent 3D statement of "in front of" (a line of sight through both boxes' interiors) on random grids and strips, from the four viewpoints and from azimuths and elevations in between; visible faces are exactly those whose normals face the camera.

Used by

  • the derivation city of the Sudoku demo (purescript-hylograph-demos/baskerville-sudoku); docs/screenshots/sudoku-city-before.png and -after.png are the city before and after it moved onto this library;
  • the isometric demo in purescript-hylograph-demos (flare on the floor, turned a quarter at a time).

License

MIT