Class: Punkme::Image
- Inherits:
-
Pixelart::Image
- Object
- Pixelart::Image
- Punkme::Image
- Defined in:
- lib/punkme.rb
Instance Attribute Summary collapse
-
#accessories ⇒ Object
readonly
Returns the value of attribute accessories.
-
#gender ⇒ Object
readonly
Returns the value of attribute gender.
-
#skintone ⇒ Object
readonly
Returns the value of attribute skintone.
Class Method Summary collapse
-
.generate(skintone: SKINTONE_DARK, gender: 'm', hair: nil, hair_color: nil) ⇒ Object
change/rename generate to make - why? why not? or add/use alias - why? why not?.
Instance Method Summary collapse
- #add(*names) ⇒ Object
-
#initialize(img, gender:, skintone: nil, hair: nil, hair_color: nil) ⇒ Image
constructor
A new instance of Image.
Constructor Details
#initialize(img, gender:, skintone: nil, hair: nil, hair_color: nil) ⇒ Image
Returns a new instance of Image.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/punkme.rb', line 64 def initialize( img, gender:, skintone: nil, hair: nil, hair_color: nil ) @gender = gender @skintone = skintone @hair = hair @hair_color = hair_color @accessories = [] super( nil, nil, img ) ### fix Image#initialze to accept "raw" image only end |
Instance Attribute Details
#accessories ⇒ Object (readonly)
Returns the value of attribute accessories.
60 61 62 |
# File 'lib/punkme.rb', line 60 def accessories @accessories end |
#gender ⇒ Object (readonly)
Returns the value of attribute gender.
60 61 62 |
# File 'lib/punkme.rb', line 60 def gender @gender end |
#skintone ⇒ Object (readonly)
Returns the value of attribute skintone.
60 61 62 |
# File 'lib/punkme.rb', line 60 def skintone @skintone end |
Class Method Details
.generate(skintone: SKINTONE_DARK, gender: 'm', hair: nil, hair_color: nil) ⇒ Object
change/rename generate to make - why? why not?
or add/use alias - why? why not?
names (attributes) MUST go first -
check if possible after keyword args ???
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/punkme.rb', line 28 def self.generate( skintone: SKINTONE_DARK, gender: 'm', hair: nil, hair_color: nil ) skintone = Color.parse( skintone ) unless skintone.is_a?( Integer ) punk = if gender == 'm' Punk::Human.make( skintone, gender: 'm' ) else ## assume f/female Punk::Human.make( skintone, gender: 'f' ) end if hair hair_color = 'black' if hair_color.nil? img = if gender == 'm' Barbershop::Hair.make( hair, color: hair_color ) else ## assume f/female Hairsalon::Hair.make( hair, color: hair_color ) end punk.compose!( img ) end ## wrap as Punkme image (keeps metadata) - why? why not? new( punk.image, gender: gender, skintone: skintone, hair: hair, hair_color: hair_color ) end |
Instance Method Details
#add(*names) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/punkme.rb', line 77 def add( *names ) punk = Image.new( Pixelart::Image.new( width, height ).image, gender: @gender, skintone: @skintone ) punk.compose!( self ) ## add ourselves (that is, base punk) here ## add (optional) attributes names.each do |name| img = if gender == 'm' Punk::Sheet.find_by( name: name, gender: 'm', size: 'l' ) else Punk::Sheet.find_by( name: name, gender: 'f', size: 's' ) end punk.compose!( img ) @accessories << name end punk end |