Module: Punk::Hair
- Defined in:
- lib/punkmaker/hair.rb
Defined Under Namespace
Classes: Maker
Class Method Summary collapse
- .[](name) ⇒ Object
-
.colorize(hair, color:) ⇒ Object
method self.derive_color_map.
- .colors ⇒ Object
- .derive_color_map(color) ⇒ Object
Class Method Details
.[](name) ⇒ Object
8 |
# File 'lib/punkmaker/hair.rb', line 8 def self.[]( name ) colors.find_by( name: name ); end |
.colorize(hair, color:) ⇒ Object
method self.derive_color_map
59 60 61 62 63 |
# File 'lib/punkmaker/hair.rb', line 59 def self.colorize( hair, color: ) # "low-level" with no validity checks on hair image and passed in color (integer) color_map = derive_color_map( color ) hair.change_colors( color_map ) end |
.colors ⇒ Object
5 6 7 |
# File 'lib/punkmaker/hair.rb', line 5 def self.colors @colors ||= ColorBundle.read( './config/colors/hair.csv' ) end |
.derive_color_map(color) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 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 |
# File 'lib/punkmaker/hair.rb', line 12 def self.derive_color_map( color ) color = Color.from_hex( color ) if color.is_a?( String ) h,s,v = Color.to_hsv( color, include_alpha: false ) h = h % 360 ## make sure h(ue) is always positive!!! puts " #{[h,s,v].inspect}" # lighter - #2a2aff / rgb( 42 42 255) - hsl(240° 100% 58%) - hsv(240° 84% 100%) # - used in hair( frumpy, f/pigtails3, f/straight3, f/wild4, f/wild5 ) # lightest - #5454ff / rgb( 84 84 255) - hsl(240° 100% 66%) - hsv(240° 67% 100%) # - used in hair(mohawk thin) # darker - #0000dd / rgb( 0 0 221) - hsl(240° 100% 43%) - hsv(240° 100% 87%) # - used in hair(mohawk) ## todo/fix: make lighter/darker formula more "robust"/ better!!! if color == 0x000000ff # black # hsv( 0° 0% 0%) lighter = Color.from_hsv( h, 0.0, 0.16 ) lightest = Color.from_hsv( h, 0.0, 0.33 ) darker = Color.from_hsv( h, 0.0, 0.0 ) ## darker than black not possible ;-) elsif color == 0xe0e0e0ff # silver # hsv( 0° 0% 88%) lighter = Color.from_hsv( h, 0.0, 1.0 ) # white lightest = Color.from_hsv( h, 0.0, 1.0 ) # white darker = Color.from_hsv( h, 0.0, [0.0, v-0.13].max ) elsif color == 0xffffffff # white # hsv( 0° 0% 100%) lighter = Color.from_hsv( h, 0.0, [0.0, v-0.11].max ) # note: make darker lightest = Color.from_hsv( h, 0.0, 1.0 ) darker = Color.from_hsv( h, 0.0, [0.0, v-0.16].max ) else lighter = Color.from_hsv( h, [0.0, s-0.16].max, v ) lightest = Color.from_hsv( h, [0.0, s-0.33].max, v ) darker = Color.from_hsv( h, s, [0.0, v-0.13].max ) end color_map = { '0000ffff' => color, '2a2affff' => lighter, '5454ffff' => lightest, '0000ddff' => darker, } color_map end |