Vivid.Buffer (vivid v0.4.5)

Copy Markdown View Source

Used to convert a Frame into a buffer for display.

You're unlikely to need to use this module directly, instead you will likely want to use Frame.buffer/2 instead.

Buffer implements the Enumerable protocol.

Example

iex> use Vivid
...> box = Box.init(Point.init(1,1), Point.init(18,8))
...> Frame.init(20, 10, RGBA.white())
...> |> Frame.push(box, RGBA.black())
...> |> Buffer.horizontal()
...> |> Stream.chunk_every(20)
...> |> Stream.map(fn line ->
...>   Stream.map(line, fn colour -> RGBA.to_ascii(colour) end)
...>   |> Enum.join()
...> end)
...> |> Enum.join("\n")
"@@@@@@@@@@@@@@@@@@@@\n" <>
"@                  @\n" <>
"@ @@@@@@@@@@@@@@@@ @\n" <>
"@ @@@@@@@@@@@@@@@@ @\n" <>
"@ @@@@@@@@@@@@@@@@ @\n" <>
"@ @@@@@@@@@@@@@@@@ @\n" <>
"@ @@@@@@@@@@@@@@@@ @\n" <>
"@ @@@@@@@@@@@@@@@@ @\n" <>
"@                  @\n" <>
"@@@@@@@@@@@@@@@@@@@@"

Summary

Functions

Returns the number of columns in the buffer.

Render the buffer horizontally, ie across rows then up columns.

Returns the number of rows in the buffer.

Render the buffer vertically, ie up columns then across rows.

Types

t()

@type t() :: %Vivid.Buffer{
  buffer: [Vivid.RGBA.t()],
  columns: integer(),
  rows: integer()
}

Functions

columns(buffer)

@spec columns(t()) :: pos_integer()

Returns the number of columns in the buffer.

horizontal(frame)

@spec horizontal(Vivid.Frame.t()) :: t()

Render the buffer horizontally, ie across rows then up columns.

Example

iex> use Vivid
...> Frame.init(5, 5, RGBA.white)
...> |> Frame.push(Line.init(Point.init(0, 2), Point.init(5, 2)), RGBA.black)
...> |> Buffer.horizontal
...> |> to_string
"@@@@@\n" <>
"@@@@@\n" <>
"     \n" <>
"@@@@@\n" <>
"@@@@@\n"

rows(buffer)

@spec rows(t()) :: pos_integer()

Returns the number of rows in the buffer.

vertical(frame)

@spec vertical(Vivid.Frame.t()) :: t()

Render the buffer vertically, ie up columns then across rows.

Example

iex> use Vivid
...> Frame.init(5, 5, RGBA.white)
...> |> Frame.push(Line.init(Point.init(0, 2), Point.init(5, 2)), RGBA.black)
...> |> Buffer.vertical
...> |> to_string
"@@ @@\n" <>
"@@ @@\n" <>
"@@ @@\n" <>
"@@ @@\n" <>
"@@ @@\n"