Skip to content
[+]api/*: made base api dir authored by cactusfluo's avatar cactusfluo
- base
- [clear](#clear)
- [background](#background)
- line
- [line](#line)
- [set_line_char](#set_line_char)
- [line_func](#line_func)
- rectangle
- [rect](#rect)
- [set_rect_border](#set_rect_border)
- [set_rect_mode](#set_rect_mode)
- text
- [text](#text)
- [set_text_mode](#set_text_mode)
- [set_text_align](#set_text_align)
- [set_text_wrap](#set_text_wrap)
- other
- [shape](#shape)
- [fill](#fill)
- [border](#border)
- [set_draw_mode](#set_draw_mode)
# clear
```javascript
> clear();
> clear(layer);
```
Clear the passed layer by putting space characters at each cell. By default, the
cleared layer is the active layer.
## Parameter:
- `layer` Layer: Layer to be cleared
# background
```javascript
> background(character);
```
Put the passed charater at each cell of the active layer.
## Parameter:
- `character` String: String to be put at each layer cells
# line
```javascript
> line(x0, y0, x1, y1);
> line(x0, y0, x1, y1, character);
```
Draw a line from `[x0, y0]` to `[x1, y1]` on the active layer with the passed
character. If no character is passed, `line()` will use the set line character
(see [set_line_char](#set_line_char)).
## Parameters:
- `x0` Number: x coordinate of the first point
- `y0` Number: y coordinate of the first point
- `x1` Number: x coordinate of the second point
- `y1` Number: y coordinate of the second point
- `character` String: Character to be put at each line point
# set_line_char
```javascript
> set_line_char();
> set_line_char(character);
```
Set the `line()` character. Next calls of `line()` will use this character if
not passed into `line()` itself.
Calling `set_line_char()` without any parameter resets the `line()` character to
it's default value.
## Parameter:
- `character` String: Character to be set as default for lines
# line_func
```javascript
> line_func(x0, y0, x1, y1, function);
```
Call the passed function for each point of the line formed by `[x0, y0]` and
`[x1, y1]`. The called function takes 3 parameters, `x` and `y` coordinates
of the current point and a boolean variable which is set to `true` when the
coordinates are inside the active layer.
Here is an example of a function passed to `line_func()`:
```javascript
function (x, y, is_on_layer) {
if (is_on_layer == true) {
my_layer[y][x] = '#';
}
}
```
## Parameters:
- `x0` Number: x coordinate of the first point
- `y0` Number: y coordinate of the first point
- `x1` Number: x coordinate of the second point
- `y1` Number: y coordinate of the second point
- `function` Function: Function to be called at each line point
# rect
```javascript
> rect(x, y, width, height);
> rect(x, y, width, height, border);
```
Draw a rectangle on the active layer. `x`, `y`, `width` and `height` are passed
to position and dimension the rectangle. A `border` string can be passed to
style the rectangle. Here is how the border string works:
```
with "012345678"
0: top-left corn
1: top side
2: top-right corner
3: left side
4: center
5: right side
6: botton-left corner
7: bottom side
8: bottom-right corner
```
The border string can also be set through `set_rect_border()` (see
[set_rect_border](#set_rect_border)).
By default, the top-left corner of the rectangle is placed at the passed
coordinates, but it can also be placed differently via `set_rect_mode()` (see
[set_rect_mode](#set_rect_mode)).
## Parameters:
- `x` Number: x coordinate of the rectangle
- `y` Number: y coordinate of the rectangle
- `width` Number: Width of the rectangle
- `height` Number: Height of the rectangle
- `border` String: String border of the rectangle
# set_rect_border
```javascript
> set_rect_border();
> set_rect_border(characters);
```
Set the `rect()` border string. Next calls of `rect()` will automatically use
this string if not passed into `rect()` itself.
Calling `set_rect_border()` without any parameter resets the `rect()` border
string to it's default value.
# Parameter:
- `characters` String: String border of `rect()`
# set_rect_mode
```javascript
> set_rect_mode();
> set_rect_mode(mode);
```
Set the `rect()` placement mode. By default, the top-left corner of the drawn
rectangle is placed at the passed cordinates.
Calling `set_rect_rect()` without any parameter resets the `rect()` border
string to it's default value.
## Parameter:
- `mode` Mode: Mode of `rect()`
## Modes:
- `RECT_CORNER` Default value, passed coordinates are used for the top-left corner.
- `RECT_CENTER` Passed coordinates are used for the center of the rectangle.
# text
```javascript
> text(string, x, y);
> text(string, x, y, paragraph_width);
```
Write the passed `string` on the active layer at [`x`, `y`] coordinates. A
paragraph width can be passed for wrap modes. In this way, the text will wrap to
avoid paragraph width overflow.
## Parameters:
- `string` String: Text to be drawn
- `x` Number: x coordinate of the text
- `y` Number: y coordinate of the text
- `paragraph_width` Number: Width of the paragraph
# set_text_mode
```javascript
> set_text_mode();
> set_text_mode(mode);
```
Set the `text()` placement mode. By default, passed coordinates of `text()` are
defining left side of the text. But it can also be the center or the right side
of the text / paragraph.
## Parameter:
- `mode` Mode: Mode of `text()`
## Modes:
- `TEXT_LEFT` Default value
- `TEXT_CENTER`
- `TEXT_RIGHT`
# set_text_align
```javascript
> set_text_align();
> set_text_align(align_mode);
```
Set the `text()` alignement mode. By default, the paragraph is aligned to left
but it can be set to center or right. The alignement works when wrap mode
Modes:
- `TEXT_ALIGN_LEFT` Default value.
- `TEXT_ALIGN_CENTER`
- `TEXT_ALIGN_RIGHT`
# set_text_wrap
```javascript
> set_text_wrap();
> set_text_wrap(wrap_mode);
```
Set the `text()` wrapping mode. By default, the text does not wrap, it is
trimmed once it got out of the active layer.
Modes:
- `TEXT_TRIM` Default value, text is trimmed out of the active layer.
- `TEXT_WRAP_HARD` Wrap text. Split words if necessary.
- `TEXT_WRAP` Wrap text without splitting words (exept if the word is bigger
than the text / paragraph width).
# shape
```javascript
> shape(x, y, radius_x, radius_y, vertices, character);
> shape(x, y, radius_x, radius_y, vertices, character, linked);
> shape(x, y, radius_x, radius_y, vertices, character, linked, rotation_offset);
```
Draw a shape on the active layer. The shape is positioned at `x` and `y` passed
coordinates. The value of `vertices` defines the number of sides of the shape.
With 3 vertices, the shape would be a **triangle**, with 4, a **square** etc.
The bigger this value is, the nearer the shape would be to a **circle**.
`radius_x` and `radius_y` are used to modify the shape width / height ratio. As
most fonts have characters taller than bigger, it is important to make some
tests with your font to know which radius would give the shape you want.
`character` is used to draw the shape.
If `linked` (`true` by default) is set to `false`, sides of the shape will not
be drawn. Only the corners will.
`rotation_offset` (`0` by default) is a number value (between `0` and `1`) which
set the shape rotation offset. At `0`,
# fill
```javascript
> fill(x, y, character);
```
# border
# set_draw_mode
```javascript
> set_draw_mode();
> set_draw_mode(mode);
```