rubysketch 0.3.8 → 0.3.13

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: b5824abb04b555aa085934c3eefb32dc0cf5a79c6bc48945d5706a260c46269d
4
- data.tar.gz: 35d88e63413027b4c8c574b860c2dd9e443cb29f140e9820ec73bacaaf800f05
3
+ metadata.gz: b0b393d392765c48e644231ab449ba437ab05bc61a3369c18b634dcdd7b156bc
4
+ data.tar.gz: 01444dfbf328a526dd607b125bfc03d1ae274b11e13817b5090442258843e63d
5
5
  SHA512:
6
- metadata.gz: 34eaeef4a6992cfa326e16bd58b07e27b4757876129d03d246b717d334620d87d6a412f61757545bd4db561f83f38d8dd9303d255276ae0a544a4731759d853c
7
- data.tar.gz: f0f4d8498f19da6a602cb4b120e91cdaebb718e66d4980433cb2386e0ed45e47aeefd25adb2c03974a93fefe2f862783325cd8c1cf923174f8467825172d647b
6
+ metadata.gz: c768f5c5948a8433d2e5b3317aecad587fb55dea24e45894bbf2c229acc8d61108804835c029ec10cfa5f59cb294bc2817db2f843782ea852274f2d4609b36c3
7
+ data.tar.gz: f638eb0330dd4bb4851375eb2b50b64dfbc7cee366b9d109162381fc7ebfcdb82f663d8457fbea80650a509e89223ced77825c087e45413d10131599c6d13688
@@ -1,6 +1,33 @@
1
1
  # RubySketch ChangeLog
2
2
 
3
3
 
4
+ ## [0.3.13] - 2020-12-12
5
+
6
+ - size(), createCanvas(): default pixelDensity is same as current value
7
+
8
+
9
+ ## [0.3.12] - 2020-12-10
10
+
11
+ - size() and createCanvas() take 'pixelDensity' parameter and default value is 1
12
+
13
+
14
+ ## [0.3.11] - 2020-12-9
15
+
16
+ - add size(), createCanvas() and pixelDensity()
17
+
18
+
19
+ ## [0.3.10] - 2020-12-1
20
+
21
+ - invert angle parameter value for arc() to fix compatibility to processing API
22
+
23
+
24
+ ## [0.3.9] - 2020-11-30
25
+
26
+ - Graphics#beginDraw() can take block to call endDraw automatically
27
+ - Capture#start() always returns nil
28
+ - add delay_camera.rb
29
+
30
+
4
31
  ## [0.3.8] - 2020-11-27
5
32
 
6
33
  - Capture#initialize() can take requestWidth, requestHeight and cameraName
data/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # RubySketch - Processing like Creative Coding Framework
1
+ # RubySketch - Processing compatible Creative Coding Framework
2
2
 
3
3
  by xordog@gmail.com
4
+
5
+
6
+ # How to release
7
+
8
+ ```
9
+ $ rake version:bump:patch message="..."
10
+ $ git push origin --tags
11
+ ```
data/Rakefile CHANGED
@@ -23,3 +23,28 @@ generate_documents
23
23
  build_ruby_gem
24
24
 
25
25
  task :default => :test
26
+
27
+
28
+ namespace :version do
29
+
30
+ namespace :bump do
31
+
32
+ task :major do
33
+ update_and_tag_version 0
34
+ end
35
+
36
+ task :minor do
37
+ update_and_tag_version 1
38
+ end
39
+
40
+ task :patch do
41
+ update_and_tag_version 2
42
+ end
43
+
44
+ task :build do
45
+ update_and_tag_version 3
46
+ end
47
+
48
+ end# bump
49
+
50
+ end# version
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.8
1
+ 0.3.13
@@ -5,7 +5,7 @@
5
5
  require 'rubysketch-processing'
6
6
 
7
7
 
8
- cam = Capture.new 300, 200, Capture.list.last
8
+ cam = Capture.new 300, 300
9
9
  cam.start
10
10
 
11
11
  draw do
@@ -0,0 +1,33 @@
1
+ %w[xot rays reflex rubysketch]
2
+ .map {|s| File.expand_path "../../#{s}/lib", __dir__}
3
+ .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
4
+
5
+ require 'rubysketch-processing'
6
+
7
+
8
+ w, h = width, height
9
+
10
+ cam = Capture.new w, h, Capture.list.last
11
+ cam.start
12
+
13
+ images = 60.times.map {
14
+ Graphics.new w, h
15
+ }
16
+
17
+ draw do
18
+ if frameCount % 2 == 0
19
+ images.unshift images.pop
20
+ images.first.tap do |image|
21
+ image.beginDraw {
22
+ image.image cam, 0, 0
23
+ }
24
+ end
25
+ end
26
+
27
+ background 0
28
+ segment_h= h / images.size
29
+ images.each.with_index do |image, i|
30
+ y = i * segment_h
31
+ copy image, 0, y, w, segment_h, 0, y, w, segment_h
32
+ end
33
+ end
@@ -767,11 +767,11 @@ module RubySketch
767
767
 
768
768
  # Start capturing.
769
769
  #
770
- # @return [Capture] self
770
+ # @return [nil] nil
771
771
  #
772
772
  def start ()
773
773
  raise "Failed to start capture" unless @camera.start
774
- self
774
+ nil
775
775
  end
776
776
 
777
777
  # Stop capturing.
@@ -913,10 +913,7 @@ module RubySketch
913
913
  #
914
914
  SQUARE = :square
915
915
 
916
- def setup__ (painter)
917
- @painter__ = painter
918
- @painter__.miter_limit = 10
919
-
916
+ def init__ (image, painter)
920
917
  @drawing__ = false
921
918
  @hsbColor__ = false
922
919
  @colorMaxes__ = [1.0] * 4
@@ -929,6 +926,8 @@ module RubySketch
929
926
  @matrixStack__ = []
930
927
  @styleStack__ = []
931
928
 
929
+ updateCanvas__ image, painter
930
+
932
931
  colorMode RGB, 255
933
932
  angleMode RADIANS
934
933
  rectMode CORNER
@@ -940,13 +939,19 @@ module RubySketch
940
939
  stroke 0
941
940
  end
942
941
 
943
- def beginDraw ()
942
+ def updateCanvas__ (image, painter)
943
+ @image__, @painter__ = image, painter
944
+ end
945
+
946
+ # @private
947
+ def beginDraw__ ()
944
948
  @matrixStack__.clear
945
949
  @styleStack__.clear
946
950
  @drawing__ = true
947
951
  end
948
952
 
949
- def endDraw ()
953
+ # @private
954
+ def endDraw__ ()
950
955
  @drawing__ = false
951
956
  end
952
957
 
@@ -1367,8 +1372,8 @@ module RubySketch
1367
1372
  def arc (a, b, c, d, start, stop)
1368
1373
  assertDrawing__
1369
1374
  x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
1370
- start = toAngle__ start
1371
- stop = toAngle__ stop
1375
+ start = toAngle__ -start
1376
+ stop = toAngle__ -stop
1372
1377
  @painter__.ellipse x, y, w, h, from: start, to: stop
1373
1378
  nil
1374
1379
  end
@@ -1710,23 +1715,27 @@ module RubySketch
1710
1715
  # Initialize graphics object.
1711
1716
  #
1712
1717
  def initialize (width, height)
1713
- @image__ = Rays::Image.new width, height
1714
- setup__ @image__.painter
1718
+ image = Rays::Image.new width, height
1719
+ init__ image, image.painter
1715
1720
  end
1716
1721
 
1717
1722
  # Start drawing.
1718
1723
  #
1719
- def beginDraw ()
1724
+ def beginDraw (&block)
1720
1725
  @painter__.__send__ :begin_paint
1721
- super
1726
+ beginDraw__
1722
1727
  push
1728
+ if block
1729
+ block.call
1730
+ endDraw
1731
+ end
1723
1732
  end
1724
1733
 
1725
1734
  # End drawing.
1726
1735
  #
1727
1736
  def endDraw ()
1728
1737
  pop
1729
- super
1738
+ endDraw__
1730
1739
  @painter__.__send__ :end_paint
1731
1740
  end
1732
1741
 
@@ -1743,8 +1752,10 @@ module RubySketch
1743
1752
  Capture = Processing::Capture
1744
1753
  Graphics = Processing::Graphics
1745
1754
 
1755
+ # @private
1746
1756
  @@context__ = nil
1747
1757
 
1758
+ # @private
1748
1759
  def self.context__ ()
1749
1760
  @@context__
1750
1761
  end
@@ -1754,23 +1765,21 @@ module RubySketch
1754
1765
  @@context__ = self
1755
1766
 
1756
1767
  @window__ = window
1757
- @image__ = @window__.canvas
1758
- setup__ @window__.canvas_painter.paint {background 0.8}
1768
+ init__ @window__.canvas, @window__.canvas_painter.paint {background 0.8}
1759
1769
 
1760
1770
  @loop__ = true
1761
1771
  @redraw__ = false
1762
1772
  @frameCount__ = 0
1763
1773
  @mousePos__ =
1764
- @mousePrevPos__ = Rays::Point.new 0
1774
+ @mousePrevPos__ = [0, 0]
1765
1775
  @mousePressed__ = false
1766
1776
  @touches__ = []
1767
1777
 
1768
- @window__.before_draw = proc {beginDraw}
1769
- @window__.after_draw = proc {endDraw}
1778
+ @window__.before_draw = proc {beginDraw__}
1779
+ @window__.after_draw = proc {endDraw__}
1770
1780
 
1771
1781
  drawFrame = -> {
1772
- @image__ = @window__.canvas
1773
- @painter__ = @window__.canvas_painter
1782
+ updateCanvas__ @window__.canvas, @window__.canvas_painter
1774
1783
  begin
1775
1784
  push
1776
1785
  @drawBlock__.call if @drawBlock__
@@ -1789,9 +1798,11 @@ module RubySketch
1789
1798
  end
1790
1799
 
1791
1800
  updatePointerStates = -> event, pressed = nil {
1792
- @mousePos__ = event.pos
1801
+ @mousePos__ = @window__.to_canvas_coord event.pos.x, event.pos.y
1793
1802
  @mousePressed__ = pressed if pressed != nil
1794
- @touches__ = event.positions.map {|pos| Touch.new pos.x, pos.y}
1803
+ @touches__ = event.positions.map {|pos|
1804
+ Touch.new *@window__.to_canvas_coord(pos.x, pos.y)
1805
+ }
1795
1806
  }
1796
1807
 
1797
1808
  @window__.pointer_down = proc do |e|
@@ -1869,15 +1880,61 @@ module RubySketch
1869
1880
  nil
1870
1881
  end
1871
1882
 
1883
+ # Changes canvas size.
1884
+ #
1885
+ # @param width [Integer] new width
1886
+ # @param height [Integer] new height
1887
+ # @param pixelDensity [Numeric] new pixel density
1888
+ #
1889
+ # @return [nil] nil
1890
+ #
1891
+ def size (width, height, pixelDensity: self.pixelDensity)
1892
+ resizeCanvas__ :size, width, height, pixelDensity
1893
+ nil
1894
+ end
1895
+
1896
+ # Changes canvas size.
1897
+ #
1898
+ # @param width [Integer] new width
1899
+ # @param height [Integer] new height
1900
+ # @param pixelDensity [Numeric] new pixel density
1901
+ #
1902
+ # @return [nil] nil
1903
+ #
1904
+ def createCanvas (width, height, pixelDensity: self.pixelDensity)
1905
+ resizeCanvas__ :createCanvas, width, height, pixelDensity
1906
+ nil
1907
+ end
1908
+
1909
+ # Changes and returns canvas pixel density.
1910
+ #
1911
+ # @param density [Numeric] new pixel density
1912
+ #
1913
+ # @return [Numeric] current pixel density
1914
+ #
1915
+ def pixelDensity (density = nil)
1916
+ resizeCanvas__ :pixelDensity, width, height, density if density
1917
+ @painter__.pixel_density
1918
+ end
1919
+
1872
1920
  # @private
1873
- private def size__ (width, height)
1874
- raise 'size() must be called on startup or setup block' if @started__
1921
+ def resizeCanvas__ (name, width, height, pixelDensity)
1922
+ raise '#{name}() must be called on startup or setup block' if @started__
1875
1923
 
1876
1924
  @painter__.__send__ :end_paint
1877
- @window__.__send__ :reset_canvas, width, height
1925
+ @window__.__send__ :resize_canvas, width, height, pixelDensity
1926
+ updateCanvas__ @window__.canvas, @window__.canvas_painter
1878
1927
  @painter__.__send__ :begin_paint
1879
1928
 
1880
- @auto_resize__ = false
1929
+ @window__.auto_resize = false
1930
+ end
1931
+
1932
+ # Returns pixel density of display.
1933
+ #
1934
+ # @return [Numeric] pixel density
1935
+ #
1936
+ def displayDensity ()
1937
+ @window__.painter.pixel_density
1881
1938
  end
1882
1939
 
1883
1940
  def windowWidth ()
@@ -1904,20 +1961,12 @@ module RubySketch
1904
1961
  @window__.event.fps
1905
1962
  end
1906
1963
 
1907
- # Returns pixel density
1908
- #
1909
- # @return [Numeric] pixel density
1910
- #
1911
- def displayDensity ()
1912
- @painter__.pixel_density
1913
- end
1914
-
1915
1964
  # Returns mouse x position
1916
1965
  #
1917
1966
  # @return [Numeric] horizontal position of mouse
1918
1967
  #
1919
1968
  def mouseX ()
1920
- @mousePos__.x
1969
+ @mousePos__[0]
1921
1970
  end
1922
1971
 
1923
1972
  # Returns mouse y position
@@ -1925,7 +1974,7 @@ module RubySketch
1925
1974
  # @return [Numeric] vertical position of mouse
1926
1975
  #
1927
1976
  def mouseY ()
1928
- @mousePos__.y
1977
+ @mousePos__[1]
1929
1978
  end
1930
1979
 
1931
1980
  # Returns mouse x position in previous frame
@@ -1933,7 +1982,7 @@ module RubySketch
1933
1982
  # @return [Numeric] horizontal position of mouse
1934
1983
  #
1935
1984
  def pmouseX ()
1936
- @mousePrevPos__.x
1985
+ @mousePrevPos__[0]
1937
1986
  end
1938
1987
 
1939
1988
  # Returns mouse y position in previous frame
@@ -1941,7 +1990,7 @@ module RubySketch
1941
1990
  # @return [Numeric] vertical position of mouse
1942
1991
  #
1943
1992
  def pmouseY ()
1944
- @mousePrevPos__.y
1993
+ @mousePrevPos__[1]
1945
1994
  end
1946
1995
 
1947
1996
  # Returns array of touches
@@ -16,7 +16,8 @@ module RubySketch
16
16
  @auto_resize = true
17
17
  @error = nil
18
18
 
19
- reset_canvas 1, 1
19
+ painter.miter_limit = 10
20
+ resize_canvas 1, 1
20
21
 
21
22
  super *args, size: [width, height], &block
22
23
  end
@@ -43,7 +44,9 @@ module RubySketch
43
44
 
44
45
  def on_draw (e)
45
46
  draw_canvas {call_block @draw, e} if @draw
46
- e.painter.image @canvas
47
+
48
+ x, y, w, h = coord_converter
49
+ e.painter.image @canvas, x, y, @canvas.width * w, @canvas.height * h
47
50
  end
48
51
 
49
52
  def on_key (e)
@@ -64,27 +67,47 @@ module RubySketch
64
67
  end
65
68
 
66
69
  def on_resize (e)
67
- reset_canvas e.width, e.height if @auto_resize
70
+ resize_canvas e.width, e.height if @auto_resize
68
71
  draw_canvas {call_block @resize, e} if @resize
69
72
  end
70
73
 
74
+ def to_canvas_coord (x, y)
75
+ xx, yy, ww, hh = coord_converter
76
+ return (x - xx) / ww, (y - yy) / hh
77
+ end
78
+
71
79
  private
72
80
 
73
- def reset_canvas (width, height)
74
- return if width * height == 0
75
- return if width == @canvas&.width && height == @canvas&.height
81
+ def resize_canvas (width, height, pixel_density = nil)
82
+ return nil if width * height == 0
76
83
 
77
- old_canvas = @canvas
78
- old_painter = @canvas_painter
84
+ unless width == @canvas&.width &&
85
+ height == @canvas&.height &&
86
+ pixel_density == @canvas_painter&.pixel_density
79
87
 
80
- cs = old_canvas&.color_space || Rays::RGBA
81
- @canvas = Rays::Image.new width, height, cs, painter.pixel_density
82
- @canvas_painter = @canvas.painter
88
+ old_canvas = @canvas
89
+ old_painter = @canvas_painter
90
+ cs = old_canvas&.color_space || Rays::RGBA
91
+ pd = pixel_density ||
92
+ old_painter&.pixel_density ||
93
+ painter .pixel_density
83
94
 
84
- if old_canvas
85
- @canvas_painter.paint {image old_canvas}
86
- copy_painter_attributes old_painter, @canvas_painter
95
+ @canvas = Rays::Image.new width, height, cs, pd
96
+ @canvas_painter = @canvas.painter
97
+
98
+ if old_canvas
99
+ @canvas_painter.paint {image old_canvas}
100
+ copy_painter_attributes old_painter, @canvas_painter
101
+ end
102
+
103
+ resize_window width, height
87
104
  end
105
+
106
+ @canvas_painter
107
+ end
108
+
109
+ def resize_window (width, height)
110
+ size width, height
88
111
  end
89
112
 
90
113
  def copy_painter_attributes (from, to)
@@ -97,6 +120,21 @@ module RubySketch
97
120
  to.font = from.font
98
121
  end
99
122
 
123
+ def coord_converter ()
124
+ ww, wh = width.to_f, height.to_f
125
+ cw, ch = @canvas.width.to_f, @canvas.height.to_f
126
+ return [0, 0, 1, 1] if ww == 0 || wh == 0 || cw == 0 || ch == 0
127
+
128
+ wratio, cratio = ww / wh, cw / ch
129
+ if wratio >= cratio
130
+ scaled_w = wh * cratio
131
+ return (ww - scaled_w) / 2, 0, scaled_w / cw, wh / ch
132
+ else
133
+ scaled_h = ww / cratio
134
+ return 0, (wh - scaled_h) / 2, ww / cw, scaled_h / ch
135
+ end
136
+ end
137
+
100
138
  def draw_canvas (&block)
101
139
  begin_draw
102
140
  block.call
@@ -12,11 +12,6 @@ require 'rubysketch'
12
12
  include Xot::Test
13
13
 
14
14
 
15
- unless $RAYS_NOAUTOINIT
16
- #def Rays.fin! () end
17
- end
18
-
19
-
20
15
  def assert_equal_vector (v1, v2, delta = 0.000001)
21
16
  assert_in_delta v1.x, v2.x, delta
22
17
  assert_in_delta v1.y, v2.y, delta
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-26 00:00:00.000000000 Z
11
+ date: 2020-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reflexion
@@ -43,6 +43,7 @@ files:
43
43
  - examples/breakout.rb
44
44
  - examples/camera.rb
45
45
  - examples/clock.rb
46
+ - examples/delay_camera.rb
46
47
  - examples/glsl.rb
47
48
  - examples/hello.rb
48
49
  - examples/image.rb