pixelart 1.2.1 → 1.2.2

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: e407d45e71520e9e7c34448811a80e796254aba70c791e3497df00b0fa700486
4
- data.tar.gz: 55c324e6cf901bd8ed78fa48d97f27a3f66c60d314d070a457ef4e272ebe9f01
3
+ metadata.gz: 6be97cd0f30e95965b6ca21d69142283d1e2869ba99e37b84245b5d95c47fda0
4
+ data.tar.gz: 2bc68cf7a70d718e2d96b92f4401f44074b01282cb5ede85d548b36edac7d3d6
5
5
  SHA512:
6
- metadata.gz: 6e36d0cb47e5e36b81b3a3f47d62fa119b898f9bbf11c422d53f5ab3cfdfe022a8f3dda3d82ea1db4f2eb422376ea82ac153922add94caeb5aff97214813a81a
7
- data.tar.gz: b8957560272efd295ef73bdd450531dc9d631fd293215dbd0f9f835bdbdb50669018f1d24a27a6df45d8714a2633bc1d22a6b6761979dc7804b3c5290c2f1eaa
6
+ metadata.gz: c329166bd2144e1e440d01447c9babc6d999de0aed2d9eb3dedaa521b016b829f0039d8fdf5475afeffbc46f2f75f1efaca1a95f73a3c3e968d653041ff4656a
7
+ data.tar.gz: 44ab750a9bdec98770ff6ed325b8fac5883e693ae3356b08012184bdf72a20c1c88a023fb883dc437311df043d6a2d23012f54309d70dfa8e3402deb5683e945
data/Manifest.txt CHANGED
@@ -13,7 +13,9 @@ lib/pixelart/led.rb
13
13
  lib/pixelart/misc.rb
14
14
  lib/pixelart/palette.rb
15
15
  lib/pixelart/pixelator.rb
16
+ lib/pixelart/silhouette.rb
16
17
  lib/pixelart/sketch.rb
17
18
  lib/pixelart/spots.rb
19
+ lib/pixelart/transparent.rb
18
20
  lib/pixelart/vector.rb
19
21
  lib/pixelart/version.rb
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
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
4
 
5
5
 
6
- * home :: [github.com/rubycoco/pixel](https://github.com/rubycoco/pixel)
7
- * bugs :: [github.com/rubycoco/pixel/issues](https://github.com/rubycoco/pixel/issues)
6
+ * home :: [github.com/pixelartexchange/pixel](https://github.com/pixelartexchange/pixel)
7
+ * bugs :: [github.com/pixelartexchange/pixel/issues](https://github.com/pixelartexchange/pixel/issues)
8
8
  * gem :: [rubygems.org/gems/pixelart](https://rubygems.org/gems/pixelart)
9
9
  * rdoc :: [rubydoc.info/gems/pixelart](http://rubydoc.info/gems/pixelart)
10
10
 
@@ -71,8 +71,8 @@ img3x.save( './i/mooncat_white-3x.png' )
71
71
 
72
72
  Voila!
73
73
 
74
- ![](https://github.com/rubycoco/pixel/raw/master/pixelart/i/mooncat_white.png)
75
- ![](https://github.com/rubycoco/pixel/raw/master/pixelart/i/mooncat_white-3x.png)
74
+ ![](https://github.com/pixelartexchange/pixel/raw/master/pixelart/i/mooncat_white.png)
75
+ ![](https://github.com/pixelartexchange/pixel/raw/master/pixelart/i/mooncat_white-3x.png)
76
76
 
77
77
 
78
78
 
@@ -100,8 +100,8 @@ img3x.save( './i/mooncat_black-3x.png' )
100
100
 
101
101
  Voila! Black is the new White!
102
102
 
103
- ![](https://github.com/rubycoco/pixel/raw/master/pixelart/i/mooncat_black.png)
104
- ![](https://github.com/rubycoco/pixel/raw/master/pixelart/i/mooncat_black-3x.png)
103
+ ![](https://github.com/pixelartexchange/pixel/raw/master/pixelart/i/mooncat_black.png)
104
+ ![](https://github.com/pixelartexchange/pixel/raw/master/pixelart/i/mooncat_black-3x.png)
105
105
 
106
106
 
107
107
 
@@ -227,8 +227,8 @@ img5x.save( './i/vader5x.png' )
227
227
 
228
228
  Voila!
229
229
 
230
- ![](https://github.com/rubycoco/pixel/raw/master/pixelart/i/vader.png)
231
- ![](https://github.com/rubycoco/pixel/raw/master/pixelart/i/vader5x.png)
230
+ ![](https://github.com/pixelartexchange/pixel/raw/master/pixelart/i/vader.png)
231
+ ![](https://github.com/pixelartexchange/pixel/raw/master/pixelart/i/vader5x.png)
232
232
 
233
233
 
234
234
 
@@ -288,4 +288,3 @@ Just install the gem:
288
288
 
289
289
  The scripts are dedicated to the public domain.
290
290
  Use it as you please with no restrictions whatsoever.
291
-
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Hoe.spec 'pixelart' do
8
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
9
  self.description = summary
10
10
 
11
- self.urls = { home: 'https://github.com/rubycoco/pixel' }
11
+ self.urls = { home: 'https://github.com/pixelartexchange/pixel' }
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
14
  self.email = 'wwwmake@googlegroups.com'
data/lib/pixelart/base.rb CHANGED
@@ -37,9 +37,12 @@ require 'pixelart/pixelator'
37
37
  require 'pixelart/misc' ## misc helpers
38
38
 
39
39
  #########################
40
- # (special) effects / filters
40
+ # (special) effects / filters / etc
41
41
  require 'pixelart/led'
42
42
  require 'pixelart/sketch'
43
+ require 'pixelart/transparent'
44
+ require 'pixelart/silhouette'
45
+
43
46
 
44
47
  ## (special) effects / filters that require imagemagick
45
48
 
@@ -18,6 +18,20 @@ class ImageComposite < Image # check: (re)name to Collage, Sheet, Sprites, or s
18
18
  @tile_width = kwargs[:width] || kwargs[:tile_width] || TILE_WIDTH
19
19
  @tile_height = kwargs[:height] || kwargs[:tile_height] || TILE_HEIGHT
20
20
 
21
+ ## check for background
22
+ background = kwargs[:background] || kwargs[:tile_background]
23
+
24
+ if background
25
+ ## wrap into an array if not already an array
26
+ ## and convert all colors to true rgba colors as integer numbers
27
+ background = [background] unless background.is_a?( Array )
28
+ @background_colors = background.map { |color| Color.parse( color ) }
29
+ else
30
+ ## todo/check: use empty array instead of nil - why? why not?
31
+ @background_colors = nil
32
+ end
33
+
34
+
21
35
  ## todo/fix: check type - args[0] is Image!!!
22
36
  if args.size == 1 ## assume "copy" c'tor with passed in image
23
37
  img = args[0] ## pass image through as-is
@@ -32,12 +46,25 @@ class ImageComposite < Image # check: (re)name to Collage, Sheet, Sprites, or s
32
46
  @tile_rows = args[1] || 3
33
47
  @tile_count = 0 # (track) current index (of added images)
34
48
 
35
- img = ChunkyPNG::Image.new( @tile_cols * @tile_width,
36
- @tile_rows * @tile_height )
49
+ background_color = if @background_colors && @background_colors.size == 1
50
+ @background_colors[0]
51
+ else
52
+ 0 # note: 0 is transparent (0) true color
53
+ end
54
+
55
+ ## todo/check - always auto-fill complete image (even if empty/no tiles)
56
+ ## with background color if only one background color
57
+ ## why? why not??? or always follow the "model"
58
+ ## with more than one background color???
59
+ img = ChunkyPNG::Image.new( @tile_cols * @tile_width,
60
+ @tile_rows * @tile_height,
61
+ background_color )
62
+
37
63
  else
38
64
  raise ArgumentError, "cols, rows or image arguments expected; got: #{args.inspect}"
39
65
  end
40
66
 
67
+
41
68
  puts " #{img.height}x#{img.width} (height x width)"
42
69
 
43
70
  super( nil, nil, img )
@@ -46,19 +73,46 @@ class ImageComposite < Image # check: (re)name to Collage, Sheet, Sprites, or s
46
73
 
47
74
  def count() @tile_count; end
48
75
  alias_method :size, :count ## add size alias (confusing if starting with 0?) - why? why not?
76
+ alias_method :tile_count, :count
77
+
78
+ def tile_width() @tile_width; end
79
+ def tile_height() @tile_height; end
80
+
81
+
49
82
 
50
83
  #####
51
84
  # set / add tile
52
-
53
- def add( image )
85
+ def _add( image )
54
86
  y, x = @tile_count.divmod( @tile_cols )
55
87
 
56
88
  puts " [#{@tile_count}] @ (#{x}/#{y}) #{image.width}x#{image.height} (height x width)"
57
89
 
90
+ ## note: only used if more than one background color specified
91
+ ## needs to cycle through
92
+ if @background_colors && @background_colors.size > 1
93
+ i = x + y*@tile_cols
94
+
95
+ ## note: cycle through background color for now
96
+ background_color = @background_colors[i % @background_colors.size]
97
+ background = Image.new( @tile_width, @tile_height, background_color ) ## todo/chekc: use "raw" ChunkyPNG:Image here - why? why not?
98
+ background.compose!( image )
99
+ image = background ## switch - make image with background new image
100
+ end
101
+
58
102
  ## note: image.image - "unwrap" the "raw" ChunkyPNG::Image
59
103
  @img.compose!( image.image, x*@tile_width, y*@tile_height )
60
104
  @tile_count += 1
61
105
  end
106
+
107
+ def add( image_or_images ) ## note: allow adding of image OR array of images
108
+ if image_or_images.is_a?( Array )
109
+ images = image_or_images
110
+ images.each { |image| _add( image ) }
111
+ else
112
+ image = image_or_images
113
+ _add( image )
114
+ end
115
+ end
62
116
  alias_method :<<, :add
63
117
 
64
118
 
@@ -89,6 +89,12 @@ end
89
89
  alias_method :scale, :zoom
90
90
 
91
91
 
92
+ def crop( x, y, crop_width, crop_height )
93
+ Image.new( nil, nil,
94
+ image.crop( x,y, crop_width, crop_height ) )
95
+ end
96
+
97
+
92
98
 
93
99
  #######################
94
100
  ## filter / effects
@@ -0,0 +1,35 @@
1
+ module Pixelart
2
+
3
+
4
+ ## todo/check:
5
+ ## use a different name for silhouette
6
+ ## - why not - outline ???
7
+ ## or - shadow ???
8
+ ## or - profile ???
9
+ ## or - figure ???
10
+ ## or - shape ???
11
+ ## or - form ???
12
+
13
+ class Image
14
+ def silhouette( color='#000000' )
15
+ color = Color.parse( color )
16
+
17
+ img = Image.new( @img.width, @img.height )
18
+
19
+ @img.width.times do |x|
20
+ @img.height.times do |y|
21
+ pixel = @img[x,y]
22
+
23
+ img[x,y] = if pixel == Color::TRANSPARENT # transparent (0)
24
+ Color::TRANSPARENT
25
+ else
26
+ color
27
+ end
28
+ end
29
+ end
30
+ img
31
+ end
32
+
33
+ end # class Image
34
+
35
+ end # module Pixelart
@@ -0,0 +1,60 @@
1
+
2
+ module Pixelart
3
+ class Image
4
+
5
+ def transparent( style = :solid, fuzzy: false )
6
+ img = Image.new( width, height )
7
+
8
+
9
+ background = self[0,0]
10
+
11
+ bh,bs,bl = Color.to_hsl( background )
12
+ bh = (bh % 360) ## might might negative degree (always make positive)
13
+
14
+ height.times do |y|
15
+ if style == :linear
16
+ background = self[0,y]
17
+
18
+ bh,bs,bl = Color.to_hsl( background )
19
+ bh = (bh % 360) ## might might negative degree (always make positive)
20
+ end
21
+ width.times do |x|
22
+ pixel = self[x,y]
23
+
24
+ if background == 0 ## special case if background is already transparent keep going
25
+ img[x,y] = pixel
26
+ elsif fuzzy
27
+ ## check for more transparents
28
+ ## not s is 0.0 to 0.99 (100%)
29
+ ## and l is 0.0 to 0.99 (100%)
30
+ h,s,l = Color.to_hsl( pixel )
31
+ h = (h % 360) ## might might negative degree (always make positive)
32
+
33
+ ## try some kind-of fuzzy "heuristic" match on background color
34
+ if ((h >= bh-5) && (h <= bh+5)) &&
35
+ ((s >= bs-0.07) && (s <= bs+0.07)) &&
36
+ ((l >= bl-0.07) && (l <= bl+0.07))
37
+ img[x,y] = 0 ## Color::TRANSPARENT
38
+
39
+ if h != bh || s != bs || l != bl
40
+ # report fuzzy background color
41
+ puts " #{x}/#{y} fuzzy background #{[h,s,l]} ~= #{[bh,bs,bl]}"
42
+ end
43
+ else
44
+ img[x,y] = pixel
45
+ end
46
+ else
47
+ if pixel == background
48
+ img[x,y] = 0 ## Color::TRANSPARENT
49
+ else
50
+ img[x,y] = pixel
51
+ end
52
+ end
53
+ end
54
+ end
55
+ img
56
+ end # method transparent
57
+
58
+
59
+ end # class Image
60
+ end # module Pixelart
@@ -3,7 +3,7 @@ module Pixelart
3
3
 
4
4
  MAJOR = 1
5
5
  MINOR = 2
6
- PATCH = 1
6
+ PATCH = 2
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.2.1
4
+ version: 1.2.2
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-13 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -111,11 +111,13 @@ files:
111
111
  - lib/pixelart/misc.rb
112
112
  - lib/pixelart/palette.rb
113
113
  - lib/pixelart/pixelator.rb
114
+ - lib/pixelart/silhouette.rb
114
115
  - lib/pixelart/sketch.rb
115
116
  - lib/pixelart/spots.rb
117
+ - lib/pixelart/transparent.rb
116
118
  - lib/pixelart/vector.rb
117
119
  - lib/pixelart/version.rb
118
- homepage: https://github.com/rubycoco/pixel
120
+ homepage: https://github.com/pixelartexchange/pixel
119
121
  licenses:
120
122
  - Public Domain
121
123
  metadata: {}