Class: MinecraftAvatars::FlatCharacter
- Defined in:
- lib/minecraft-avatars/flat_character.rb
Instance Attribute Summary
Attributes inherited from BaseImage
Instance Method Summary collapse
-
#initialize(player_name, height = 64, accessories = true) ⇒ FlatCharacter
constructor
A new instance of FlatCharacter.
Methods inherited from BaseImage
Constructor Details
#initialize(player_name, height = 64, accessories = true) ⇒ FlatCharacter
Returns a new instance of FlatCharacter.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/minecraft-avatars/flat_character.rb', line 8 def initialize(player_name, height=64, accessories=true) throw InvalidResolutionException unless (height & (height-1)) == 0 width = height/2 skin = RawSkin.new(player_name) self.chunky = ChunkyPNG::Image.new(16, 32, ChunkyPNG::Color::TRANSPARENT) self.chunky.compose!(skin.sections[:head_front], 4, 0) self.chunky.compose!(skin.sections[:head_accessory], 4, 0) if accessories self.chunky.compose!(skin.sections[:body_front], 4, 8) self.chunky.compose!(skin.sections[:leg_front], 4, 20) self.chunky.compose!(skin.sections[:leg_front].mirror, 8, 20) self.chunky.compose!(skin.sections[:arm_front], 0, 8) self.chunky.compose!(skin.sections[:arm_front].mirror, 12, 8) self.chunky.resample_nearest_neighbor!(width, height) end |