module Lime
Overview
The main module of lime.
All x
and y
arguments are zero-based.
An IndexError
will be raised if:
- An
x
argument is greater thanWindow.width
. - An
x
argument is lower than-Window.width_cells
. - A
y
argument is greater thanWindow.height
. - A
y
argument is lower than-Window.height_cells
.
NOTE Sometimes you might come across the terms "cell" and "pixel":
- A "cell" refers to one place of a character on the console:
█
. - A "pixel" does not refer to a pixel of a display.
It refers to the half of a "cell":
▀
and▄
.
Extended Modules
Defined in:
lime.crlime/drawables.cr
lime/modules.cr
Instance Method Summary
-
#buffer(x, y) : Char | Colorize::Object(Char)
Returns the character of the buffer at x, y.
-
#buffer : Array(Char | Colorize::Object(Char))
Returns the buffer as an array of characters.
-
#buffer=(buffer : Array(Char | Colorize::Object(Char)))
Sets the buffer to buffer.
-
#buffer_height=(height)
Sets the height of the buffer to height.
-
#clear
Clears the buffer.
-
#draw
Draws the content of the buffer to the screen.
-
#get_key : Symbol | String
Waits until a key has been pressed and returns it compactly as a symbol.
-
#get_key_raw : String
Waits until a key has been pressed and returns it.
-
#line(x1 : Int32, y1 : Int32, x2 : Int32, y2 : Int32, color : Colorize::Color = Colorize::ColorANSI::Default)
Inserts a line from x1, y1 to x2, y2 with color into the buffer.
-
#loop(&)
The order of the loop is as follows:
-
#peek_key : Symbol | String | Nil
Returns the key that is down in the moment this method is called compactly as a symbol or
nil
if no key is down. -
#peek_key_raw : String | Nil
Returns the key that is down in the moment this method is called or
nil
if no key is down. -
#pixel(x : Int32, y : Int32, color : Colorize::Color = Colorize::ColorANSI::Default)
Inserts a pixel at x, y with color into the buffer.
-
#print(char : Char | Colorize::Object(Char), x : Int32, y : Int32)
Inserts char into the buffer at x, y.
-
#print(string : String, x : Int32, y : Int32)
Inserts string into the buffer at x, y.
-
#print(string : Colorize::Object(String), x : Int32, y : Int32)
Inserts string into the buffer at x, y.
-
#printf(string : String, x : Int32, y : Int32)
Inserts string formatted into the buffer at x, y.
-
#printf(string : Colorize::Object(String), x : Int32, y : Int32)
Inserts string formatted into the buffer at x, y.
Instance Method Detail
Draws the content of the buffer to the screen.
NOTE This should not be called concurrently.
Waits until a key has been pressed and returns it compactly as a symbol.
:up
if up arrow has been pressed.:down
if down arrow has been pressed.:left
if left arrow has been pressed.:right
if right arrow has been pressed.:enter
if enter has been pressed.:tab
if tab has been pressed.:backspace
if backspace has been pressed.:escape
if escape has been pressed.:ctrl_c
if Ctrl+C has been pressed.
If none of the above keys are pressed, the key is returned as-is.
NOTE Ctrl+C is caught by this method and will not be handled by the system.
Waits until a key has been pressed and returns it.
NOTE Ctrl+C is caught by this method and will not be handled by the system.
Inserts a line from x1, y1 to x2, y2 with color into the buffer.
Lime.line(0, 0, 5, 5)
▀▄
▀▄
▀▄
Lime.line(0, 0, 10, 5)
▀▀▄▄
▀▀▄▄
▀▀▄
This method uses Bresenham's line algorithm.
The order of the loop is as follows:
1. Executes the given block.
2. Draws the content of the buffer to the screen.
3. Clears the buffer.
Returns the key that is down in the moment this method is called compactly as a symbol or nil
if no key is down.
:up
if up arrow is down.:down
if down arrow is down.:left
if left arrow is down.:right
if right arrow is down.:enter
if enter is down.:tab
if tab is down.:backspace
if backspace is down.:escape
if escape is down.:ctrl_c
if Ctrl+C is down.
If none of the above keys are down, the key is returned as-is.
NOTE Ctrl+C is caught by this method and will not be handled by the system.
Returns the key that is down in the moment this method is called or nil
if no key is down.
NOTE Ctrl+C is caught by this method and will not be handled by the system.
Inserts a pixel at x, y with color into the buffer.
Lime.pixel(2, 2)
▀
Lime.pixel(2, 2)
Lime.pixel(2, 3)
█
Inserts char into the buffer at x, y.
Inserts string into the buffer at x, y.
Inserts string formatted into the buffer at x, y.
This method properly aligns each line in the string beneath each other.
Lime.printf("hello\nworld", 2, 2)
hello
world
Inserts string formatted into the buffer at x, y.
This method properly aligns each line in the string beneath each other.
Lime.printf("hello\nworld", 2, 2)
hello
world