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
121
|
# File 'lib/pixelart/sketch.rb', line 6
def sketch( sketch=4, line: 1,
line_color: Color::BLACK,
colorize: false )
width = @img.width*sketch + (@img.width+1)*line
height = @img.height*sketch + (@img.height+1)*line
puts " #{width}x#{height}"
background_color = colorize ? Color::TRANSPARENT
: Color::WHITE
img = Image.new( width, height, background_color )
@img.width.times do |x|
@img.height.times do |y|
pixel = @img[x,y]
left = x == 0 ? Color::TRANSPARENT : @img[x-1,y]
top = y == 0 ? Color::TRANSPARENT : @img[x ,y-1]
diag = (x==0 || y== 0) ? Color::TRANSPARENT : @img[x-1,y-1]
if pixel != left line.times do |n|
(sketch+line*2).times do |m|
img[ x*sketch + line*x + n,
m + y*sketch + line*y] = line_color
end
end
end
if pixel != top (sketch+line*2).times do |n|
line.times do |m|
img[n + x*sketch + line*x,
y*sketch + line*y + m] = line_color
end
end
end
if x == @img.width-1 && pixel != Color::TRANSPARENT
line.times do |n|
(sketch+line*2).times do |m|
img[ (x+1)*sketch + line*(x+1) + n,
m + y*sketch + line*y] = line_color
end
end
end
if y== @img.height-1 && pixel != Color::TRANSPARENT
(sketch+line*2).times do |n|
line.times do |m|
img[n + x*sketch + line*x,
(y+1)*sketch + line*(y+1) + m] = line_color
end
end
end
if colorize && pixel != Color::TRANSPARENT
sketch.times do |n|
sketch.times do |m|
img[x*sketch + line*(x+1) + n,
y*sketch + line*(y+1) + m] = pixel
end
end
if pixel == left line.times do |n|
sketch.times do |m|
img[x*sketch + line*x + n,
y*sketch + line*(y+1) + m] = pixel
end
end
end
if pixel == top sketch.times do |n|
line.times do |m|
img[x*sketch + line*(x+1) + n,
y*sketch + line*y + m] = pixel
end
end
end
if pixel == left && pixel == top && pixel == diag
line.times do |n|
line.times do |m|
img[x*sketch + line*x + n,
y*sketch + line*y + m] = pixel
end
end
end
end
end end
img
end
|