6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/pixelart/spots.rb', line 6
def spots_hidef( spot=10,
spacing: 0,
center: nil,
radius: nil,
background: nil,
lightness: nil,
odd: false )
width = @img.width*spot+(@img.width-1)*spacing
height = @img.height*spot+(@img.height-1)*spacing
settings = { spot: spot
}
settings[ :spacing ] = spacing if spacing
settings[ :center ] = center if center
settings[ :radius ] = radius if radius
settings[ :background ] = background if background
settings[ :lightness ] = lightness if lightness
settings[ :odd ] = odd if odd
v = Vector.new( width, height, header: <<TXT )
generated by pixelart/v#{VERSION} on #{Time.now.utc}
spots_hidef with settings:
#{settings.to_json}
TXT
min_center, max_center = center ? center : [0,0]
min_radius, max_radius = radius ? radius : [0,0]
background_colors = if background
background_ary = background.is_a?( Array) ? background : [background]
background_ary.map { |background| Color.parse( background ) }
else
[0] end
min_lightness, max_lightness = lightness ? lightness : [0.0,0.0]
@img.width.times do |x|
@img.height.times do |y|
color = @img[ x, y ]
if color == 0 next if background.nil?
color = if background_colors.size == 1
background_colors[0]
else background_colors[ rand( background_colors.size ) ]
end
end
if lightness
h,s,l = Color.to_hsl( color, include_alpha: false )
h = h % 360
l_diff = min_lightness +
(max_lightness-min_lightness)*rand()
lnew = [1.0, l+l_diff].min
lnew = [0.0, lnew].max
color = Color.from_hsl( h,
[1.0, s].min,
lnew )
end
color_hex = Color.to_hex( color, include_alpha: true )
cx_offset,
cy_offset = if center [(spot/2 + min_center) + rand( max_center-min_center ),
(spot/2 + min_center) + rand( max_center-min_center )]
else
[spot/2, spot/2]
end
cx = x*spot + x*spacing + cx_offset
cy = y*spot + y*spacing + cx_offset
r = if radius min_radius + rand( max_radius-min_radius )
else
spot/2
end
cx += spot/2 if odd && (y % 2 == 1)
v.circle( cx: cx, cy: cy, r: r, fill: color_hex)
end
end
v
end
|