pixelart 1.0.0 → 1.1.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/Manifest.txt +2 -0
- data/Rakefile +1 -0
- data/lib/pixelart/base.rb +33 -2
- data/lib/pixelart/blur.rb +19 -0
- data/lib/pixelart/spots.rb +129 -0
- data/lib/pixelart/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb520f7fc94b0b7d62336829d92929bbeb27600f0042ab3f68d81b6e5b26d2b3
|
4
|
+
data.tar.gz: ed4756f69b5f5d5ca696a1105aa348b5b86ab33653ff7c34d1b24f4dc75e244f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa3d9eeb12a4a59e4f6ec3191e432ae11d7cf44465e0b6722c69bda985af6caeea3a4390f773d4d535a38096f483c3d9467b03f63ed6547a168f79361db1991
|
7
|
+
data.tar.gz: d7f6d039eddc337b62ca22b338712a26423781b2a57703429469d376c02af0fef6aadd9182f4fb2cb755dc83f27c6bcbb97519ee528c01169ba8070534c7c377
|
data/Manifest.txt
CHANGED
@@ -4,6 +4,7 @@ README.md
|
|
4
4
|
Rakefile
|
5
5
|
lib/pixelart.rb
|
6
6
|
lib/pixelart/base.rb
|
7
|
+
lib/pixelart/blur.rb
|
7
8
|
lib/pixelart/color.rb
|
8
9
|
lib/pixelart/composite.rb
|
9
10
|
lib/pixelart/gradient.rb
|
@@ -13,4 +14,5 @@ lib/pixelart/misc.rb
|
|
13
14
|
lib/pixelart/palette.rb
|
14
15
|
lib/pixelart/pixelator.rb
|
15
16
|
lib/pixelart/sketch.rb
|
17
|
+
lib/pixelart/spots.rb
|
16
18
|
lib/pixelart/version.rb
|
data/Rakefile
CHANGED
data/lib/pixelart/base.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
|
-
|
1
|
+
###############
|
2
|
+
# 3rd party
|
2
3
|
require 'chunky_png'
|
3
4
|
|
5
|
+
# optional
|
6
|
+
# note: requires installed imagemagick command line installed for usage
|
7
|
+
require 'mini_magick'
|
8
|
+
|
9
|
+
|
10
|
+
|
4
11
|
## stdlib
|
5
12
|
require 'pp'
|
6
13
|
require 'time'
|
7
14
|
require 'date'
|
8
15
|
require 'fileutils'
|
9
16
|
|
17
|
+
require 'json'
|
18
|
+
require 'yaml'
|
19
|
+
|
20
|
+
|
21
|
+
|
10
22
|
|
11
23
|
## our own code
|
12
24
|
require 'pixelart/version' # note: let version always go first
|
@@ -20,9 +32,28 @@ require 'pixelart/pixelator'
|
|
20
32
|
|
21
33
|
require 'pixelart/misc' ## misc helpers
|
22
34
|
|
23
|
-
|
35
|
+
#########################
|
36
|
+
# (special) effects / filters
|
37
|
+
require 'pixelart/led'
|
24
38
|
require 'pixelart/sketch'
|
25
39
|
|
40
|
+
## (special) effects / filters that require imagemagick
|
41
|
+
|
42
|
+
|
43
|
+
## todo/check - use a config block or such - why? why not?
|
44
|
+
module Pixelart
|
45
|
+
MAGICK_SCRIPT = './tmp/magick_script.txt'
|
46
|
+
MAGICK_INPUT = './tmp/magick_input.png'
|
47
|
+
MAGICK_OUTPUT = './tmp/magick_output.png'
|
48
|
+
end
|
49
|
+
|
50
|
+
require 'pixelart/spots'
|
51
|
+
require 'pixelart/blur'
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
26
57
|
|
27
58
|
|
28
59
|
##########
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Pixelart
|
2
|
+
|
3
|
+
class Image
|
4
|
+
|
5
|
+
def blur( blur=2 )
|
6
|
+
@img.save( MAGICK_INPUT )
|
7
|
+
|
8
|
+
MiniMagick::Tool::Magick.new do |magick|
|
9
|
+
magick << MAGICK_INPUT
|
10
|
+
magick.blur( "#{blur}x#{blur}" )
|
11
|
+
magick << MAGICK_OUTPUT
|
12
|
+
end
|
13
|
+
|
14
|
+
Image.read( MAGICK_OUTPUT )
|
15
|
+
end
|
16
|
+
|
17
|
+
end # class Image
|
18
|
+
end # class Pixelart
|
19
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module Pixelart
|
2
|
+
|
3
|
+
class Image
|
4
|
+
|
5
|
+
|
6
|
+
def spots( spot=10,
|
7
|
+
spacing: 0,
|
8
|
+
center: nil,
|
9
|
+
radius: nil,
|
10
|
+
background: nil,
|
11
|
+
lightness: nil,
|
12
|
+
odd: false )
|
13
|
+
|
14
|
+
width = @img.width
|
15
|
+
height = @img.height
|
16
|
+
## puts " #{width}x#{height}"
|
17
|
+
|
18
|
+
min_center, max_center = center ? center : [0,0]
|
19
|
+
min_radius, max_radius = radius ? radius : [0,0]
|
20
|
+
|
21
|
+
background_color = background ? Color.parse( background ) : 0
|
22
|
+
|
23
|
+
min_lightness, max_lightness = lightness ? lightness : [0.0,0.0]
|
24
|
+
|
25
|
+
## note: magick command line might get way too long, thus,
|
26
|
+
## save commands to a script
|
27
|
+
script = String.new('')
|
28
|
+
script << "#{MAGICK_INPUT} \\\n"
|
29
|
+
|
30
|
+
|
31
|
+
width.times do |x|
|
32
|
+
height.times do |y|
|
33
|
+
color = @img[ x, y ]
|
34
|
+
|
35
|
+
if color == 0 ## transparent
|
36
|
+
if background ## change transparent to background
|
37
|
+
color = background_color
|
38
|
+
else
|
39
|
+
next ## skip transparent
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
if lightness
|
45
|
+
## todo/check: make it work with alpha too
|
46
|
+
h,s,l = Color.to_hsl( color, include_alpha: false )
|
47
|
+
|
48
|
+
h = h % 360 ## make sure h(ue) is always positive!!!
|
49
|
+
|
50
|
+
## note: rand() return between 0.0 and 1.0
|
51
|
+
l_diff = min_lightness +
|
52
|
+
(max_lightness-min_lightness)*rand()
|
53
|
+
|
54
|
+
lnew = [1.0, l+l_diff].min
|
55
|
+
lnew = [0.0, lnew].max
|
56
|
+
|
57
|
+
## print " #{l}+#{l_diff}=#{lnew} "
|
58
|
+
|
59
|
+
color = Color.from_hsl( h,
|
60
|
+
[1.0, s].min,
|
61
|
+
lnew )
|
62
|
+
end
|
63
|
+
|
64
|
+
## note: return hexstring with leading #
|
65
|
+
# e.g. 0 becomes #00000000
|
66
|
+
# and so on
|
67
|
+
color_hex = Color.to_hex( color, include_alpha: true )
|
68
|
+
script << "-fill '#{color_hex}' "
|
69
|
+
|
70
|
+
cx_offset,
|
71
|
+
cy_offset = if center ## randomize (offset off center +/-)
|
72
|
+
[(spot/2 + min_center) + rand( max_center-min_center ),
|
73
|
+
(spot/2 + min_center) + rand( max_center-min_center )]
|
74
|
+
else
|
75
|
+
[spot/2, ## center
|
76
|
+
spot/2]
|
77
|
+
end
|
78
|
+
|
79
|
+
cx = x*spot + x*spacing + cx_offset
|
80
|
+
cy = y*spot + y*spacing + cx_offset
|
81
|
+
|
82
|
+
px_offset = if radius ## randomize (radius +/-)
|
83
|
+
min_radius + rand( max_radius-min_radius )
|
84
|
+
else
|
85
|
+
spot/2
|
86
|
+
end
|
87
|
+
px = cx + px_offset
|
88
|
+
py = cy
|
89
|
+
|
90
|
+
|
91
|
+
if odd && (y % 2 == 1) ## add odd offset
|
92
|
+
cx += spot/2
|
93
|
+
px += spot/2
|
94
|
+
end
|
95
|
+
|
96
|
+
## circle
|
97
|
+
## give the center and any point on the perimeter (boundary)
|
98
|
+
script << "-draw 'circle #{cx},#{cy},#{px},#{py}' \\\n"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
script << "-write #{MAGICK_OUTPUT}\n"
|
103
|
+
|
104
|
+
|
105
|
+
## use an empty image (canvas) with transparent background
|
106
|
+
## as magick input image
|
107
|
+
canvas = Image.new( width*spot+(width-1)*spacing,
|
108
|
+
height*spot+(height-1)*spacing )
|
109
|
+
canvas.save( MAGICK_INPUT )
|
110
|
+
|
111
|
+
## note: save magick input first (see above) before save script
|
112
|
+
## will (auto-)create missing directories in path (if missing)
|
113
|
+
|
114
|
+
File.open( MAGICK_SCRIPT, 'w:utf-8' ) do |f|
|
115
|
+
f.write( script )
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
MiniMagick::Tool::Magick.new do |magick|
|
120
|
+
magick.script( MAGICK_SCRIPT )
|
121
|
+
end
|
122
|
+
|
123
|
+
Image.read( MAGICK_OUTPUT )
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end # class Image
|
128
|
+
end # class Pixelart
|
129
|
+
|
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.1.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: 2021-09-
|
11
|
+
date: 2021-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mini_magick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rdoc
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +88,7 @@ files:
|
|
74
88
|
- Rakefile
|
75
89
|
- lib/pixelart.rb
|
76
90
|
- lib/pixelart/base.rb
|
91
|
+
- lib/pixelart/blur.rb
|
77
92
|
- lib/pixelart/color.rb
|
78
93
|
- lib/pixelart/composite.rb
|
79
94
|
- lib/pixelart/gradient.rb
|
@@ -83,6 +98,7 @@ files:
|
|
83
98
|
- lib/pixelart/palette.rb
|
84
99
|
- lib/pixelart/pixelator.rb
|
85
100
|
- lib/pixelart/sketch.rb
|
101
|
+
- lib/pixelart/spots.rb
|
86
102
|
- lib/pixelart/version.rb
|
87
103
|
homepage: https://github.com/rubycoco/pixel
|
88
104
|
licenses:
|