Class: Cryptopunks::Image
- Inherits:
-
Pixelart::Image
- Object
- Pixelart::Image
- Cryptopunks::Image
- Defined in:
- lib/cryptopunks/composite.rb,
lib/cryptopunks.rb,
lib/cryptopunks.rb,
lib/cryptopunks/image.rb
Overview
nest Composite inside Image - why? why not?
Defined Under Namespace
Classes: Composite
Class Method Summary collapse
- .generate(*values) ⇒ Object
-
.read(path) ⇒ Object
convenience helper.
Instance Method Summary collapse
-
#initialize(initial = nil, design: nil, colors: nil) ⇒ Image
constructor
A new instance of Image.
Constructor Details
#initialize(initial = nil, design: nil, colors: nil) ⇒ Image
52 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 |
# File 'lib/cryptopunks/image.rb', line 52 def initialize( initial=nil, design: nil, colors: nil ) if initial ## pass image through as-is img = initial else ## todo/fix: ## move design code into design class!!! ## for now assume design is a string ## split into parts ## original/alien-male or original@alien-male ## more/alien-female or more@alien-female ## original/human-male+darker or original@human-male!darker ???? ## human-male!darker ????? ## keep @ as separator too - why? why not? parts = design.split( %r{[@/]} ) parts.unshift( '*' ) if parts.size == 1 ## assume "all-in-one" series (use * as name/id/placeholder) series_key = parts[0] design_composite = parts[1] ## todo/check - find a way for unambigious (color) variant key ## use unique char e.g. +*!# or such more_parts = design_composite.split( %r{[!+]} ) design_key = more_parts[0] variant_key = more_parts[1] ## color variant for now (for humans) e.g. lighter/light/dark/darker series = if ['*','**','_','__'].include?( series_key ) DESIGNS ## use all-series-in-one collection else case series_key when 'original' then DESIGNS_ORIGINAL when 'more' then DESIGNS_MORE else raise ArgumentError, "unknown design series >#{series_key}<; sorry" end end design = series[ design_key ] raise ArgumentError, "unknow design >#{design_key}< in series >#{series_key}<; sorry" if design.nil? if colors.nil? ## try to auto-fill in colors ## note: (auto-)remove _male,_female qualifier if exist colors_key = design_key.sub( '-male', '' ).sub( '-female', '' ) colors = COLORS[ colors_key ] ## allow / support color scheme variants (e.g. lighter/light/dark/darker) etc. if colors.is_a?(Hash) if variant_key colors = colors[ variant_key ] raise ArgumentError, "no colors defined for variant >#{variant_key}< for design >#{design_key}< in series >#{series_key}<; sorry" if colors.nil? else ## note: use (fallback to) first color scheme if no variant key present colors = colors[ colors.keys[0] ] end end raise ArgumentError, "no (default) colors defined for design >#{design_key}< in series >#{series_key}<; sorry" if colors.nil? end ## 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) ⇒ Object
43 44 45 46 47 |
# File 'lib/cryptopunks.rb', line 43 def self.generate( *values ) img = Cryptopunks.generator.generate( *values ) ## note: unwrap inner image before passing on to c'tor (requires ChunkyPNG image for now) new( img.image ) end |
.read(path) ⇒ Object
convenience helper
46 47 48 49 |
# File 'lib/cryptopunks/image.rb', line 46 def self.read( path ) ## convenience helper img = ChunkyPNG::Image.from_file( path ) new( img ) end |