pixelflow_canvas 0.7.1 → 0.7.2
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/lib/pixelflow_canvas/version.rb +1 -1
- data/lib/pixelflow_canvas.rb +51 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 419e160a5f8978c34f3fa8fbb79c399747cb628267e32dacdcba7ac9276681c5
|
4
|
+
data.tar.gz: 4017536c4d4c091b861248367964a04df890904517135194d971df0d14703283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 682317f125eef34904ce479f8b95ce4bf9cfc18db7f674d20dbee9504dbb3602d103adad43b0c35ec5f1630b4c0e580c6e99c6f6359ec3db200314c0819b4c2b
|
7
|
+
data.tar.gz: 2fcd08dedd0dfeb7ba71eb8608b72403c6794761541578cb1bcfb49188db055aa16898587d5853331b4847552ebe3c52df73489746260c311d4c033b73221a3b
|
data/lib/pixelflow_canvas.rb
CHANGED
@@ -31,7 +31,7 @@ module Pixelflow
|
|
31
31
|
:nearest => 0,
|
32
32
|
:bilinear => 1,
|
33
33
|
}
|
34
|
-
def initialize(width, height, color_mode = nil)
|
34
|
+
def initialize(width, height, color_mode = nil, &block)
|
35
35
|
@width = 320
|
36
36
|
@height = 180
|
37
37
|
@x = 0
|
@@ -48,10 +48,17 @@ module Pixelflow
|
|
48
48
|
set_size(width, height)
|
49
49
|
set_color_mode(color_mode) if color_mode
|
50
50
|
@last_timestamp = Time.now.to_f
|
51
|
+
if block_given?
|
52
|
+
instance_eval(&block)
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
56
|
attr_reader :width, :height
|
54
57
|
|
58
|
+
def run(&block)
|
59
|
+
instance_eval(&block)
|
60
|
+
end
|
61
|
+
|
55
62
|
def set_size(width, height)
|
56
63
|
@x = 0
|
57
64
|
@y = 0
|
@@ -511,6 +518,49 @@ module Pixelflow
|
|
511
518
|
draw_line(x2, y2, x0, y0)
|
512
519
|
end
|
513
520
|
|
521
|
+
def flood_fill(x, y, r = nil, g = nil, b = nil)
|
522
|
+
x = x.to_i
|
523
|
+
y = y.to_i
|
524
|
+
r ||= @r
|
525
|
+
g ||= @g
|
526
|
+
b ||= @b
|
527
|
+
return if x < 0 || x >= @width || y < 0 || y >= @height
|
528
|
+
sr = 0
|
529
|
+
sg = 0
|
530
|
+
sb = 0
|
531
|
+
if @color_mode == :rgb
|
532
|
+
sr = @screen[(y * @width + x) * 3 + 0]
|
533
|
+
sg = @screen[(y * @width + x) * 3 + 1]
|
534
|
+
sb = @screen[(y * @width + x) * 3 + 2]
|
535
|
+
else
|
536
|
+
sr = @screen[y * @width + x]
|
537
|
+
end
|
538
|
+
stack = [[x, y]]
|
539
|
+
while stack.any?
|
540
|
+
x, y = stack.pop
|
541
|
+
next if x < 0 || x >= @width || y < 0 || y >= @height
|
542
|
+
if @color_mode == :rgb
|
543
|
+
offset = (y * @width + x) * 3
|
544
|
+
if @screen[offset + 0] == sr && @screen[offset + 1] == sg && @screen[offset + 2] == sb
|
545
|
+
set_pixel(x, y)
|
546
|
+
stack.push([x - 1, y])
|
547
|
+
stack.push([x + 1, y])
|
548
|
+
stack.push([x, y - 1])
|
549
|
+
stack.push([x, y + 1])
|
550
|
+
end
|
551
|
+
else
|
552
|
+
offset = y * @width + x
|
553
|
+
if @screen[offset] == sr
|
554
|
+
set_pixel(x, y)
|
555
|
+
stack.push([x - 1, y])
|
556
|
+
stack.push([x + 1, y])
|
557
|
+
stack.push([x, y - 1])
|
558
|
+
stack.push([x, y + 1])
|
559
|
+
end
|
560
|
+
end
|
561
|
+
end
|
562
|
+
end
|
563
|
+
|
514
564
|
# FONT RENDERING
|
515
565
|
|
516
566
|
def self.load_font(font)
|