Module: Punk::Human

Defined in:
lib/punkmaker/type/human.rb

Overview

make it a class - why? why not?

Constant Summary collapse

BASE_M =
Image.read( "#{Pixelart::Module::Punkmaker.root}/config/human-male4.png" )
BASE_F =
Image.read( "#{Pixelart::Module::Punkmaker.root}/config/human-female4.png" )

Class Method Summary collapse

Class Method Details

.base(gender: 'm') ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/punkmaker/type/human.rb', line 29

def self.base( gender: 'm' )
  base =  gender == 'm' ? BASE_M : BASE_F

  ## note: make a copy of base 
  punk = Image.new( base.width, base.height )  
  punk.compose!( base )  
  punk
end

.derive_color_map(color) ⇒ Object

todo/check:

add a derive_colors or dervice_skintones  method - why? why not?
  - change to name skintone_palette - why? why not?

def self.derive_skintone_colors( color or base ) ???



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/punkmaker/type/human.rb', line 102

def self.derive_color_map( color )
    color = Color.from_hex( color )  if color.is_a?( String )

    base = color

    hsl  = Color.to_hsl( color )
    pp hsl

    h, s, l = hsl
    h = h % 360   # make always positive (might be -50 or such)
    pp [h,s,l]

    ## sub one degree on hue on color wheel (plus +10% on lightness??)
    ## darker
    eyebrows = Color.from_hsl(
                   h,
                   s,
                   [0.05, l-0.1].max)

    color_map = {
       '#ead9d9'  =>   base,
       '#a58d8d'  =>   eyebrows,
    }
    color_map
end

.derive_shine(color) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/punkmaker/type/human.rb', line 78

def self.derive_shine( color )
  color = Color.from_hex( color )  if color.is_a?( String )

  hsv  = Color.to_hsv( color )
  # pp hsv

  h, s, v = hsv
  h = h % 360   # make always positive (might be -50 or such)
  ## pp [h,s,v]

  ## add extra saturation if v(alue) / brightness is max 1.0 - why? why not?
  sdiff = v >= 0.99 ? 0.25 : 0.15

  lighter =  Color.from_hsv( h, [0.0, s-sdiff].max, [v+0.1,1.0].min )  
  lighter
end

.make(color = nil, shine: true, eye_color: nil, gender: 'm') ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/punkmaker/type/human.rb', line 39

def self.make( color=nil,
               shine: true,
               eye_color: nil,
               gender: 'm'  )

  punk =  base( gender: gender )
  
  skintone = color ? parse_skintone( color ) : nil 
  if skintone    ## change skin tone (& eyebrows)?
    color_map = derive_color_map( skintone )  
    punk = punk.change_colors( color_map )
  end

  if eye_color    ## change eye color?
     eye_color = parse_eye_color( eye_color ) 
     if gender == 'm'
       punk[9,12]  = eye_color
       punk[14,12] = eye_color
     else
       punk[9,13] = eye_color
       punk[14,13] = eye_color
     end
  end

  if shine     ## add shine?
     # note: default shine color is white
     shine_color =   skintone ? derive_shine( skintone ) : 0xffffffff
     if gender == 'm'
       punk[9,7] = shine_color
       punk[8,8] = shine_color
     else 
       punk[9,9] = shine_color
    end   
  end

  punk
end

.parse_eye_color(color) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/punkmaker/type/human.rb', line 20

def self.parse_eye_color( color )
  if color.is_a?( String )
     Eyes[ color ] || Color.from_hex( color )
  else
     color
  end
end

.parse_skintone(color) ⇒ Object

lookup skintone by name or rgb(a) hex string or integer “true color”



12
13
14
15
16
17
18
# File 'lib/punkmaker/type/human.rb', line 12

def self.parse_skintone( color )   ##  lookup skintone by name or rgb(a) hex string or integer "true color"
  if color.is_a?( String ) 
     Skintone[ color ] || Color.from_hex( color )  
  else ## assume color is integer - assert - why? why not?
     color
  end
end