pixelart 1.3.8 → 1.4.0
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/CHANGELOG.md +1 -0
- data/lib/pixelart/base.rb +1 -0
- data/lib/pixelart/image.rb +70 -14
- data/lib/pixelart/version.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a86710643f5a8a481ee79899147c49aa6d7e97b3398c679b15412b5c3ac0565
|
4
|
+
data.tar.gz: 2282693e41bff4de6de43c3742fe9c1a1b5a01a320ed819f326f6c6eee571b46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b033ac3b7f5cb608c18c8f3a9ccb53d671667b6b1df5d7dd1b7654608dc149bdd13131d19f46fd975c02bea4340dc65cd93fde028499c47468753a1ff1418d1
|
7
|
+
data.tar.gz: 544bbae40dca87fab685997813bba02637d1e7d9d21ff68138ba82a381ad289e5aa02041bc2c488cf6835c6cc1ca7b241a5e888720556031063e6962060f291b
|
data/CHANGELOG.md
CHANGED
data/lib/pixelart/base.rb
CHANGED
data/lib/pixelart/image.rb
CHANGED
@@ -53,14 +53,42 @@ CHARS = '.@xo^~%*+=:' ## todo/check: rename to default chars or such? why? w
|
|
53
53
|
## or require user-defined chars to be passed in - why? why not?
|
54
54
|
def self.parse( pixels, colors:,
|
55
55
|
background: Color::TRANSPARENT,
|
56
|
-
chars: CHARS
|
56
|
+
chars: CHARS,
|
57
|
+
width: nil,
|
58
|
+
height: nil )
|
57
59
|
has_keys = colors.is_a?(Hash) ## check if passed-in user-defined keys (via hash table)?
|
58
60
|
|
59
61
|
colors = parse_colors( colors )
|
60
|
-
pixels = parse_pixels( pixels )
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
## note: for now use strict parser only
|
64
|
+
## if colors with hash map / keys defined
|
65
|
+
## will raise error / exit if unknown token found!!!
|
66
|
+
## AND pixels is a single txt / text string to parse (NOT array of string lines)
|
67
|
+
##
|
68
|
+
#
|
69
|
+
# note default for now is:
|
70
|
+
# 1) tokens separated by space if not strict (e.g. has no color keys AND not array of strings)
|
71
|
+
# 2) every char is a token if array of strings
|
72
|
+
pixels = if has_keys && pixels.is_a?( String )
|
73
|
+
keys = colors.keys.map { |key| key.to_s }
|
74
|
+
## todo/fix: - sort by lenght first;
|
75
|
+
## - escape for rx chars!!
|
76
|
+
rx = /#{keys.join('|')}/
|
77
|
+
parse_pixels_strict( rx, pixels )
|
78
|
+
else
|
79
|
+
parse_pixels( pixels )
|
80
|
+
end
|
81
|
+
|
82
|
+
## note: for now only use (require) width for flattened/streamed text input
|
83
|
+
if width
|
84
|
+
## always flattern first - why? why not?
|
85
|
+
## allow multi-line text inputs - allow/support why? why not?
|
86
|
+
pixels = pixels.flatten.each_slice( width ).to_a
|
87
|
+
else
|
88
|
+
## find row with max width
|
89
|
+
width = pixels.reduce(1) {|width,row| row.size > width ? row.size : width }
|
90
|
+
height = pixels.size
|
91
|
+
end
|
64
92
|
|
65
93
|
background = Color.parse( background ) unless background.is_a?( Integer )
|
66
94
|
|
@@ -320,18 +348,18 @@ def image() @img; end
|
|
320
348
|
|
321
349
|
######
|
322
350
|
# helpers
|
323
|
-
def self.parse_pixels(
|
324
|
-
|
325
|
-
|
326
|
-
|
351
|
+
def self.parse_pixels( obj )
|
352
|
+
pixels = []
|
353
|
+
if obj.is_a?( Array ) ## assume array of string (lines)
|
354
|
+
lines = obj
|
355
|
+
lines.each do |line|
|
327
356
|
## convert (string) line into indidual chars
|
328
|
-
|
357
|
+
pixels << line.each_char.reduce( [] ) { |mem, c| mem << c; mem }
|
329
358
|
end
|
330
|
-
data
|
331
359
|
else ## assume it's a (multi-line) string (with newlines)
|
332
360
|
## assert and throw ArgumentError if not? - why? why not?
|
333
|
-
|
334
|
-
|
361
|
+
txt = obj
|
362
|
+
txt.each_line do |line|
|
335
363
|
line = line.strip
|
336
364
|
next if line.start_with?( '#' ) || line.empty? ## note: allow comments and empty lines
|
337
365
|
|
@@ -339,13 +367,41 @@ def self.parse_pixels( pixels )
|
|
339
367
|
## to separate pixel codes
|
340
368
|
## 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
|
341
369
|
## or
|
342
|
-
|
370
|
+
pixels << line.split( /[ \t]+/ )
|
343
371
|
end
|
344
|
-
data
|
345
372
|
end
|
373
|
+
pixels
|
346
374
|
end
|
347
375
|
|
348
376
|
|
377
|
+
def self.parse_pixels_strict( rx, txt )
|
378
|
+
## must match tokens in regex (rx) e.g. /0|1|2|3../ or /A|B|C... etc./
|
379
|
+
pixels = []
|
380
|
+
|
381
|
+
txt.each_line do |line|
|
382
|
+
line = line.strip
|
383
|
+
next if line.start_with?( '#' ) || line.empty? ## note: allow comments and empty lines
|
384
|
+
|
385
|
+
scan = StringScanner.new( line )
|
386
|
+
tokens = []
|
387
|
+
loop do
|
388
|
+
# puts " pos: #{scan.pos} - size: #{scan.rest.size} - #{scan.rest}"
|
389
|
+
token = scan.scan( rx )
|
390
|
+
if token.nil?
|
391
|
+
## todo/fix: raise an exception here
|
392
|
+
puts "!! ERROR - parse error; expected match of #{rx.to_s} but got: #{scan.rest}"
|
393
|
+
exit 1
|
394
|
+
end
|
395
|
+
tokens << token
|
396
|
+
|
397
|
+
scan.skip( /[ \t]+/ )
|
398
|
+
break if scan.eos?
|
399
|
+
end
|
400
|
+
pixels << tokens
|
401
|
+
end
|
402
|
+
pixels
|
403
|
+
end
|
404
|
+
|
349
405
|
|
350
406
|
def self.parse_colors( colors )
|
351
407
|
if colors.is_a?( Array ) ## convenience shortcut
|
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: 1.
|
4
|
+
version: 1.4.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: 2023-
|
11
|
+
date: 2023-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocos
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '4.0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '4.0'
|
103
103
|
description: pixelart - yes, you can! generate your own pixel art images (off-blockchain)
|
104
104
|
using any design (in ascii text) in any colors; incl. 2x/4x/8x zoom for bigger sizes
|
105
105
|
email: gerald.bauer@gmail.com
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
159
|
+
rubygems_version: 3.4.10
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: pixelart - yes, you can! generate your own pixel art images (off-blockchain)
|