pixelart 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +6 -0
- data/README.md +246 -0
- data/Rakefile +30 -0
- data/lib/pixelart.rb +119 -0
- data/lib/pixelart/version.rb +22 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 61a062dde7cebbcee3dfcf1f39e4ff384961bd773736f54c4959efc8d7c0a768
|
4
|
+
data.tar.gz: 0d533bfef5d9b4cc13c3323a64acba128a39ba0d97d5c87748033c7c2f2ceba6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dccdefa4552f08db7b118f63e6d33d9c0925ccd05bb0b4b6b92e5f419400ad313837e0c38afa9d74a7e8dd9a39bd8919ad4069563ff35901f8f1d18e877c035
|
7
|
+
data.tar.gz: fc33580f828311ffc4f73b329f2e22d93d387dc7d3b7146aa15d0045d048289860d4639469479fad057f6c3a1ca49124db474311540984a8f7ddef7ed00a172e
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
# Pixel Art
|
2
|
+
|
3
|
+
pixelart - mint your own pixel art images off chain using any design (in ascii text) in any colors; incl. 2x/4x/8x zoom for bigger sizes
|
4
|
+
|
5
|
+
|
6
|
+
* home :: [github.com/cryptocopycats/mooncats](https://github.com/cryptocopycats/mooncats)
|
7
|
+
* bugs :: [github.com/cryptocopycats/mooncats/issues](https://github.com/cryptocopycats/mooncats/issues)
|
8
|
+
* gem :: [rubygems.org/gems/pixelart](https://rubygems.org/gems/pixelart)
|
9
|
+
* rdoc :: [rubydoc.info/gems/pixelart](http://rubydoc.info/gems/pixelart)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Let's use the mooncat design #0 (Standing·Smile·Solid·Left)
|
16
|
+
in the original 21×17 pixel format in ascii text:
|
17
|
+
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'pixelart'
|
21
|
+
|
22
|
+
pixels =<<PIXELS
|
23
|
+
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0
|
24
|
+
0 0 0 0 0 0 0 0 0 0 0 1 3 1 0 0 0 1 3 1 0
|
25
|
+
0 0 0 0 0 0 0 0 0 0 0 1 5 3 1 1 1 3 5 1 0
|
26
|
+
0 1 1 1 0 0 0 0 0 0 1 1 3 3 3 3 3 3 3 1 1
|
27
|
+
0 1 3 1 0 0 0 0 0 0 1 3 3 3 3 3 3 3 3 3 1
|
28
|
+
1 3 1 1 0 1 1 1 1 1 1 3 3 1 3 3 3 1 3 3 1
|
29
|
+
1 3 1 0 1 1 3 3 3 3 1 3 3 3 3 3 3 3 3 3 1
|
30
|
+
1 3 1 0 1 3 3 3 3 3 1 3 3 4 3 5 3 4 3 3 1
|
31
|
+
1 3 1 1 1 3 3 3 3 3 1 3 3 3 4 3 4 3 3 3 1
|
32
|
+
1 1 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 0
|
33
|
+
0 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 0 0
|
34
|
+
0 0 0 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 0 0
|
35
|
+
0 0 0 1 1 3 3 3 1 4 4 4 1 3 3 3 3 3 1 0 0
|
36
|
+
0 0 0 0 1 1 3 3 3 1 4 1 3 3 1 3 3 1 0 0 0
|
37
|
+
0 0 0 0 0 1 1 3 3 1 4 1 3 1 1 3 1 0 0 0 0
|
38
|
+
0 0 0 0 0 0 1 1 3 5 1 1 5 1 1 5 1 0 0 0 0
|
39
|
+
0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0
|
40
|
+
PIXELS
|
41
|
+
```
|
42
|
+
|
43
|
+
And let's use the genesis white color scheme - super rare only 48 exist in the official MoonCatRescue blockchain contract state storage ;-):
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
colors = [
|
47
|
+
'#555555', # color 1
|
48
|
+
'#d3d3d3', # color 2
|
49
|
+
'#ffffff', # color 3
|
50
|
+
'#aaaaaa', # color 4
|
51
|
+
'#ff9999' # color 5
|
52
|
+
]
|
53
|
+
```
|
54
|
+
|
55
|
+
Note: The color 0 (transparent) is auto-magically added / defined.
|
56
|
+
|
57
|
+
|
58
|
+
And let's mint a mooncat image:
|
59
|
+
|
60
|
+
``` ruby
|
61
|
+
img = Pixelart::Image.new( pixels, colors: colors )
|
62
|
+
img.save( './i/mooncat_white.png' )
|
63
|
+
```
|
64
|
+
|
65
|
+
And let's try a 3x zoom factor:
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
img = Pixelart::Image.new( pixels, colors: colors, zoom: 3 )
|
69
|
+
img.save( './i/mooncat_white-3x.png' )
|
70
|
+
```
|
71
|
+
|
72
|
+
Voila!
|
73
|
+
|
74
|
+
![](i/mooncat_white.png)
|
75
|
+
![](i/mooncat_white-3x.png)
|
76
|
+
|
77
|
+
|
78
|
+
Let's change the colors to use the genesis black color scheme:
|
79
|
+
|
80
|
+
``` ruby
|
81
|
+
colors = [
|
82
|
+
'#555555', # color 1
|
83
|
+
'#222222', # color 2
|
84
|
+
'#111111', # color 3
|
85
|
+
'#bbbbbb', # color 4
|
86
|
+
'#ff9999' # color 5
|
87
|
+
]
|
88
|
+
```
|
89
|
+
|
90
|
+
And let's start minting:
|
91
|
+
|
92
|
+
``` ruby
|
93
|
+
img = Pixelart::Image.new( pixels, colors: colors )
|
94
|
+
img.save( './i/mooncat_black.png' )
|
95
|
+
|
96
|
+
img = Pixelart::Image.new( pixels, colors: colors, zoom: 3 )
|
97
|
+
img.save( './i/mooncat_black-3x.png' )
|
98
|
+
```
|
99
|
+
|
100
|
+
Voila! Black is the new White!
|
101
|
+
|
102
|
+
![](i/mooncat_black.png)
|
103
|
+
![](i/mooncat_black-3x.png)
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
## Yes, You Can - Use Your Own Pixel Designs
|
109
|
+
|
110
|
+
Let's use the Darth Vader pixel art originally designed by
|
111
|
+
Aral Tasher in CSS. See the [online demo »](https://codepen.io/araltasher/pen/ajdzNE)
|
112
|
+
|
113
|
+
Let's cut-n-paste the pixel art matrix:
|
114
|
+
|
115
|
+
|
116
|
+
``` ruby
|
117
|
+
pixels = <<PIXELS
|
118
|
+
o o o o o o o o o o o o o o o o o lg lg lg dg o o o o o o o o o o o o o o o o o
|
119
|
+
o o o o o o o o o o o o o o dg lg lg w lg lg dg dg lg dg o o o o o o o o o o o o o o
|
120
|
+
o o o o o o o o o o o o o dg lg w lg w lg lg dg dg w lg dg o o o o o o o o o o o o o
|
121
|
+
o o o o o o o o o o o o dg lg w w lg w lg lg dg dg w w lg dg o o o o o o o o o o o
|
122
|
+
o o o o o o o o o o o o dg dg w w lg w lg lg dg dg w w dg dg o o o o o o o o o o o
|
123
|
+
o o o o o o o o o o o dg dg dg lg w lg w lg lg dg dg w lg dg dg dg o o o o o o o o o o
|
124
|
+
o o o o o o o o o o o dg dg dg w lg lg w lg lg dg dg lg w dg dg dg o o o o o o o o o o
|
125
|
+
o o o o o o o o o o o dg dg w lg lg lg w lg lg dg dg lg lg w dg dg o o o o o o o o o o
|
126
|
+
o o o o o o o o o o o dg lg lg b b b lg dg dg lg b b b lg lg dg o o o o o o o o o o
|
127
|
+
o o o o o o o o o o o dg lg b b b b b lg lg b b b b b lg dg o o o o o o o o o o
|
128
|
+
o o o o o o o o o o o lg b b db lg db b dg dg b lg db db b b lg o o o o o o o o o o
|
129
|
+
o o o o o o o o o o lg b b b db db db b lg lg b db db db b b b lg o o o o o o o o o
|
130
|
+
o o o o o o o o o o lg b b dg lg lg lg lg b b lg lg lg lg dg b b lg o o o o o o o o o
|
131
|
+
o o o o o o o o o lg b b b dg dg dg dg lg b b lg dg dg dg dg b b b lg o o o o o o o o
|
132
|
+
o o o o o o o o o lg b b b dg dg dg lg b b b b lg dg dg dg b b b lg o o o o o o o o
|
133
|
+
o o o o o o o o lg b b b b b dg dg b dg b dg b b lg dg b b b b b lg o o o o o o o
|
134
|
+
o o o o o o o o b b b b b b w b b dg b dg b dg b w b b b b b b o o o o o o o
|
135
|
+
o o o o o o o o b b b b b b dg dg dg dg dg dg dg dg dg dg b b b b b b o o o o o o o
|
136
|
+
o o o o o o o o o b b b b lg b b b b b b b b b b b b b b b o o o o o o o o
|
137
|
+
o o o o o o o o o o o o b lg lg dg dg b b b b dg dg b b b o o o o o o o o o o o
|
138
|
+
o o o o o o o o o o o o lg lg dg dg dg dg b b b dg dg dg dg b b o o o o o o o o o o
|
139
|
+
o o o o o o o o o dg dg b dg dg dg dg dg dg dg dg dg dg dg dg dg dg dg b dg dg o o o o o o o
|
140
|
+
o o o o o o o o dg dg b b lg lg lg lg lg lg lg lg lg lg lg lg lg lg lg b b dg dg o o o o o o
|
141
|
+
o o o o o o o dg dg b lg b lg dg lg lg dg dg lg lg dg dg lg lg dg dg lg b lg b dg dg o o o o o
|
142
|
+
o o o o o o dg dg b lg lg b lg dg lg lg dg dg lg lg dg dg lg lg dg dg lg b lg lg b dg dg o o o o
|
143
|
+
o o o o o dg dg b b b b b lg dg lg lg dg dg lg lg dg dg lg lg dg dg lg b b b b b dg dg
|
144
|
+
o o o o dg dg dg b dg dg b b b b lg lg dg dg lg lg dg dg lg lg b b b b dg dg dg b dg dg dg
|
145
|
+
o o o dg dg dg b dg dg dg b b b dg b b dg dg lg lg dg dg b b b dg b b b dg dg dg b dg dg dg
|
146
|
+
o o o dg dg b dg dg dg b b b dg dg dg b b b lg lg b b b dg dg dg b b b b dg dg dg b dg dg
|
147
|
+
o o dg dg dg b dg dg b b b b dg dg dg b lg lg b b lg lg dg dg dg dg b b b b b dg dg b dg dg dg
|
148
|
+
o o dg dg dg b dg b b b b b dg dg dg b b b b b b b dg b dg dg b b b b b b dg b dg dg dg
|
149
|
+
o dg dg dg dg b dg b b b b b dg b dg b b lg lg b r b dg b dg dg b b b b b b dg b dg dg dg dg
|
150
|
+
o dg dg dg dg b dg lg b b b b dg b dg b b b b b b b dg b dg dg b b b b b lg dg b dg dg dg dg
|
151
|
+
o dg dg dg dg b lg dg lg b b b dg b dg b b lg lg b blu b dg b dg dg b b b b lg dg lg b dg dg dg dg
|
152
|
+
o dg dg dg dg b dg lg dg lg b b dg b dg b b b b b b b dg b dg dg b b b lg dg lg dg b dg dg dg dg
|
153
|
+
o dg dg dg dg b dg dg lg dg lg b dg b dg b lg lg lg lg lg lg b b dg dg b b lg dg lg dg dg b dg dg dg dg
|
154
|
+
o dg dg dg dg b b dg dg lg dg b b b b b b b b b b b b b b b b b dg lg dg dg b b dg dg dg dg
|
155
|
+
o dg dg dg dg b b b dg dg dg b lg b g b b lg lg lg lg b b g b lg b b dg dg dg b b b dg dg dg dg
|
156
|
+
o dg dg dg dg b b b b dg b b b b b b b dg dg lg lg b b b b b b b b dg b b b b dg dg dg dg
|
157
|
+
o dg dg dg dg b b b b b b b b b b b b b b b b b b b b b b b b b b b b b dg dg dg dg
|
158
|
+
o dg dg dg dg b b b b b b b dg b dg b dg dg dg dg dg dg b dg b lg b b b b b b b b dg dg dg dg
|
159
|
+
o dg dg dg b b b b b b b b dg b dg b dg dg dg dg dg dg b dg b lg dg b b b b b b b b dg dg dg
|
160
|
+
o dg dg dg b b b b b b b b b dg dg b dg dg dg dg dg dg b dg b dg dg b b b b b b b b dg dg dg
|
161
|
+
o dg dg dg b b b b b b b b b dg dg b b dg dg dg dg b b dg b w lg b b b b b b b b dg dg dg
|
162
|
+
o dg dg dg b b b b b b b b b dg dg b b dg dg dg dg b b dg b w lg b b b b b b b b dg dg dg
|
163
|
+
o dg dg dg b b b b b b b b b dg dg b dg b dg dg b dg b dg b lg dg b b b b b b b b dg dg dg
|
164
|
+
o dg dg dg b b b b b b b b b dg dg b dg dg b b dg dg b dg b dg dg b b b b b b b b dg dg dg
|
165
|
+
o dg dg dg b b b b b b b b dg dg dg b dg dg b dg dg dg b dg b lg dg b b b b b b b b dg dg dg
|
166
|
+
o dg dg dg b b b b b b b b dg dg dg b dg dg b dg dg dg b dg b lg dg b b b b b b b b dg dg dg
|
167
|
+
dg dg dg dg b b b b b b b b dg dg dg b dg dg b dg dg dg b dg b lg dg b b b b b b b b dg dg dg dg
|
168
|
+
dg dg dg dg b b b b b b b b dg dg dg b dg b b b dg dg b dg b b b b b b b b b b b dg dg dg dg
|
169
|
+
dg dg dg dg b b b b b b b b dg dg dg b dg b b b dg dg b dg dg dg b b b b b b b b b dg dg dg dg
|
170
|
+
dg dg dg dg b b b b b b b b dg dg dg b dg b b b dg dg b dg dg dg b b b b b b b b b dg dg dg dg
|
171
|
+
dg dg dg dg b b b b b b b b dg b dg b dg b b b dg dg b dg dg dg b b b b b b b b b dg dg dg dg
|
172
|
+
dg dg dg dg b b b b b b b b dg b dg b dg b b b dg dg b dg dg dg b b b b b b b b b dg dg dg dg
|
173
|
+
dg dg dg dg b b b b b b b b dg b dg b dg b b b dg dg b dg dg dg b b b b b b b b b dg dg dg dg
|
174
|
+
dg dg dg dg b b b b b b b b dg b dg b dg b b b dg dg b dg b dg b b b b b b b b b dg dg dg dg
|
175
|
+
dg dg dg dg b b b b b b b b dg b dg b dg b b b dg dg b dg b dg b b b b b b b b b dg dg dg dg
|
176
|
+
dg dg dg dg b b b b b b b b dg b dg b dg b b b dg dg b dg b dg b b b b b b b b b dg dg dg dg
|
177
|
+
dg dg dg dg b b b b b b b b dg b dg b dg b b b dg dg b dg b dg b b b b b b b b b dg dg dg dg
|
178
|
+
dg dg dg dg b b b b b b b b b b b b dg b b b dg dg b b b b b b b b b b b b b dg dg dg dg
|
179
|
+
dg dg dg dg b b b b b b b b dg lg dg dg dg b b b dg lg dg dg dg dg b b b b b b b b b dg dg dg dg
|
180
|
+
dg dg dg dg b b b b b b b b dg lg dg dg dg b b b dg lg dg dg dg dg b b b b b b b b b dg dg dg dg
|
181
|
+
dg dg dg dg b b o o o o o o b b b dg dg b b b dg dg dg b b b o o o o o o o b b dg dg dg dg
|
182
|
+
o o dg dg o o o o o o o b lg lg dg b b b o o b b lg dg dg dg b o o o o o o b b dg dg dg dg
|
183
|
+
o o o o o o o o o b lg lg dg dg dg dg dg b o o b dg lg lg dg dg dg b
|
184
|
+
o o o o o o o o b dg dg dg dg dg dg dg dg b o o b dg dg dg dg dg dg b b
|
185
|
+
o o o o ulg ulg ulg ulg b b b b b b b b b b ulg ulg b b b b b b b b b ulg ulg ulg ulg
|
186
|
+
PIXELS
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
Note: Yes, you can use any number (e.g. `0` `1` `2` `3` etc)
|
191
|
+
or shortcut (e.g. `o` `b` `ulg` `lg` etc) for pixels.
|
192
|
+
Only make sure you have a color map matching your shortcuts.
|
193
|
+
|
194
|
+
|
195
|
+
Let's add the color map:
|
196
|
+
|
197
|
+
``` ruby
|
198
|
+
colors = {
|
199
|
+
o: 'transparent',
|
200
|
+
b: '#1D191A',
|
201
|
+
ulg: '#eaeaec',
|
202
|
+
lg: '#747474',
|
203
|
+
db: '#453C35',
|
204
|
+
dg: '#343031',
|
205
|
+
w: '#fff',
|
206
|
+
r: '#fc3435',
|
207
|
+
blu: '#1F3A93',
|
208
|
+
g: '#00943b'
|
209
|
+
}
|
210
|
+
```
|
211
|
+
|
212
|
+
|
213
|
+
And let's mint an imperial master image:
|
214
|
+
|
215
|
+
``` ruby
|
216
|
+
img = Pixelart::Image.new( pixels, colors: colors )
|
217
|
+
img.save( './i/vader.png' )
|
218
|
+
```
|
219
|
+
|
220
|
+
And let's try a 5x zoom factor:
|
221
|
+
|
222
|
+
``` ruby
|
223
|
+
img = Pixelart::Image.new( pixels, colors: colors, zoom: 5 )
|
224
|
+
img.save( './i/vader5x.png' )
|
225
|
+
```
|
226
|
+
|
227
|
+
Voila!
|
228
|
+
|
229
|
+
![](i/vader.png)
|
230
|
+
![](i/vader5x.png)
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
## Install
|
236
|
+
|
237
|
+
Just install the gem:
|
238
|
+
|
239
|
+
$ gem install pixelart
|
240
|
+
|
241
|
+
|
242
|
+
## License
|
243
|
+
|
244
|
+
The scripts are dedicated to the public domain.
|
245
|
+
Use it as you please with no restrictions whatsoever.
|
246
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/pixelart/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'pixelart' do
|
5
|
+
|
6
|
+
self.version = Pixelart::VERSION
|
7
|
+
|
8
|
+
self.summary = "pixelart - mint your own pixel art images off chain using any design (in ascii text) in any colors; incl. 2x/4x/8x zoom for bigger sizes"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = { home: 'https://github.com/cryptocopycats/mooncats' }
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'wwwmake@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
['chunky_png'],
|
22
|
+
]
|
23
|
+
|
24
|
+
self.licenses = ['Public Domain']
|
25
|
+
|
26
|
+
self.spec_extras = {
|
27
|
+
required_ruby_version: '>= 2.3'
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
data/lib/pixelart.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
## 3rd party
|
2
|
+
require 'chunky_png'
|
3
|
+
|
4
|
+
## stdlib
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
## our own code
|
8
|
+
require 'pixelart/version' # note: let version always go first
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
module Pixelart
|
13
|
+
class Image
|
14
|
+
|
15
|
+
def initialize( pixels, colors:, zoom: 1 )
|
16
|
+
@colors = parse_colors( colors )
|
17
|
+
@pixels = parse_pixels( pixels )
|
18
|
+
|
19
|
+
max_width = @pixels.reduce(1) {|max_width,row| row.size > max_width ? row.size : max_width }
|
20
|
+
max_height = @pixels.size
|
21
|
+
|
22
|
+
@img = ChunkyPNG::Image.new( max_width*zoom,
|
23
|
+
max_height*zoom,
|
24
|
+
ChunkyPNG::Color::TRANSPARENT )
|
25
|
+
|
26
|
+
@pixels.each_with_index do |row,y|
|
27
|
+
row.each_with_index do |color,x|
|
28
|
+
pixel = @colors[color]
|
29
|
+
zoom.times do |n|
|
30
|
+
zoom.times do |m|
|
31
|
+
@img[n+zoom*x,m+zoom*y] = pixel
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end # each row
|
35
|
+
end # each data
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def parse_pixels( pixels )
|
40
|
+
data = []
|
41
|
+
pixels.each_line do |line|
|
42
|
+
line = line.strip
|
43
|
+
if line.empty?
|
44
|
+
puts "!! WARN: skipping empty line in pixel art source"
|
45
|
+
next
|
46
|
+
end
|
47
|
+
|
48
|
+
## note: allow multiple spaces or tabs to separate pixel codes
|
49
|
+
## e.g. o o o o o o o o o o o o dg lg w w lg w lg lg dg dg w w lg dg o o o o o o o o o o o
|
50
|
+
## or
|
51
|
+
data << line.split( /[ \t]+/)
|
52
|
+
end
|
53
|
+
data
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
#####
|
58
|
+
# (image) delegates
|
59
|
+
## todo/check: add some more??
|
60
|
+
def save( path, constraints = {} )
|
61
|
+
@img.save( path, constraints )
|
62
|
+
end
|
63
|
+
|
64
|
+
def width() @img.width; end
|
65
|
+
def height() @img.height; end
|
66
|
+
|
67
|
+
## return image ref - use a different name - why? why not?
|
68
|
+
def image() @img; end
|
69
|
+
|
70
|
+
def colors() @colors; end ## todo/check - return color map (hash table) or just color values (array) - why? why not?
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
######
|
75
|
+
# helpers
|
76
|
+
def parse_colors( colors )
|
77
|
+
if colors.is_a?( Array ) ## convenience shortcut
|
78
|
+
## note: always auto-add color 0 as pre-defined transparent - why? why not?
|
79
|
+
h = { '0' => ChunkyPNG::Color::TRANSPARENT }
|
80
|
+
colors.each_with_index do |color, i|
|
81
|
+
h[ (i+1).to_s ] = parse_color( color )
|
82
|
+
end
|
83
|
+
h
|
84
|
+
else ## assume hash table with color map
|
85
|
+
## convert into ChunkyPNG::Color
|
86
|
+
colors.map do |key,color|
|
87
|
+
## always convert key to string why? why not? use symbol?
|
88
|
+
[ key.to_s, parse_color( color ) ]
|
89
|
+
end.to_h
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def parse_color( color )
|
94
|
+
if color.is_a?( Integer ) ## e.g. Assumess ChunkyPNG::Color.rgb() or such
|
95
|
+
color ## pass through as is 1:1
|
96
|
+
elsif color.is_a?(String)
|
97
|
+
if color.downcase == 'transparent' ## special case for builtin colors
|
98
|
+
ChunkyPNG::Color::TRANSPARENT
|
99
|
+
else
|
100
|
+
## note: return an Integer !!! (not a Color class or such!!! )
|
101
|
+
ChunkyPNG::Color.from_hex( color )
|
102
|
+
end
|
103
|
+
else
|
104
|
+
raise ArgumentError, "unknown color format; cannot parse - expected rgb hex string e.g. d3d3d3"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
end # class Image
|
110
|
+
end # module Pixelart
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
### add some convenience shortcuts
|
115
|
+
PixelArt = Pixelart
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
puts Pixelart.banner # say hello
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module Pixelart
|
3
|
+
|
4
|
+
MAJOR = 0
|
5
|
+
MINOR = 1
|
6
|
+
PATCH = 0
|
7
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
8
|
+
|
9
|
+
def self.version
|
10
|
+
VERSION
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.banner
|
14
|
+
"pixelart/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.root
|
18
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
19
|
+
end
|
20
|
+
|
21
|
+
end # module Pixelart
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pixelart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chunky_png
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '7'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '4.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hoe
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.22'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.22'
|
61
|
+
description: pixelart - mint your own pixel art images off chain using any design
|
62
|
+
(in ascii text) in any colors; incl. 2x/4x/8x zoom for bigger sizes
|
63
|
+
email: wwwmake@googlegroups.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files:
|
67
|
+
- CHANGELOG.md
|
68
|
+
- Manifest.txt
|
69
|
+
- README.md
|
70
|
+
files:
|
71
|
+
- CHANGELOG.md
|
72
|
+
- Manifest.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/pixelart.rb
|
76
|
+
- lib/pixelart/version.rb
|
77
|
+
homepage: https://github.com/cryptocopycats/mooncats
|
78
|
+
licenses:
|
79
|
+
- Public Domain
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- "--main"
|
84
|
+
- README.md
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '2.3'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubygems_version: 3.1.4
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: pixelart - mint your own pixel art images off chain using any design (in
|
102
|
+
ascii text) in any colors; incl. 2x/4x/8x zoom for bigger sizes
|
103
|
+
test_files: []
|