pixelart 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,32 +1,32 @@
1
- require 'hoe'
2
- require './lib/pixelart/version.rb'
3
-
4
- Hoe.spec 'pixelart' do
5
-
6
- self.version = Pixelart::VERSION
7
-
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
- self.description = summary
10
-
11
- self.urls = { home: 'https://github.com/rubycoco/pixel' }
12
-
13
- self.author = 'Gerald Bauer'
14
- self.email = 'wwwmake@googlegroups.com'
15
-
16
- # switch extension to .markdown for gihub formatting
17
- self.readme_file = 'README.md'
18
- self.history_file = 'CHANGELOG.md'
19
-
20
- self.extra_deps = [
21
- ['chunky_png'],
22
- ['mini_magick'],
23
- ['csvreader'],
24
- ]
25
-
26
- self.licenses = ['Public Domain']
27
-
28
- self.spec_extras = {
29
- required_ruby_version: '>= 2.3'
30
- }
31
-
32
- end
1
+ require 'hoe'
2
+ require './lib/pixelart/version.rb'
3
+
4
+ Hoe.spec 'pixelart' do
5
+
6
+ self.version = Pixelart::VERSION
7
+
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
+ self.description = summary
10
+
11
+ self.urls = { home: 'https://github.com/pixelartexchange/pixelart' }
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'wwwmake@googlegroups.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.extra_deps = [
21
+ ['chunky_png'],
22
+ ['mini_magick'],
23
+ ['csvreader'],
24
+ ]
25
+
26
+ self.licenses = ['Public Domain']
27
+
28
+ self.spec_extras = {
29
+ required_ruby_version: '>= 2.3'
30
+ }
31
+
32
+ end
data/lib/pixelart/base.rb CHANGED
@@ -1,81 +1,87 @@
1
- ###############
2
- # 3rd party
3
- require 'chunky_png'
4
-
5
- # optional
6
- # note: requires installed imagemagick command line installed for usage
7
- require 'mini_magick'
8
-
9
-
10
- # bonus / prologue / convenience 3rd party
11
- require 'csvreader'
12
-
13
-
14
- ## stdlib
15
- require 'pp'
16
- require 'time'
17
- require 'date'
18
- require 'fileutils'
19
-
20
- require 'json'
21
- require 'yaml'
22
-
23
-
24
-
25
-
26
- ## our own code
27
- require 'pixelart/version' # note: let version always go first
28
- require 'pixelart/color'
29
- require 'pixelart/gradient'
30
- require 'pixelart/palette'
31
- require 'pixelart/image'
32
- require 'pixelart/composite'
33
-
34
-
35
- require 'pixelart/pixelator'
36
-
37
- require 'pixelart/misc' ## misc helpers
38
-
39
- #########################
40
- # (special) effects / filters
41
- require 'pixelart/led'
42
- require 'pixelart/sketch'
43
-
44
- ## (special) effects / filters that require imagemagick
45
-
46
-
47
- ## todo/check - use a config block or such - why? why not?
48
- module Pixelart
49
- MAGICK_SCRIPT = './tmp/magick_script.txt'
50
- MAGICK_INPUT = './tmp/magick_input.png'
51
- MAGICK_OUTPUT = './tmp/magick_output.png'
52
- end
53
-
54
- require 'pixelart/vector' ## vector graphics helpers
55
-
56
-
57
- require 'pixelart/spots'
58
- require 'pixelart/blur'
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
- ##########
67
- # add some spelling convenience variants
68
- PixelArt = Pixelart
69
-
70
- module Pixelart
71
- Palette256 = Palette8Bit = Palette8bit
72
-
73
- Palette256Image = Palette8BitImage = Palette8bitImage =
74
- ImagePalette256 = ImagePalette8Bit = ImagePalette8bit
75
-
76
- CompositeImage = ImageComposite
77
- end
78
-
79
-
80
-
81
- puts Pixelart.banner # say hello
1
+ ###############
2
+ # 3rd party
3
+ require 'chunky_png'
4
+
5
+ # optional
6
+ # note: requires installed imagemagick command line installed for usage
7
+ require 'mini_magick'
8
+
9
+
10
+ # bonus / prologue / convenience 3rd party
11
+ require 'csvreader'
12
+
13
+
14
+ ## stdlib
15
+ require 'pp'
16
+ require 'time'
17
+ require 'date'
18
+ require 'fileutils'
19
+
20
+ require 'json'
21
+ require 'yaml'
22
+
23
+
24
+
25
+
26
+ ## our own code
27
+ require 'pixelart/version' # note: let version always go first
28
+ require 'pixelart/color'
29
+ require 'pixelart/gradient'
30
+ require 'pixelart/palette'
31
+ require 'pixelart/image'
32
+ require 'pixelart/composite'
33
+
34
+
35
+ require 'pixelart/pixelator'
36
+
37
+ require 'pixelart/misc' ## misc helpers
38
+ require 'pixelart/stripes'
39
+
40
+ #########################
41
+ # (special) effects / filters / etc
42
+ require 'pixelart/circle'
43
+ require 'pixelart/led'
44
+ require 'pixelart/sketch'
45
+ require 'pixelart/transparent'
46
+ require 'pixelart/silhouette'
47
+ require 'pixelart/ukraine'
48
+
49
+
50
+ ## (special) effects / filters that require imagemagick
51
+
52
+
53
+ ## todo/check - use a config block or such - why? why not?
54
+ module Pixelart
55
+ MAGICK_SCRIPT = './tmp/magick_script.txt'
56
+ MAGICK_INPUT = './tmp/magick_input.png'
57
+ MAGICK_OUTPUT = './tmp/magick_output.png'
58
+ end
59
+
60
+ require 'pixelart/vector' ## vector graphics helpers
61
+
62
+
63
+ require 'pixelart/spots'
64
+ require 'pixelart/blur'
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+ ##########
73
+ # add some spelling convenience variants
74
+ PixelArt = Pixelart
75
+
76
+ module Pixelart
77
+ Palette256 = Palette8Bit = Palette8bit
78
+
79
+ Palette256Image = Palette8BitImage = Palette8bitImage =
80
+ ImagePalette256 = ImagePalette8Bit = ImagePalette8bit
81
+
82
+ CompositeImage = ImageComposite
83
+ end
84
+
85
+
86
+
87
+ puts Pixelart.banner # say hello
data/lib/pixelart/blur.rb CHANGED
@@ -1,19 +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
-
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,46 @@
1
+ ###
2
+ #
3
+ # add more circle aliases
4
+ # e.g. circular / round or such - why? why not?
5
+
6
+
7
+ module Pixelart
8
+
9
+ class Image
10
+ def circle
11
+ ### for radius use min of width / height
12
+ r = [@img.width, @img.height].min / 2
13
+
14
+ center_x = width / 2
15
+ center_y = height / 2
16
+
17
+ ################
18
+ # try with 96x96
19
+ # center_x: 96 / 2 = 48
20
+ # center_y: 96 / 2 = 48
21
+ #
22
+ # r: 96 / 2 = 48
23
+
24
+ img = Image.new( @img.width, @img.height )
25
+
26
+ @img.width.times do |x|
27
+ @img.height.times do |y|
28
+
29
+ ## change to float calcuation (instead of ints) - why? why not?
30
+ xx, yy, rr = x - center_x,
31
+ y - center_y,
32
+ r
33
+
34
+ img[ x, y] = if xx*xx+yy*yy < rr*rr
35
+ @img[ x, y ]
36
+ else
37
+ 0 ## transparent - alpha(0)
38
+ end
39
+ end
40
+ end
41
+
42
+ img
43
+ end
44
+ end # class Image
45
+
46
+ end # module Pixelart
@@ -1,131 +1,131 @@
1
- module Pixelart
2
-
3
-
4
- class Color
5
- TRANSPARENT = 0 # rgba( 0, 0, 0, 0)
6
- BLACK = 0xff # rgba( 0, 0, 0,255)
7
- WHITE = 0xffffffff # rgba(255,255,255,255)
8
-
9
-
10
- def self.parse( color )
11
- if color.is_a?( Integer ) ## e.g. assumes ChunkyPNG::Color.rgb() or such
12
- color ## pass through as is 1:1
13
- elsif color.is_a?( Array ) ## assume array of hsl(a) e. g. [180, 0.86, 0.88]
14
- from_hsl( *color )
15
- elsif color.is_a?( String )
16
- if color.downcase == 'transparent' ## special case for builtin colors
17
- TRANSPARENT
18
- else
19
- ## note: return an Integer !!! (not a Color class or such!!! )
20
- from_hex( color )
21
- end
22
- else
23
- raise ArgumentError, "unknown color format; cannot parse - expected rgb hex string e.g. d3d3d3"
24
- end
25
- end
26
-
27
- def self.from_hex( hex )
28
- ## Creates a color by converting it from a string in hex notation.
29
- ##
30
- ## It supports colors with (#rrggbbaa) or without (#rrggbb)
31
- ## alpha channel as well as the 3-digit short format (#rgb)
32
- ## for those without. Color strings may include
33
- ## the prefix "0x" or "#"".
34
- ChunkyPNG::Color.from_hex( hex )
35
- end
36
-
37
- def self.from_hsl( hue, saturation, lightness, alpha=255)
38
- ChunkyPNG::Color.from_hsl( hue,
39
- saturation,
40
- lightness,
41
- alpha )
42
- end
43
-
44
-
45
- def self.to_hex( color, include_alpha: true )
46
- ChunkyPNG::Color.to_hex( color, include_alpha )
47
- end
48
-
49
- def self.to_hsl( color, include_alpha: true )
50
- # Returns an array with the separate HSL components of a color.
51
- ChunkyPNG::Color.to_hsl( color, include_alpha )
52
- end
53
-
54
- def self.r( color ) ChunkyPNG::Color.r( color ); end
55
- def self.g( color ) ChunkyPNG::Color.g( color ); end
56
- def self.b( color ) ChunkyPNG::Color.b( color ); end
57
-
58
- def self.rgb( r, g, b ) ChunkyPNG::Color.rgb( r, g, b); end
59
-
60
-
61
-
62
- ## known built-in color names
63
- def self.build_names
64
- names = {
65
- '#00000000' => 'TRANSPARENT',
66
- '#000000ff' => 'BLACK',
67
- '#ffffffff' => 'WHITE',
68
- }
69
-
70
- ## auto-add grayscale 1 to 254
71
- (1..254).each do |n|
72
- hex = "#" + ('%02x' % n)*3
73
- hex << "ff" ## add alpha channel (255)
74
- names[ hex ] = "8-BIT GRAYSCALE ##{n}"
75
- end
76
-
77
- names
78
- end
79
-
80
- NAMES = build_names
81
-
82
-
83
-
84
- def self.format( color )
85
- rgb = [r(color),
86
- g(color),
87
- b(color)]
88
-
89
- # rgb in hex (string format)
90
- # note: do NOT include alpha channel for now - why? why not?
91
- hex = "#" + rgb.map{|num| '%02x' % num }.join
92
-
93
- hsl = to_hsl( color )
94
- ## get alpha channel (transparency) for hsla
95
- alpha = hsl[3]
96
-
97
-
98
- buf = ''
99
- buf << hex
100
- buf << " / "
101
- buf << "rgb("
102
- buf << "%3d " % rgb[0]
103
- buf << "%3d " % rgb[1]
104
- buf << "%3d)" % rgb[2]
105
- buf << " - "
106
- buf << "hsl("
107
- buf << "%3d° " % (hsl[0] % 360)
108
- buf << "%3d%% " % (hsl[1]*100+0.5).to_i
109
- buf << "%3d%%)" % (hsl[2]*100+0.5).to_i
110
-
111
- if alpha != 255
112
- buf << " - α(%3d%%)" % (alpha*100/255+0.5).to_i
113
- else
114
- buf << " " ## add empty for 255 (full opacity)
115
- end
116
-
117
- ## note: add alpha channel to hex
118
- alpha_hex = '%02x' % alpha
119
- name = NAMES[ hex+alpha_hex ]
120
- buf << " - #{name}" if name
121
-
122
- buf
123
- end
124
- class << self
125
- alias_method :fmt, :format
126
- end
127
-
128
- end # class Color
129
- end # module Pixelart
130
-
131
-
1
+ module Pixelart
2
+
3
+
4
+ class Color
5
+ TRANSPARENT = 0 # rgba( 0, 0, 0, 0)
6
+ BLACK = 0xff # rgba( 0, 0, 0,255)
7
+ WHITE = 0xffffffff # rgba(255,255,255,255)
8
+
9
+
10
+ def self.parse( color )
11
+ if color.is_a?( Integer ) ## e.g. assumes ChunkyPNG::Color.rgb() or such
12
+ color ## pass through as is 1:1
13
+ elsif color.is_a?( Array ) ## assume array of hsl(a) e. g. [180, 0.86, 0.88]
14
+ from_hsl( *color )
15
+ elsif color.is_a?( String )
16
+ if color.downcase == 'transparent' ## special case for builtin colors
17
+ TRANSPARENT
18
+ else
19
+ ## note: return an Integer !!! (not a Color class or such!!! )
20
+ from_hex( color )
21
+ end
22
+ else
23
+ raise ArgumentError, "unknown color format; cannot parse - expected rgb hex string e.g. d3d3d3"
24
+ end
25
+ end
26
+
27
+ def self.from_hex( hex )
28
+ ## Creates a color by converting it from a string in hex notation.
29
+ ##
30
+ ## It supports colors with (#rrggbbaa) or without (#rrggbb)
31
+ ## alpha channel as well as the 3-digit short format (#rgb)
32
+ ## for those without. Color strings may include
33
+ ## the prefix "0x" or "#"".
34
+ ChunkyPNG::Color.from_hex( hex )
35
+ end
36
+
37
+ def self.from_hsl( hue, saturation, lightness, alpha=255)
38
+ ChunkyPNG::Color.from_hsl( hue,
39
+ saturation,
40
+ lightness,
41
+ alpha )
42
+ end
43
+
44
+
45
+ def self.to_hex( color, include_alpha: true )
46
+ ChunkyPNG::Color.to_hex( color, include_alpha )
47
+ end
48
+
49
+ def self.to_hsl( color, include_alpha: true )
50
+ # Returns an array with the separate HSL components of a color.
51
+ ChunkyPNG::Color.to_hsl( color, include_alpha )
52
+ end
53
+
54
+ def self.r( color ) ChunkyPNG::Color.r( color ); end
55
+ def self.g( color ) ChunkyPNG::Color.g( color ); end
56
+ def self.b( color ) ChunkyPNG::Color.b( color ); end
57
+
58
+ def self.rgb( r, g, b ) ChunkyPNG::Color.rgb( r, g, b); end
59
+
60
+
61
+
62
+ ## known built-in color names
63
+ def self.build_names
64
+ names = {
65
+ '#00000000' => 'TRANSPARENT',
66
+ '#000000ff' => 'BLACK',
67
+ '#ffffffff' => 'WHITE',
68
+ }
69
+
70
+ ## auto-add grayscale 1 to 254
71
+ (1..254).each do |n|
72
+ hex = "#" + ('%02x' % n)*3
73
+ hex << "ff" ## add alpha channel (255)
74
+ names[ hex ] = "8-BIT GRAYSCALE ##{n}"
75
+ end
76
+
77
+ names
78
+ end
79
+
80
+ NAMES = build_names
81
+
82
+
83
+
84
+ def self.format( color )
85
+ rgb = [r(color),
86
+ g(color),
87
+ b(color)]
88
+
89
+ # rgb in hex (string format)
90
+ # note: do NOT include alpha channel for now - why? why not?
91
+ hex = "#" + rgb.map{|num| '%02x' % num }.join
92
+
93
+ hsl = to_hsl( color )
94
+ ## get alpha channel (transparency) for hsla
95
+ alpha = hsl[3]
96
+
97
+
98
+ buf = ''
99
+ buf << hex
100
+ buf << " / "
101
+ buf << "rgb("
102
+ buf << "%3d " % rgb[0]
103
+ buf << "%3d " % rgb[1]
104
+ buf << "%3d)" % rgb[2]
105
+ buf << " - "
106
+ buf << "hsl("
107
+ buf << "%3d° " % (hsl[0] % 360)
108
+ buf << "%3d%% " % (hsl[1]*100+0.5).to_i
109
+ buf << "%3d%%)" % (hsl[2]*100+0.5).to_i
110
+
111
+ if alpha != 255
112
+ buf << " - α(%3d%%)" % (alpha*100/255+0.5).to_i
113
+ else
114
+ buf << " " ## add empty for 255 (full opacity)
115
+ end
116
+
117
+ ## note: add alpha channel to hex
118
+ alpha_hex = '%02x' % alpha
119
+ name = NAMES[ hex+alpha_hex ]
120
+ buf << " - #{name}" if name
121
+
122
+ buf
123
+ end
124
+ class << self
125
+ alias_method :fmt, :format
126
+ end
127
+
128
+ end # class Color
129
+ end # module Pixelart
130
+
131
+