mooncats 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mooncats/image.rb +85 -19
- data/lib/mooncats/structs.rb +31 -0
- data/lib/mooncats/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0251649c9c064b96c7c52770bb8245b99d5a67f7885c22a256e41bef7a6e7837'
|
4
|
+
data.tar.gz: 532761a4f6d3f46c6342c7a527427c9867c228cbc58402d9852bfd63e53f3b6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db123a1e67ad1163dff0c3e9949243ecb24c0869a2aeb9e3e2e289e3c448febbf2b00103ba7f06cde707a0b7048bc004b975463816a6098a97615fa90d5d84e5
|
7
|
+
data.tar.gz: 57a4f6fae3953ad6fa2a55b1d4bf11ce3755012033acddd4f480c30ec7a41b51c9fe8b2f06f1ece6a8e67ba19fe2591ed7d2273e8cc8b00306f6bcc6d2c95581
|
data/README.md
CHANGED
@@ -115,7 +115,7 @@ And so on.
|
|
115
115
|
Yes, you can mint mooncats in your own scripts
|
116
116
|
and much more.
|
117
117
|
See the
|
118
|
-
[**Programming
|
118
|
+
[**Programming MoonCats & MarsCats Step-by-Step Booklet / Guide »**](https://github.com/cryptocopycats/programming-mooncats)
|
119
119
|
|
120
120
|
|
121
121
|
|
data/lib/mooncats/image.rb
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
|
2
2
|
module Mooncats
|
3
|
+
|
4
|
+
|
5
|
+
class Color ## convenience helper to "abstract" ChunkyPNG usage away in "outside" (not internal) sample code
|
6
|
+
def self.to_hex(color, include_alpha: false)
|
7
|
+
if include_alpha
|
8
|
+
'#%08x' % color
|
9
|
+
else
|
10
|
+
'#%06x' % [color >> 8]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.rgb_to_hsl( r, g, b )
|
15
|
+
rgb = ChunkyPNG::Color.rgb( r, g, b )
|
16
|
+
hsl = ChunkyPNG::Color.to_hsl( rgb )
|
17
|
+
hsl
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_hsl( h, s, l )
|
21
|
+
ChunkyPNG::Color.from_hsl( h, s, l )
|
22
|
+
end
|
23
|
+
end # class Color
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
3
28
|
class Image
|
4
29
|
|
5
30
|
|
@@ -20,9 +45,10 @@ def self.generate( id, zoom: 1 )
|
|
20
45
|
COLORS_GENESIS_BLACK
|
21
46
|
end
|
22
47
|
else
|
23
|
-
derive_palette( meta.r,
|
24
|
-
meta.g,
|
25
|
-
|
48
|
+
derive_palette( r: meta.r,
|
49
|
+
g: meta.g,
|
50
|
+
b: meta.b,
|
51
|
+
invert: meta.invert? )
|
26
52
|
end
|
27
53
|
|
28
54
|
new( design: design,
|
@@ -37,7 +63,6 @@ end
|
|
37
63
|
|
38
64
|
|
39
65
|
|
40
|
-
|
41
66
|
def initialize( design: 0,
|
42
67
|
colors: COLORS_GENESIS_WHITE,
|
43
68
|
zoom: 1 )
|
@@ -95,21 +120,30 @@ def image() @cat; end
|
|
95
120
|
|
96
121
|
##################
|
97
122
|
# (static) helpers
|
98
|
-
def self.derive_palette( r, g, b
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
123
|
+
def self.derive_palette( r: nil, g: nil, b: nil,
|
124
|
+
hue: nil,
|
125
|
+
invert: false )
|
126
|
+
|
127
|
+
if hue
|
128
|
+
## pass through as is 1:1
|
129
|
+
else ## assume r, g, b
|
130
|
+
## note: Color.rgb returns an Integer (e.g. 34113279 - true color or just hex rgba or?)
|
131
|
+
rgb = ChunkyPNG::Color.rgb( r, g, b )
|
132
|
+
|
133
|
+
# to_hsl(color, include_alpha = false) ⇒ Array<Fixnum>[0], ...
|
134
|
+
# Returns an array with the separate HSL components of a color.
|
135
|
+
hsl = ChunkyPNG::Color.to_hsl( rgb )
|
136
|
+
#=> [237, 0.9705882352941178, 0.26666666666666666]
|
137
|
+
|
138
|
+
# h = hsl[0]
|
139
|
+
# s = hsl[1]
|
140
|
+
# l = hsl[2]
|
141
|
+
|
142
|
+
hue = hsl[0]
|
143
|
+
end
|
144
|
+
|
145
|
+
hx = hue % 360
|
146
|
+
hy = (hue + 320) % 360
|
113
147
|
#=> e.g. hx: 237, hy: 197
|
114
148
|
|
115
149
|
c1 = ChunkyPNG::Color.from_hsl( hx, 1, 0.1 )
|
@@ -148,6 +182,38 @@ def parse_color( color )
|
|
148
182
|
raise ArgumentError, "unknown color format; cannot parse - expected rgb hex string e.g. d3d3d3"
|
149
183
|
end
|
150
184
|
end
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
class Bar ## (nested) class inside Image (e.g. Image::Bar)
|
189
|
+
## make a color bar
|
190
|
+
def initialize( colors:, zoom: 24 )
|
191
|
+
@bar = ChunkyPNG::Image.new( colors.size*zoom,
|
192
|
+
zoom,
|
193
|
+
ChunkyPNG::Color::WHITE ) # why? why not?
|
194
|
+
|
195
|
+
colors.each_with_index do |color,i|
|
196
|
+
zoom.times do |x|
|
197
|
+
zoom.times do |y|
|
198
|
+
@bar[x+zoom*i,y] = color
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end # def initialize
|
203
|
+
|
204
|
+
#####
|
205
|
+
# (image) delegates
|
206
|
+
## todo/check: add some more??
|
207
|
+
def save( path, constraints = {} )
|
208
|
+
@bar.save( path, constraints )
|
209
|
+
end
|
210
|
+
|
211
|
+
def width() @bar.width; end
|
212
|
+
def height() @bar.height; end
|
213
|
+
|
214
|
+
## return image ref - use a different name - why? why not?
|
215
|
+
def image() @bar; end
|
216
|
+
end # (nested) class Bar
|
151
217
|
end # class Image
|
152
218
|
|
153
219
|
|
data/lib/mooncats/structs.rb
CHANGED
@@ -90,6 +90,35 @@ class Metadata
|
|
90
90
|
def pattern() k % 64; end ## treat facing left|right as the same
|
91
91
|
|
92
92
|
|
93
|
+
def hue
|
94
|
+
@hue ||= begin
|
95
|
+
rgb = ChunkyPNG::Color.rgb( r, g, b )
|
96
|
+
hsl = ChunkyPNG::Color.to_hsl( rgb )
|
97
|
+
hsl[0]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def color
|
102
|
+
case hue
|
103
|
+
when 0..29 then 'Red'
|
104
|
+
when 30..59 then 'Orange'
|
105
|
+
when 60..89 then 'Yellow'
|
106
|
+
when 90..119 then 'Chartreuse'
|
107
|
+
when 120..149 then 'Green'
|
108
|
+
when 150..179 then 'Lime Green'
|
109
|
+
when 180..209 then 'Cyan'
|
110
|
+
when 210..239 then 'Sky Blue'
|
111
|
+
when 240..269 then 'Blue'
|
112
|
+
when 270..299 then 'Purple'
|
113
|
+
when 300..329 then 'Magenta'
|
114
|
+
when 330..359 then 'Fuscia'
|
115
|
+
else
|
116
|
+
puts "!! ERROR - unexpected hue (in degress); got #{hue} - expected 0 to 359"
|
117
|
+
exit 1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
93
122
|
def design
|
94
123
|
@design ||= Design.new( k % 128 )
|
95
124
|
end
|
@@ -116,6 +145,8 @@ class Metadata
|
|
116
145
|
when :b then b
|
117
146
|
when :rgb then rgb
|
118
147
|
when :invert then invert?
|
148
|
+
when :hue then hue
|
149
|
+
when :color then color
|
119
150
|
when :design then design.to_i
|
120
151
|
when :pattern then pattern
|
121
152
|
when :facing then facing
|
data/lib/mooncats/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mooncats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|