vivid v0.4.2 Vivid.SLPFA View Source

Scanline Polygon Filling Algorithm, as per https://hackernoon.com/computer-graphics-scan-line-polygon-fill-algorithm-3cb47283df6#.20fac9f40

This algorithm only fills the inside of a polygon, leaving you free to to compose it with the original polygon if you want to use different border and fill colours, for example.

Link to this section Summary

Functions

Fills the inside area of a polygon using the Scanline Polygon Filling Algorithm

Link to this section Functions

Fills the inside area of a polygon using the Scanline Polygon Filling Algorithm.

Examples

The original polygon.

iex> use Vivid
...> frame = Frame.init(16, 16, RGBA.black)
...> polygon = Polygon.init([Point.init(1, 1), Point.init(4, 1), Point.init(4, 7), Point.init(11, 7), Point.init(11, 1), Point.init(14, 1), Point.init(14, 14), Point.init(1, 14)])
...> Frame.push(frame, polygon, RGBA.white)
...>   |> to_string
"                \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @            @ \n" <>
" @            @ \n" <>
" @            @ \n" <>
" @            @ \n" <>
" @            @ \n" <>
" @            @ \n" <>
" @  @@@@@@@@  @ \n" <>
" @  @      @  @ \n" <>
" @  @      @  @ \n" <>
" @  @      @  @ \n" <>
" @  @      @  @ \n" <>
" @  @      @  @ \n" <>
" @@@@      @@@@ \n" <>
"                \n"

The filled area of the polygon

iex> use Vivid
...> frame = Frame.init(16, 16, RGBA.black)
...> polygon = Polygon.init([Point.init(1, 1), Point.init(4, 1), Point.init(4, 7), Point.init(11, 7), Point.init(11, 1), Point.init(14, 1), Point.init(14, 14), Point.init(1, 14)]) |> Vivid.SLPFA.fill |> Group.init
...> Frame.push(frame, polygon, RGBA.white)
...>   |> to_string
"                \n" <>
"                \n" <>
"  @@@@@@@@@@@@  \n" <>
"  @@@@@@@@@@@@  \n" <>
"  @@@@@@@@@@@@  \n" <>
"  @@@@@@@@@@@@  \n" <>
"  @@@@@@@@@@@@  \n" <>
"  @@@@@@@@@@@@  \n" <>
"  @@@@@@@@@@@@  \n" <>
"  @@        @@  \n" <>
"  @@        @@  \n" <>
"  @@        @@  \n" <>
"  @@        @@  \n" <>
"  @@        @@  \n" <>
"  @@        @@  \n" <>
"                \n"

The polygon and the fill combined.

iex> use Vivid
...> frame = Frame.init(16, 16, RGBA.black)
...> polygon = Polygon.init([Point.init(1, 1), Point.init(4, 1), Point.init(4, 7), Point.init(11, 7), Point.init(11, 1), Point.init(14, 1), Point.init(14, 14), Point.init(1, 14)])
...> inside = polygon |> Vivid.SLPFA.fill |> Group.init
...> Frame.push(frame, polygon, RGBA.white)
...>   |> Frame.push(inside, RGBA.white)
...>   |> to_string
"                \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@@@@@@@@@@@ \n" <>
" @@@@      @@@@ \n" <>
" @@@@      @@@@ \n" <>
" @@@@      @@@@ \n" <>
" @@@@      @@@@ \n" <>
" @@@@      @@@@ \n" <>
" @@@@      @@@@ \n" <>
"                \n"