Sternhalma.Hex (Sternhalma v0.1.1) View Source
Link to this section Summary
Functions
Return Hex coordinate for a given pixel coordinate {x, y}.
Return the next Hex coordinate based on a provided direction.
Return the surrounding Hex coordinates.
Return a new Hex struct with coordinates x, z, and y. Return nil if the coordinates provided do not add to 0.
Return {x, y} pixel coordinates for a given Hex coordinate.
Link to this section Types
Specs
direction() :: :top_left | :top_right | :left | :right | :bottom_left | :bottom_right
Specs
Represents x z y.
The coordinates x, z, and y must add to 0 in some way.
See https://www.redblobgames.com/grids/hexagons/#coordinates-cube for more info.
Link to this section Functions
Specs
Return Hex coordinate for a given pixel coordinate {x, y}.
Examples
iex> from_pixel({8.267949192431123, 4.0})
%Sternhalma.Hex{x: 1, y: 3, z: -4}
Specs
Return the next Hex coordinate based on a provided direction.
Examples
iex> neighbor(Sternhalma.Hex.new({1, -4, 3}), :top_left)
%Sternhalma.Hex{x: 0, y: 3, z: -3}
Specs
Return the surrounding Hex coordinates.
Examples
iex> neighbors(Sternhalma.Hex.new({1, -4, 3}))
[
top_left: %Sternhalma.Hex{x: 0, y: 3, z: -3},
top_right: %Sternhalma.Hex{x: 1, y: 2, z: -3},
left: %Sternhalma.Hex{x: 0, y: 4, z: -4},
right: %Sternhalma.Hex{x: 2, y: 2, z: -4},
bottom_left: %Sternhalma.Hex{x: 1, y: 4, z: -5},
bottom_right: %Sternhalma.Hex{x: 2, y: 3, z: -5}
]
Specs
Return a new Hex struct with coordinates x, z, and y. Return nil if the coordinates provided do not add to 0.
Specs
Return {x, y} pixel coordinates for a given Hex coordinate.
Examples
iex> to_pixel(Sternhalma.Hex.new({1, -4, 3}))
{8.267949192431123, 4.0}