pixelart 1.2.0 → 1.2.1

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: 798a4eb7b61556c0c79889d01d404a499598286779e009fa71304986f4d68c31
4
- data.tar.gz: 9b17446fe914c1b62135c1e1432bc2debf74037ca9e602feb25e71ec7088b117
3
+ metadata.gz: e407d45e71520e9e7c34448811a80e796254aba70c791e3497df00b0fa700486
4
+ data.tar.gz: 55c324e6cf901bd8ed78fa48d97f27a3f66c60d314d070a457ef4e272ebe9f01
5
5
  SHA512:
6
- metadata.gz: 8073e67ffd10361088fd66b768d4aa5927c2f65cdd54389615b980c2181ec8cde2a2ad21eced1fe7a756af7ce2e7c681b2aea4a89aed2c869ad04a956388d54a
7
- data.tar.gz: b69918e012f6270a9aa0817d69e094bb52cd12ed05399ac566872efdd2174af9c9534ef2e72f4f34f4d3f1bbe4d5062aedcbb42deb67ff55c52a005965b2d969
6
+ metadata.gz: 6e36d0cb47e5e36b81b3a3f47d62fa119b898f9bbf11c422d53f5ab3cfdfe022a8f3dda3d82ea1db4f2eb422376ea82ac153922add94caeb5aff97214813a81a
7
+ data.tar.gz: b8957560272efd295ef73bdd450531dc9d631fd293215dbd0f9f835bdbdb50669018f1d24a27a6df45d8714a2633bc1d22a6b6761979dc7804b3c5290c2f1eaa
data/Rakefile CHANGED
@@ -20,6 +20,7 @@ Hoe.spec 'pixelart' do
20
20
  self.extra_deps = [
21
21
  ['chunky_png'],
22
22
  ['mini_magick'],
23
+ ['csvreader'],
23
24
  ]
24
25
 
25
26
  self.licenses = ['Public Domain']
data/lib/pixelart/base.rb CHANGED
@@ -7,6 +7,9 @@ require 'chunky_png'
7
7
  require 'mini_magick'
8
8
 
9
9
 
10
+ # bonus / prologue / convenience 3rd party
11
+ require 'csvreader'
12
+
10
13
 
11
14
  ## stdlib
12
15
  require 'pp'
@@ -64,18 +64,21 @@ end
64
64
 
65
65
 
66
66
 
67
- def zoom( zoom=2 )
67
+ def zoom( zoom=2, spacing: 0 )
68
68
  ## create a new zoom factor x image (2x, 3x, etc.)
69
69
 
70
- img = Image.new( @img.width*zoom,
71
- @img.height*zoom )
70
+ width = @img.width*zoom+(@img.width-1)*spacing
71
+ height = @img.height*zoom+(@img.height-1)*spacing
72
72
 
73
- @img.height.times do |y|
74
- @img.width.times do |x|
73
+ img = Image.new( width, height )
74
+
75
+ @img.width.times do |x|
76
+ @img.height.times do |y|
75
77
  pixel = @img[x,y]
76
78
  zoom.times do |n|
77
79
  zoom.times do |m|
78
- img[n+zoom*x,m+zoom*y] = pixel
80
+ img[n+zoom*x+spacing*x,
81
+ m+zoom*y+spacing*y] = pixel
79
82
  end
80
83
  end
81
84
  end # each x
@@ -25,6 +25,53 @@ class Vector # holds a vector graphics image (in source)
25
25
  end
26
26
  end # class Circle
27
27
 
28
+ class Path < Shape
29
+ def initialize( fill:, stroke: )
30
+ @commands = []
31
+ @fill = fill
32
+ @stroke = stroke
33
+ end
34
+
35
+ def move_to( x, y ) ## add a move_to instruction
36
+ @commands << ['M', x, y]
37
+ self
38
+ end
39
+
40
+ def line_to( x, y )
41
+ @commands << ['L', x, y]
42
+ self
43
+ end
44
+
45
+ def line( *coords ) ## move_to/line_to all-in-one shortcut
46
+ ## todo/check - assert coords has at least two x/y pairs - why? why not?
47
+ move_to( *coords[0..1] )
48
+ coords[2..-1].each_slice( 2) do |coord|
49
+ line_to( *coord )
50
+ end
51
+ self
52
+ end
53
+
54
+
55
+
56
+ def to_svg
57
+ buf = %Q{<path style="stroke: #{@stroke}; fill: #{@fill || 'none'};" }
58
+ buf << %Q{d="}
59
+ last_command = ''
60
+ @commands.each_with_index do |command,i|
61
+ buf << " " if i > 0 # add space separator
62
+
63
+ ## "optimize" - that is, do not repead command if same as before
64
+ buf << command[0] if command[0] != last_command
65
+ buf << "#{command[1]} #{command[2]}"
66
+ last_command = command[0]
67
+ end
68
+
69
+ buf << %Q{"}
70
+ buf << "/>"
71
+ buf
72
+ end
73
+ end # class Path
74
+
28
75
 
29
76
 
30
77
  def initialize( width, height, header: nil )
@@ -39,6 +86,14 @@ class Vector # holds a vector graphics image (in source)
39
86
  @shapes << Circle.new( cx, cy, r, fill: fill )
40
87
  end
41
88
 
89
+ ## note: default stroke (color) to black (#000000) for now - why? why not?
90
+ def path( stroke: '#000000', fill: nil )
91
+ path = Path.new( stroke: stroke, fill: fill )
92
+ @shapes << path
93
+
94
+ path ## note: MUST return "inner" path shape for chaining "dsl-like" methods / commands
95
+ end
96
+
42
97
 
43
98
 
44
99
  def to_image
@@ -3,7 +3,7 @@ module Pixelart
3
3
 
4
4
  MAJOR = 1
5
5
  MINOR = 2
6
- PATCH = 0
6
+ PATCH = 1
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
data/lib/pixelart.rb CHANGED
@@ -8,3 +8,5 @@ require 'pixelart/base' # aka "strict(er)" version
8
8
  # make Image, Color, Palette8bit, etc top-level
9
9
  include Pixelart
10
10
 
11
+
12
+
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.0
4
+ version: 1.2.1
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-10-02 00:00:00.000000000 Z
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: csvreader
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rdoc
43
57
  requirement: !ruby/object:Gem::Requirement