@spec clear_canvas() :: :ok
Used to erase all the drawings and leave an empy canvas.
@spec draw_rectangle(map) :: {:ok, Rectangle.t()} | {:error, Ecto.Changeset.t()}
It create and store a new Rectangle
in the DB which will be rendered on the next page load.
Attributes
x
:integer, the horizontal position of the top right corner of the rectangle, Requiredy
:integer, the vertical position of the top right corner of the rectangle, Requiredwidth
:integer, the width of the rectangle, Requiredheight
:integer, the height of the rectangle, Requiredfill_char
:string, the character to fill the rectangle withoutline_char
:string, the character to draw the outline of the rectangle
Note: Either fill_char
or outline_char
should be specifyed.
## Examples
iex> Canvas.draw_rectangle(%{x: 2, y: 0, width: 3, height: 5, fill_char: ".", outline_char: "X"})
To generate the next canvas follow the next steps:
- Start the server in interactive mode
iex -S mix phx.server
- visit
localhost:4000
to see an empty canvas - to create the first
Rectangle
s go back to the terminal and run the following commands.
iex> Canvas.draw_rectangle(%{x: 0, y: 10, width: 8, height: 4, outline_char: "O"})
{:ok, %Canvas.Rectangles.Rectangle{ ... }}
iex> Canvas.draw_rectangle(%{x: 5, y: 12, width: 5, height: 3, fill_char: "X", outline_char: "X" })
{:ok, %Canvas.Rectangles.Rectangle{ ... }}
iex> Canvas.draw_rectangle(%{x: 15, y: 3, width: 7, height: 6, fill_char: "." })
{:ok, %Canvas.Rectangles.Rectangle{ ... }}
- reload the page and the
Rectangles
should be rendered in the canvas.
To generate the API documentation files:
> mix deps.get
...
> mix docs
Later you can acces to your doc/Canvas.html