pixelart 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pixelart/image.rb +27 -8
- data/lib/pixelart/misc.rb +29 -0
- data/lib/pixelart/version.rb +2 -2
- 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: 4ebe6ddb193d15d611f37461ebca0f7de77d9df6d14c0078eeb483fcdcaf505e
|
4
|
+
data.tar.gz: 773ab34615671bb06b4e8b8e77096cc9e44588ec5c1b04662474e410a0382223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50f927ae70136c40e9d8bcac7c7c87641dc51427fbf5abaf2a88f1312327e83f59689b597b91e0d9003887a349b10fd20ce4be2ba7bf7baf1b9cebd2df2ee7b5
|
7
|
+
data.tar.gz: 6afea4ef51112243f065b7071d26c4ae6a70b3c408015838ab01a02d38a3a53ff3f14f04c7cd9746520c6be10f4153eba8b6533e4a52726dc531a7d54e250c29
|
data/lib/pixelart/image.rb
CHANGED
@@ -9,7 +9,14 @@ def self.read( path ) ## convenience helper
|
|
9
9
|
end
|
10
10
|
|
11
11
|
|
12
|
-
|
12
|
+
|
13
|
+
CHARS = '.@xo^~%*+=:' ## todo/check: rename to default chars or such? why? why not?
|
14
|
+
|
15
|
+
## todo/check: support default chars encoding auto-of-the-box always
|
16
|
+
## or require user-defined chars to be passed in - why? why not?
|
17
|
+
def self.parse( pixels, colors:, chars: CHARS )
|
18
|
+
has_keys = colors.is_a?(Hash) ## check if passed-in user-defined keys (via hash table)?
|
19
|
+
|
13
20
|
colors = parse_colors( colors )
|
14
21
|
pixels = parse_pixels( pixels )
|
15
22
|
|
@@ -20,7 +27,19 @@ def self.parse( pixels, colors: )
|
|
20
27
|
|
21
28
|
pixels.each_with_index do |row,y|
|
22
29
|
row.each_with_index do |color,x|
|
23
|
-
pixel =
|
30
|
+
pixel = if has_keys ## if passed-in user-defined keys check only the user-defined keys
|
31
|
+
colors[color]
|
32
|
+
else
|
33
|
+
## try map ascii art char (.@xo etc.) to color index (0,1,2)
|
34
|
+
## if no match found - fallback on assuming draw by number (0 1 2 etc.) encoding
|
35
|
+
pos = chars.index( color )
|
36
|
+
if pos
|
37
|
+
colors[ pos.to_s ]
|
38
|
+
else ## assume nil (not found)
|
39
|
+
colors[ color ]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
24
43
|
img[x,y] = pixel
|
25
44
|
end # each row
|
26
45
|
end # each data
|
@@ -170,6 +189,9 @@ def []=( x, y, value ) @img[x,y]=value; end
|
|
170
189
|
|
171
190
|
def pixels() @img.pixels; end
|
172
191
|
|
192
|
+
### todo/check: add colors() e.g. @img.pixels.uniq - why? why not?
|
193
|
+
|
194
|
+
|
173
195
|
## return image ref - use a different name - why? why not?
|
174
196
|
## change to to_image - why? why not?
|
175
197
|
def image() @img; end
|
@@ -183,10 +205,7 @@ def self.parse_pixels( pixels )
|
|
183
205
|
data = []
|
184
206
|
pixels.each_line do |line|
|
185
207
|
line = line.strip
|
186
|
-
if line.empty?
|
187
|
-
puts "!! WARN: skipping empty line in pixel art source"
|
188
|
-
next
|
189
|
-
end
|
208
|
+
next if line.start_with?( '#' ) || line.empty? ## note: allow comments and empty lines
|
190
209
|
|
191
210
|
## note: allow multiple spaces or tabs to separate pixel codes
|
192
211
|
## 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
|
@@ -197,12 +216,13 @@ def self.parse_pixels( pixels )
|
|
197
216
|
end
|
198
217
|
|
199
218
|
|
219
|
+
|
200
220
|
def self.parse_colors( colors )
|
201
221
|
if colors.is_a?( Array ) ## convenience shortcut
|
202
222
|
## note: always auto-add color 0 as pre-defined transparent - why? why not?
|
203
223
|
h = { '0' => Color::TRANSPARENT }
|
204
224
|
colors.each_with_index do |color, i|
|
205
|
-
|
225
|
+
h[ (i+1).to_s ] = Color.parse( color )
|
206
226
|
end
|
207
227
|
h
|
208
228
|
else ## assume hash table with color map
|
@@ -215,7 +235,6 @@ def self.parse_colors( colors )
|
|
215
235
|
end
|
216
236
|
|
217
237
|
|
218
|
-
|
219
238
|
end # class Image
|
220
239
|
end # module Pixelart
|
221
240
|
|
data/lib/pixelart/misc.rb
CHANGED
@@ -15,6 +15,9 @@ class ImagePalette8bit < Image # or use Palette256 alias?
|
|
15
15
|
img = ChunkyPNG::Image.new( 32*size+(32-1)*spacing,
|
16
16
|
8*size+(8-1)*spacing )
|
17
17
|
|
18
|
+
|
19
|
+
colors =colors.map {|color| Color.parse( color ) }
|
20
|
+
|
18
21
|
colors.each_with_index do |color,i|
|
19
22
|
y,x = i.divmod( 32 )
|
20
23
|
if size > 1
|
@@ -32,6 +35,32 @@ class ImagePalette8bit < Image # or use Palette256 alias?
|
|
32
35
|
super( img.width, img.height, img )
|
33
36
|
end
|
34
37
|
end # class ImagePalette8bit
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
class ImageColorBar < Image
|
42
|
+
## make a color bar
|
43
|
+
## keep auto-zoom 24x or such - why? why not?
|
44
|
+
def initialize( colors, size: 24 )
|
45
|
+
img = ChunkyPNG::Image.new( colors.size*size,
|
46
|
+
size,
|
47
|
+
ChunkyPNG::Color::WHITE ) # why? why not?
|
48
|
+
|
49
|
+
colors = colors.map {|color| Color.parse( color ) }
|
50
|
+
|
51
|
+
colors.each_with_index do |color,i|
|
52
|
+
size.times do |x|
|
53
|
+
size.times do |y|
|
54
|
+
img[x+size*i,y] = color
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
super( img.width, img.height, img )
|
60
|
+
end
|
61
|
+
end # class ImageColorBar
|
62
|
+
|
63
|
+
|
35
64
|
end # module Pixelart
|
36
65
|
|
37
66
|
|
data/lib/pixelart/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixelart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2021-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|