lime
lime
A library for drawing graphics on the console screen
Features
- Drawing of
- text
- lines
- rectangles
- filled rectangles
- circles
- PNG images
- Management of the window
- Controlling of the console cursor
- Keyboard and mouse pointer input
Installation
Add the dependency to your shard.yml
:
dependencies:
lime:
github: r00ster91/lime
Then run shards install
Example
Three lights flashing repeatedly in order:
require "lime"
# Create the lights:
# They are red, green and blue rectangles with doubled lines
light1 = Rectangle.new(
x: 2, y: 1,
width: 5, height: 3,
type: Double, color: :red
)
light2 = Rectangle.new(8, 1, 5, 3, Double, :green)
light3 = Rectangle.new(14, 1, 5, 3, Double, :blue)
# The light that is currently on
light = 1
loop do
if light == 3
light = 1
else
light += 1
end
case light
when 1
light1.color = :light_red
light2.color = :green
light3.color = :blue
when 2
light1.color = :red
light2.color = :light_green
light3.color = :blue
when 3
light1.color = :red
light2.color = :green
light3.color = :light_blue
end
# Insert the lights into the buffer:
light1.draw
light2.draw
light3.draw
# Draw the content of the buffer to the screen:
Lime.draw
# Clear the buffer (not the screen) so we have room for the next frame:
Lime.clear
# You can use `Lime.loop` instead of a normal loop to skip the above two steps
# A short delay:
sleep 0.5
end
In the top left corner we can see:
See examples
for more examples.
For technical information about lime, see src/README.md
.
Contributing
- Fork it (https://github.com/r00ster91/lime/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Install required shards (
shards install
) - Make your changes
- Format the code (
crystal tool format
) - Make sure the specs compile (
crystal spec -v
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- r00ster - creator and maintainer