Module: Punk::Ape

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

Overview

make it a class - why? why not?

Constant Summary collapse

BASE_M =
Image.read( "#{Pixelart::Module::Punkmaker.root}/config/ape-male.png" )
BASE_F =
Image.read( "#{Pixelart::Module::Punkmaker.root}/config/ape-female.png" )

Class Method Summary collapse

Class Method Details

.derive_color_map(color) ⇒ Object



25
26
27
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
58
59
60
# File 'lib/punkmaker/type/ape.rb', line 25

def self.derive_color_map( color )
    color = Color.from_hex( color )  if color.is_a?( String )
   
    darkest = 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]

  darker = Color.from_hsl(
    h,
    s,
    [1.0,l+0.05].min)

  light = Color.from_hsl(
     (h+1)%360,
     [1.0,s+0.10].min,
     [1.0,l+0.20].min)

  lighter = Color.from_hsl(
    (h+1)%360,
    [1.0,s+0.20].min,
    [1.0,l+0.35].min)

  color_map = {
      '#352410' =>  darkest,  # darkest  - 56 pixels (base!!)
      '#6a563f' => darker,    # darker   -  4 pixels
      '#856f56' => light,     # light    - 63 pixels
      '#a98c6b' => lighter    # lighter
  }

  color_map
end

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/punkmaker/type/ape.rb', line 9

def self.make( color=nil,
                  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 )
   
   if color    
     color_map = derive_color_map( color )  
     punk = punk.change_colors( color_map )
   end

   punk
end