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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c090cdc8db292f899c236139eec7643f7511a3ef0d578a5175fd4ca3a6e77edc
4
- data.tar.gz: 0ec735b7b0c0f63b8174e712d82364b01fc7a1c730d74d49be5f8cd2b9701884
3
+ metadata.gz: 419e160a5f8978c34f3fa8fbb79c399747cb628267e32dacdcba7ac9276681c5
4
+ data.tar.gz: 4017536c4d4c091b861248367964a04df890904517135194d971df0d14703283
5
5
  SHA512:
6
- metadata.gz: dc6baa7cb65f20eb65966c99e248854e0550a16749d77a5544e5219a9a305b8f5a6e1d6fe026ff98995e14550f54b9b85a40f1d443e171bcd40550d080314e79
7
- data.tar.gz: f52a914851f557ee3d5b2cf99726dd70f2c33e439c141ca039bc671f945316dfdf57e14c906ed358a8c8131eb959d4ddd48acf76f5f99d5a823a985ff6e432d6
6
+ metadata.gz: 682317f125eef34904ce479f8b95ce4bf9cfc18db7f674d20dbee9504dbb3602d103adad43b0c35ec5f1630b4c0e580c6e99c6f6359ec3db200314c0819b4c2b
7
+ data.tar.gz: 2fcd08dedd0dfeb7ba71eb8608b72403c6794761541578cb1bcfb49188db055aa16898587d5853331b4847552ebe3c52df73489746260c311d4c033b73221a3b
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PixelflowCanvas
4
- VERSION = "0.7.1"
4
+ VERSION = "0.7.2"
5
5
  end
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixelflow_canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Specht