Skip to content

Latest commit

 

History

History
181 lines (113 loc) · 4.08 KB

README.md

File metadata and controls

181 lines (113 loc) · 4.08 KB

Spritesheet

Usage

Pack(age)-Up Spritesheet(s)

Let's try some punk readymades with "stand-alone" images:

i/bart_simpson.png
  dante_alighieri.png
  galileo_galilei.png
  mao_zedong.png
  snoop_dogg.png
  terminator.png
  the_grinch.png
  the_joker.png
  the_mask.png
  william_shakespeare.png

and with a attributes (definition) in the comma-separated values (.csv) format:

path, category, name, more_names


william_shakespeare.png,,  William Shakespeare,   Will | Will Shakespeare | Shakespeare
dante_alighieri.png,,  Dante Alighieri,   Dante

galileo_galilei.png,,  Galileo Galilei,   Galileo | Galilei

mao_zedong.png,,       Mao Zedong,        Mao

snoop_dogg.png,,       Snoop Dogg,        Snoop

bart_simpson.png,,     Bart Simpson,     Bart | Simpson
terminator.png,,       Terminator

...

(Source: spritesheet/attributes.csv)

require 'spritesheet'

attributes_path  =  './attributes.csv'
image_dir        =  './i'


sheet = Pixelart::Spritesheet.pack( attributes_path,
                                      dir: image_dir,
                                      width: 24,
                                      height: 24 )

pp sheet.records
puts "  #{sheet.records.size} record(s)"

sheet.export( "./spritesheet_pack.csv" )

sheet.image.save( "./spritesheet_pack.png" )
sheet.image.zoom(4).save( "./[email protected]" )

And use spritsheet reference for image generation and lookup:

sheet.image[0].zoom(4).save( "./[email protected]" )
sheet.image[1].zoom(4).save( "./[email protected]" )

will      = sheet.find_by( name: 'Will' )
galileo   = sheet.find_by( name: 'Galileo' )

will.save( "./will.png" )
will.zoom(4).save( "./[email protected]" )

galileo.save( "./galileo.png" )
galileo.zoom(4).save( "./[email protected]" )

Read (Pre-Packaged-Up) Spritesheet(s)

Let's try punk doge shiba inus in the 24x24px format.

(Source: config/spritesheet.png)

id, category, name, more_names
0, , classic,
1, , dark,
2, , zombie,
3, , alien,
4, , crazyhair,
5, , beanie,
6, , cap,
7, , capforward,
8, , cowboyhat,
9, , fedora,
...

(Source: config/spritesheet.csv)

require 'spritesheet'


image_path =  './config/spritesheet.png'
meta_path  =  './config/spritesheet.csv'

pp recs = Pixelart::Spritesheet.read_records( meta_path )
puts "  #{recs.size} record(s)"
pp recs = Pixelart::Spritesheet.read_meta( meta_path )
puts "  #{recs.size} record(s)"

sheet = Pixelart::Spritesheet.read( image_path,
                                    meta_path,
                                    width: 24,
                                    height: 24 )

pp sheet.records
puts "  #{sheet.records.size} record(s)"
pp sheet.meta
puts "  #{sheet.meta.size} record(s)"


sheet.image.save( "./spritesheet.png" )

sheet.image[0].zoom(4).save( "./[email protected]" )
sheet.image[1].zoom(4).save( "./[email protected]" )

classic = sheet.find_by( name: 'Classic' )
alien   = sheet.find_by( name: 'Alien' )

classic.save( "./classic.png" )
classic.zoom(4).save( "./[email protected]" )

alien.save( "./alien.png" )
alien.zoom(4).save( "./[email protected]" )


classic = sheet[ 'Classic' ]
alien   = sheet[ 'Alien' ]

classic.save( "./classic-ii.png" )
classic.zoom(4).save( "./[email protected]" )

alien.save( "./alien-ii.png" )
alien.zoom(4).save( "./[email protected]" )

Questions? Comments?

Post them over at the Help & Support page. Thanks.