Module: Punk::Alien

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

Overview

make it a class - why? why not?

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.base(gender: 'm') ⇒ Object



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

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/punkmaker/type/alien.rb', line 72

def self.derive_color_map( color )

# 2 pixels #f1ffff / rgb(241 255 255) - hsl(180° 100%  97%)  - lighter
# 125 pixels #c8fbfb / rgb(200 251 251) - hsl(180°  86%  88%)   - base (use as base)
#  6 pixels #9be0e0 / rgb(155 224 224) - hsl(180°  53%  74%)   - darker
#  2 pixels #75bdbd / rgb(117 189 189) - hsl(180°  35%  60%)  - darkest
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]


darker = Color.from_hsl(
  h,
  [0.0,s-0.05].max,
  [0.0,l-0.10].max)

darkest = Color.from_hsl(
  h,
  [0.0,s-0.10].max,
  [0.0,l-0.20].max)


color_map = {
    '#c8fbfb' =>  base,
    '#9be0e0' => darker,
    '#75bdbd' => darkest,
}

color_map
end

.derive_shine(color) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/punkmaker/type/alien.rb', line 46

def self.derive_shine( color )
## was before - reuse old formula- why? why not?
## todo/check - check "formula" used in skintones script for humans!!!
## lighter = Color.from_hsl(
##   (h+1)%360,   # todo/check: make lighter by -1 on hue? or +1????
##   [1.0,s+0.10].min,
##   [1.0,l+0.25].min)

  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.35 : 0.25

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

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/punkmaker/type/alien.rb', line 21

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

  punk = base( gender: gender )  ## get base image (as a copy to modify)
               
  if color    ## change skin tone (& eyebrows)?
    color_map = derive_color_map( color )  
    punk = punk.change_colors( color_map )
  end

 
  if shine
   shine_color =    color ? derive_shine( color ) : 0xf1ffffff
   if gender == 'm'
     punk[9,7] = shine_color
     punk[8,8] = shine_color
   else 
     punk[9,9] = shine_color
   end
  end   
  punk
end