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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7ef9b53c8d7eddc68fd7bcc85283b85e041ade464d15408296f76ec7e79cc94
4
- data.tar.gz: 87c43c6be85a868c83839ba75a4d569b1d655ccbdbf7382fe150cddeff63fc57
3
+ metadata.gz: 5a86710643f5a8a481ee79899147c49aa6d7e97b3398c679b15412b5c3ac0565
4
+ data.tar.gz: 2282693e41bff4de6de43c3742fe9c1a1b5a01a320ed819f326f6c6eee571b46
5
5
  SHA512:
6
- metadata.gz: 45b4afb06f3744d61677bbbf88f835dad19098ca128c9b0982bfa179677c44a7895d457b43e708da818666f14d58c2d029cd88e36224202d70de50a85c8632f2
7
- data.tar.gz: 186929d319a497d1c93962f97722888f3b173318bfca0c12397eef0a988178ce2dde11d9b4da80ad4a7dede5344831fdab8fda61ac87f04a02919964edfdf14f
6
+ metadata.gz: 0b033ac3b7f5cb608c18c8f3a9ccb53d671667b6b1df5d7dd1b7654608dc149bdd13131d19f46fd975c02bea4340dc65cd93fde028499c47468753a1ff1418d1
7
+ data.tar.gz: 544bbae40dca87fab685997813bba02637d1e7d9d21ff68138ba82a381ad289e5aa02041bc2c488cf6835c6cc1ca7b241a5e888720556031063e6962060f291b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,4 @@
1
+ ### 1.4.0
1
2
  ### 0.0.1 / 2021-04-08
2
3
 
3
4
  * Everything is new. First release
data/lib/pixelart/base.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'cocos'
2
2
  require 'base64'
3
+ require 'strscan' ## todo/fix: auto-add strscan in cocos - why? why not?
3
4
 
4
5
 
5
6
  ###
@@ -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
- width = pixels.reduce(1) {|width,row| row.size > width ? row.size : width }
63
- height = pixels.size
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( pixels )
324
- if pixels.is_a?( Array ) ## assume array of string (lines)
325
- data = []
326
- pixels.each do |line|
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
- data << line.each_char.reduce( [] ) { |mem, c| mem << c; mem }
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
- data = []
334
- pixels.each_line do |line|
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
- data << line.split( /[ \t]+/)
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
@@ -2,8 +2,8 @@
2
2
  module Pixelart
3
3
 
4
4
  MAJOR = 1
5
- MINOR = 3
6
- PATCH = 8
5
+ MINOR = 4
6
+ PATCH = 0
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
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.3.8
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-06-13 00:00:00.000000000 Z
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: '3.23'
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: '3.23'
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.3.7
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)