pixelart 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 931c4aa26d5a0594b4aec85f532d16e93d3dd505f4d2f9729b24e3fd45c662c4
4
- data.tar.gz: 5dc8936fc9a0f76b05cf4209ad69ebeba87f25bd3c0290cad59e961760aa5782
3
+ metadata.gz: 5a86710643f5a8a481ee79899147c49aa6d7e97b3398c679b15412b5c3ac0565
4
+ data.tar.gz: 2282693e41bff4de6de43c3742fe9c1a1b5a01a320ed819f326f6c6eee571b46
5
5
  SHA512:
6
- metadata.gz: 3189094ecb75f30d1ccd52bafc83b6ece3319b0b5c4f769ab02110212b5674adc59a816dc2abfa8be3d9a6a344bd253471677d5802391325b681987eb9d5ece0
7
- data.tar.gz: a1e6e2ea6c25ac1ed7f2542ff8039a8ac1b5232001539611a151302959563e623d879e9c6590aa4cc1468d7716eb7ffaa8faeeed9360589570664a94f512aa48
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/Manifest.txt CHANGED
@@ -13,7 +13,6 @@ lib/pixelart/image.rb
13
13
  lib/pixelart/invert.rb
14
14
  lib/pixelart/led.rb
15
15
  lib/pixelart/misc.rb
16
- lib/pixelart/orc721/generator.rb
17
16
  lib/pixelart/pixelator.rb
18
17
  lib/pixelart/sample.rb
19
18
  lib/pixelart/silhouette.rb
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
  ###
@@ -70,9 +71,5 @@ require 'pixelart/convert'
70
71
 
71
72
 
72
73
 
73
- ####
74
- # add orc-721 - why? why not?
75
- require 'pixelart/orc721/generator'
76
-
77
74
 
78
75
  puts Pixelart.banner # say hello
@@ -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 = 7
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.7
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-08 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
@@ -125,7 +125,6 @@ files:
125
125
  - lib/pixelart/invert.rb
126
126
  - lib/pixelart/led.rb
127
127
  - lib/pixelart/misc.rb
128
- - lib/pixelart/orc721/generator.rb
129
128
  - lib/pixelart/pixelator.rb
130
129
  - lib/pixelart/sample.rb
131
130
  - lib/pixelart/silhouette.rb
@@ -157,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
156
  - !ruby/object:Gem::Version
158
157
  version: '0'
159
158
  requirements: []
160
- rubygems_version: 3.3.7
159
+ rubygems_version: 3.4.10
161
160
  signing_key:
162
161
  specification_version: 4
163
162
  summary: pixelart - yes, you can! generate your own pixel art images (off-blockchain)
@@ -1,51 +0,0 @@
1
-
2
-
3
- module Orc721
4
- class Generator
5
- ###################
6
- ## convenience setup helper(s)
7
- def self.read( path, width: 24, height: 24 )
8
- new( Pixelart::ImageComposite.read( path,
9
- width: width,
10
- height: height ))
11
- end
12
-
13
-
14
- def initialize( spritesheet )
15
- ### todo: check for composite image type? - why? why not?
16
- @spritesheet = spritesheet
17
- end
18
-
19
- def _parse( spec )
20
- ## for delimiter allow for now: - why? why not?
21
- ## (multiple) space ( )
22
- ## command or semicolon
23
- spec.strip.split( %r{[ ,;/_-]+} ).map {|v| v.to_i(10) }
24
- end
25
-
26
- def parse( spec )
27
- ## convenience helper
28
- ## parses g spec in various (delimited) formats
29
- g = _parse( spec )
30
- generate( *g )
31
- end
32
-
33
- def generate( *attributes )
34
- img = Pixelart::Image.new( width, height )
35
- attributes.each do |num|
36
- img.compose!( @spritesheet[ num ] )
37
- end
38
- img
39
- end
40
- alias_method :g, :generate
41
-
42
- def width() @spritesheet.tile_width; end
43
- def height() @spritesheet.tile_height; end
44
- def count() @spritesheet.count; end
45
- end # class Generator
46
- end # module Orc721
47
-
48
-
49
- ######
50
- ## add convenience aliases - why? why not?
51
- ORC721 = Orc721