pixelflow_canvas 0.7.0 → 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: d10f65282a8fbb64155c197de0e1e7711b92120713ff0f6fcf7bd5df530fa54f
4
- data.tar.gz: c4aa8c9cd6b908b0e6083c0704eb54fc02f92fc6fc10a0cad8d977f2c473b1b1
3
+ metadata.gz: 419e160a5f8978c34f3fa8fbb79c399747cb628267e32dacdcba7ac9276681c5
4
+ data.tar.gz: 4017536c4d4c091b861248367964a04df890904517135194d971df0d14703283
5
5
  SHA512:
6
- metadata.gz: 48dc9dd9a4b65481e99c153af7aeed48af54fed4a1790a19ea00a2738cf10e060509e21a929fa5c50d1dd3828087a39f8e2800cceb0e90ce88ed7eb6aa5e713c
7
- data.tar.gz: 6c31e9d538cd5bfe00408a573e2c8ece9e6e677bb8412870e6de7ba3c4158fe8d3eaaed52d3dfdc0840f60e97c1682b8fe991b14979b277a0bdf12d4923639f8
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.0"
4
+ VERSION = "0.7.2"
5
5
  end
@@ -6,6 +6,7 @@ require 'chunky_png'
6
6
  require 'json'
7
7
  require 'socket'
8
8
  require 'time'
9
+ require 'yaml'
9
10
 
10
11
  module Pixelflow
11
12
  class Canvas
@@ -30,7 +31,7 @@ module Pixelflow
30
31
  :nearest => 0,
31
32
  :bilinear => 1,
32
33
  }
33
- def initialize(width, height, color_mode = nil)
34
+ def initialize(width, height, color_mode = nil, &block)
34
35
  @width = 320
35
36
  @height = 180
36
37
  @x = 0
@@ -47,10 +48,17 @@ module Pixelflow
47
48
  set_size(width, height)
48
49
  set_color_mode(color_mode) if color_mode
49
50
  @last_timestamp = Time.now.to_f
51
+ if block_given?
52
+ instance_eval(&block)
53
+ end
50
54
  end
51
55
 
52
56
  attr_reader :width, :height
53
57
 
58
+ def run(&block)
59
+ instance_eval(&block)
60
+ end
61
+
54
62
  def set_size(width, height)
55
63
  @x = 0
56
64
  @y = 0
@@ -510,6 +518,49 @@ module Pixelflow
510
518
  draw_line(x2, y2, x0, y0)
511
519
  end
512
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
+
513
564
  # FONT RENDERING
514
565
 
515
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.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Specht