struct Lime::Drawables::Pixels

Overview

A drawable sequence of pixels.

Defined in:

lime/drawables.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(path : String, x : Int32, y : Int32) #

Initializes new Pixels from an image.

path must lead to an PNG-encoded image.


[View source]
def self.new(x : Int32, y : Int32, color_characters : String) #

Initializes new Pixels from a string.

Iterates through every character of color_characters and every time a color character is found, it's replaced with its color.

Available color characters are:

  • '1': default
  • '0': black
  • '9': dark gray
  • '6': light gray
  • 'w': white
  • 'r': red
  • 'g': green
  • 'b': blue
  • 'y': yellow
  • 'm': magenta
  • 'c': cyan
  • 'R': light red
  • 'G': light green
  • 'B': light blue
  • 'Y': light yellow
  • 'M': light magenta
  • 'C': light cyan

Comments are also allowed in the string.

Example string:

# A flower:
 RRR
RYYYR # Head
 RRR
  g
G g G
GGgGG # Stem
 GgG
  g

becomes:

flower

Raises Error when an invalid color character is found in color_characters.


[View source]

Instance Method Detail

def draw #

Inserts the pixels into the buffer.


[View source]
def height : Int32 #

[View source]
def map(&) #

Invokes the given block for each of the pixels, replacing the pixel with the pixel returned by the block. The block must return a Tuple(UInt8, UInt8, UInt8).

# Invert colors of an image:
image.map { |pixel| {255u8 - pixel.red, 255u8 - pixel.green, 255u8 - pixel.blue} }

[View source]
def width : Int32 #

[View source]
def x : Int32 #

[View source]
def x=(x : Int32) #

[View source]
def y : Int32 #

[View source]
def y=(y : Int32) #

[View source]