module Lime
Overview
The main module of lime.
All x and y arguments are zero-based.
An IndexError will be raised if:
- An
xargument is greater thanWindow.width. - An
xargument is lower than-Window.width_cells. - A
yargument is greater thanWindow.height. - A
yargument 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
nilif no key is down. -
#peek_key_raw : String | Nil
Returns the key that is down in the moment this method is called or
nilif 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.
:upif up arrow has been pressed.:downif down arrow has been pressed.:leftif left arrow has been pressed.:rightif right arrow has been pressed.:enterif enter has been pressed.:tabif tab has been pressed.:backspaceif backspace has been pressed.:escapeif escape has been pressed.:ctrl_cif 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.
:upif up arrow is down.:downif down arrow is down.:leftif left arrow is down.:rightif right arrow is down.:enterif enter is down.:tabif tab is down.:backspaceif backspace is down.:escapeif escape is down.:ctrl_cif 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