Class: Cryptopunks::Image

Inherits:
Pixelart::Image
  • Object
show all
Defined in:
lib/cryptopunks.rb,
lib/cryptopunks.rb,
lib/cryptopunks.rb,
lib/cryptopunks/image.rb

Constant Summary collapse

Composite =
ImageComposite

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial = nil, design: nil, colors: nil) ⇒ Image

keep design & colors keyword args in c’tor here

or use parse() like in pixelart - why? why not?


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cryptopunks/image.rb', line 17

def initialize( initial=nil, design: nil,
                             colors: nil )
    if initial
      ## pass image through as-is

      img = initial
    else
      ## note: unwrap inner image before passing on to super c'tor

      img = Pixelart::Image.parse( design, colors: colors ).image
    end

    super( img.width, img.height, img )
end

Class Method Details

.generate(*values, style: nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cryptopunks.rb', line 53

def self.generate( *values, style: nil )

#####  add style option / hack - why? why not?

  if style
    values =  if style.downcase.index( 'natural') && style.downcase.index( '2')
            ["#{values[0]} (N2)"] + values[1..-1]
         elsif style.downcase[0] == 'n'  ## starting with n - always assume natural(s)

            ## auto-add (N) for Natural to archetype

            ["#{values[0]} (N)"] + values[1..-1]
         else
           puts "!! ERROR - unknown punk style #{style}; sorry"
           exit 1
         end
  end


###### hack for black&white

##   auto-add b&w (black&white) to all attribute names e.g.

##      Eyes   =>  Eyes B&W

##      Smile  =>  Smile B&W

##      ....


archetype_key =  Generator.normalize_key( values[0] )
if archetype_key.end_with?( 'bw' ) ||  ## e.g. B&W

   archetype_key.end_with?( '1bit')    ## e.g. 1-Bit or 1Bit


   values = [values[0]] + values[1..-1].map do |attribute|
      attribute_key = Generator.normalize_key( attribute )
      if ['wildhair'].include?( attribute_key )   ## pass through known b&w attributes by "default"

          attribute
      elsif attribute_key.index( "black" )
          attribute ## pass through as-is

      else
          "#{attribute} B&W"
      end
  end

  pp values
    end


    # note: female mouth by default has "custom" colors (not black)

    #          for every 1/2/3/4 (human) skin tone and for zombie

    #   auto-"magically" add mapping

    #

    #  todo/check/fix - add more "contraints"

    #    for mapping to only kick-in for "basic" versions

    #      and not "colored" e.g. golden and such - why? why not?

    #

    #    move this mapping here to "post-lookup" processing

    #   to get/incl. more "meta" attribute info  - why? why not?

    if archetype_key.index( 'female1' ) ||
  archetype_key.index( 'female2' ) ||
  archetype_key.index( 'female3' ) ||
  archetype_key.index( 'female4' ) ||
  archetype_key.index( 'zombiefemale' )

 values = [values[0]] + values[1..-1].map do |attribute|
   attribute_key = Generator.normalize_key( attribute )

   if attribute_key == 'smile' || attribute_key == 'frown'
     attribute +=   if    archetype_key.index( 'zombiefemale' ) then ' Zombie'
                    elsif archetype_key.index( 'female1' )      then ' 1'
                    elsif archetype_key.index( 'female2' )      then ' 2'
                    elsif archetype_key.index( 'female3' )      then ' 3'
                    elsif archetype_key.index( 'female4' )      then ' 4'
                    else
                      puts "!! ERROR - smile or frown (mouth expression) not supported for archetype:"
                      pp values
                      exit 1
                    end
   end
   attribute
 end
    end

  img = Cryptopunks.generator.generate( *values, style: style )
  ## note: unwrap inner image before passing on to c'tor (requires ChunkyPNG image for now)

  new( img.image )
end

.read(path) ⇒ Object

convenience helper



7
8
9
10
# File 'lib/cryptopunks/image.rb', line 7

def self.read( path )   ## convenience helper

  img = ChunkyPNG::Image.from_file( path )
  new( img )
end