Class: Pixelart::ImagePalette8bit
Overview
or use Palette256 alias?
Constant Summary
Constants inherited from Image
Pixelart::Image::CHARS, Pixelart::Image::PALETTE8BIT, Pixelart::Image::RAINBOW_BLUE, Pixelart::Image::RAINBOW_GREEN, Pixelart::Image::RAINBOW_ORANGE, Pixelart::Image::RAINBOW_RED, Pixelart::Image::RAINBOW_VIOLET, Pixelart::Image::RAINBOW_YELLOW, Pixelart::Image::UKRAINE_BLUE, Pixelart::Image::UKRAINE_YELLOW
Instance Method Summary collapse
-
#initialize(colors, size: 1, spacing: nil) ⇒ ImagePalette8bit
constructor
A new instance of ImagePalette8bit.
Methods inherited from Image
#[], #[]=, #_change_colors!, #_parse_color_map, #_parse_colors, blob, #blur, calc_sample_steps, calc_stripes, #change_colors, #change_palette8bit, #circle, #compose!, convert, #crop, #flip_horizontally, #grayscale, #height, #image, inherited, #invert, #led, #left, #mirror, parse, parse_base64, parse_colors, parse_pixels, parse_pixels_strict, #pixels, #rainbow, read, #rotate_clockwise, #rotate_counter_clockwise, #sample, #sample_debug, #save, #silhouette, #sketch, #spots, #spots_hidef, #stripes_horizontal, subclasses, #to_blob, #transparent, #ukraine, #width, #zoom
Constructor Details
#initialize(colors, size: 1, spacing: nil) ⇒ ImagePalette8bit
Returns a new instance of ImagePalette8bit.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pixelart/misc.rb', line 5 def initialize( colors, size: 1, spacing: nil ) ## todo/check: change size arg to pixel or such? better name/less confusing - why? why not? ## todo/check: assert colors MUST have 256 colors!!!! ## use a "smart" default if no spacing set ## 0 for for (pixel) size == 1 ## 1 for the rest spacing = size == 1 ? 0 : 1 if spacing.nil? img = ChunkyPNG::Image.new( 32*size+(32-1)*spacing, 8*size+(8-1)*spacing ) colors =colors.map {|color| Color.parse( color ) } colors.each_with_index do |color,i| y,x = i.divmod( 32 ) if size > 1 size.times do |n| size.times do |m| img[ x*size+n+spacing*x, y*size+m+spacing*y] = color end end else img[x,y] = color end end super( img.width, img.height, img ) end |