rubysketch 0.3.9 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a3690207d8b2a8c6bfe3b556e9e1267e3508bcd757952fc738ce2594844a6a5
4
- data.tar.gz: '0112280fc01e89633adff2ebbccc012ceab1bdcd9271dc9d6f14d8c9969ca586'
3
+ metadata.gz: 11106527579020a3b5bd37a616605f659099ca5523cb314399850652a647c96f
4
+ data.tar.gz: a18591f7c86b38291a11eac844ff6da0a43a3916c79df3f7bf4eff330a5f1ebf
5
5
  SHA512:
6
- metadata.gz: bad81197d43586840b8f6828dd3f267a131017796d988bb958969b4fcc3cae7bcf41eca4123ce9f38039dab69195859cd3bb96a8afe1eda650a3abacd92a6944
7
- data.tar.gz: de7e3c7bb04cdf8ac3f90893277e20b671073ebe03197c9a31987cdb5324e7e0ce07659064bce787115713c95471bdacec4323a29ce0a2bf22ad8d2b7cff6937
6
+ metadata.gz: 91f78963b6a956b4a68194963fb4de22a007ba075aad59d9a69fe752b596615bbf21189e5e404cb4d8346a3f287d6b7b061d027dc5e05bf7598904f99e21342d
7
+ data.tar.gz: 4a054bd08ebdaa62e3fab7dd853cad2aa95fa7f9d6ed414992d0d7df8eb6de7d17dd5fc27925d544f3aec9866ad3ccef0c9d5c5e09bdc7ed8703f31801d9dbe3
@@ -1,6 +1,38 @@
1
1
  # RubySketch ChangeLog
2
2
 
3
3
 
4
+ ## [0.3.14] - 2020-12-12
5
+
6
+ - fix loadImage() fails when Encoding.default_internal is not nil
7
+
8
+
9
+ ## [0.3.13] - 2020-12-12
10
+
11
+ - size(), createCanvas(): default pixelDensity is same as current value
12
+
13
+
14
+ ## [0.3.12] - 2020-12-10
15
+
16
+ - size() and createCanvas() take 'pixelDensity' parameter and default value is 1
17
+
18
+
19
+ ## [0.3.11] - 2020-12-9
20
+
21
+ - add size(), createCanvas() and pixelDensity()
22
+
23
+
24
+ ## [0.3.10] - 2020-12-1
25
+
26
+ - invert angle parameter value for arc() to fix compatibility to processing API
27
+
28
+
29
+ ## [0.3.9] - 2020-11-30
30
+
31
+ - Graphics#beginDraw() can take block to call endDraw automatically
32
+ - Capture#start() always returns nil
33
+ - add delay_camera.rb
34
+
35
+
4
36
  ## [0.3.8] - 2020-11-27
5
37
 
6
38
  - 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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.9
1
+ 0.3.14
@@ -5,7 +5,7 @@
5
5
  require 'rubysketch-processing'
6
6
 
7
7
 
8
- icon = loadImage 'https://xord.org/rubysketch/rubysketch.png'
8
+ icon = loadImage 'https://xord.org/rubysketch/images/rubysketch128.png'
9
9
 
10
10
  draw do
11
11
  background 0, 10
@@ -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,6 +939,10 @@ module RubySketch
940
939
  stroke 0
941
940
  end
942
941
 
942
+ def updateCanvas__ (image, painter)
943
+ @image__, @painter__ = image, painter
944
+ end
945
+
943
946
  # @private
944
947
  def beginDraw__ ()
945
948
  @matrixStack__.clear
@@ -1369,8 +1372,8 @@ module RubySketch
1369
1372
  def arc (a, b, c, d, start, stop)
1370
1373
  assertDrawing__
1371
1374
  x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
1372
- start = toAngle__ start
1373
- stop = toAngle__ stop
1375
+ start = toAngle__ -start
1376
+ stop = toAngle__ -stop
1374
1377
  @painter__.ellipse x, y, w, h, from: start, to: stop
1375
1378
  nil
1376
1379
  end
@@ -1712,8 +1715,8 @@ module RubySketch
1712
1715
  # Initialize graphics object.
1713
1716
  #
1714
1717
  def initialize (width, height)
1715
- @image__ = Rays::Image.new width, height
1716
- setup__ @image__.painter
1718
+ image = Rays::Image.new width, height
1719
+ init__ image, image.painter
1717
1720
  end
1718
1721
 
1719
1722
  # Start drawing.
@@ -1749,8 +1752,10 @@ module RubySketch
1749
1752
  Capture = Processing::Capture
1750
1753
  Graphics = Processing::Graphics
1751
1754
 
1755
+ # @private
1752
1756
  @@context__ = nil
1753
1757
 
1758
+ # @private
1754
1759
  def self.context__ ()
1755
1760
  @@context__
1756
1761
  end
@@ -1760,14 +1765,13 @@ module RubySketch
1760
1765
  @@context__ = self
1761
1766
 
1762
1767
  @window__ = window
1763
- @image__ = @window__.canvas
1764
- setup__ @window__.canvas_painter.paint {background 0.8}
1768
+ init__ @window__.canvas, @window__.canvas_painter.paint {background 0.8}
1765
1769
 
1766
1770
  @loop__ = true
1767
1771
  @redraw__ = false
1768
1772
  @frameCount__ = 0
1769
1773
  @mousePos__ =
1770
- @mousePrevPos__ = Rays::Point.new 0
1774
+ @mousePrevPos__ = [0, 0]
1771
1775
  @mousePressed__ = false
1772
1776
  @touches__ = []
1773
1777
 
@@ -1775,8 +1779,7 @@ module RubySketch
1775
1779
  @window__.after_draw = proc {endDraw__}
1776
1780
 
1777
1781
  drawFrame = -> {
1778
- @image__ = @window__.canvas
1779
- @painter__ = @window__.canvas_painter
1782
+ updateCanvas__ @window__.canvas, @window__.canvas_painter
1780
1783
  begin
1781
1784
  push
1782
1785
  @drawBlock__.call if @drawBlock__
@@ -1795,9 +1798,11 @@ module RubySketch
1795
1798
  end
1796
1799
 
1797
1800
  updatePointerStates = -> event, pressed = nil {
1798
- @mousePos__ = event.pos
1801
+ @mousePos__ = @window__.to_canvas_coord event.pos.x, event.pos.y
1799
1802
  @mousePressed__ = pressed if pressed != nil
1800
- @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
+ }
1801
1806
  }
1802
1807
 
1803
1808
  @window__.pointer_down = proc do |e|
@@ -1875,15 +1880,61 @@ module RubySketch
1875
1880
  nil
1876
1881
  end
1877
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
+
1878
1920
  # @private
1879
- private def size__ (width, height)
1880
- 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__
1881
1923
 
1882
1924
  @painter__.__send__ :end_paint
1883
- @window__.__send__ :reset_canvas, width, height
1925
+ @window__.__send__ :resize_canvas, width, height, pixelDensity
1926
+ updateCanvas__ @window__.canvas, @window__.canvas_painter
1884
1927
  @painter__.__send__ :begin_paint
1885
1928
 
1886
- @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
1887
1938
  end
1888
1939
 
1889
1940
  def windowWidth ()
@@ -1910,20 +1961,12 @@ module RubySketch
1910
1961
  @window__.event.fps
1911
1962
  end
1912
1963
 
1913
- # Returns pixel density
1914
- #
1915
- # @return [Numeric] pixel density
1916
- #
1917
- def displayDensity ()
1918
- @painter__.pixel_density
1919
- end
1920
-
1921
1964
  # Returns mouse x position
1922
1965
  #
1923
1966
  # @return [Numeric] horizontal position of mouse
1924
1967
  #
1925
1968
  def mouseX ()
1926
- @mousePos__.x
1969
+ @mousePos__[0]
1927
1970
  end
1928
1971
 
1929
1972
  # Returns mouse y position
@@ -1931,7 +1974,7 @@ module RubySketch
1931
1974
  # @return [Numeric] vertical position of mouse
1932
1975
  #
1933
1976
  def mouseY ()
1934
- @mousePos__.y
1977
+ @mousePos__[1]
1935
1978
  end
1936
1979
 
1937
1980
  # Returns mouse x position in previous frame
@@ -1939,7 +1982,7 @@ module RubySketch
1939
1982
  # @return [Numeric] horizontal position of mouse
1940
1983
  #
1941
1984
  def pmouseX ()
1942
- @mousePrevPos__.x
1985
+ @mousePrevPos__[0]
1943
1986
  end
1944
1987
 
1945
1988
  # Returns mouse y position in previous frame
@@ -1947,7 +1990,7 @@ module RubySketch
1947
1990
  # @return [Numeric] vertical position of mouse
1948
1991
  #
1949
1992
  def pmouseY ()
1950
- @mousePrevPos__.y
1993
+ @mousePrevPos__[1]
1951
1994
  end
1952
1995
 
1953
1996
  # Returns array of touches
@@ -2393,8 +2436,10 @@ module RubySketch
2393
2436
 
2394
2437
  unless path.file?
2395
2438
  URI.open uri do |input|
2439
+ input.set_encoding nil# disable default_internal
2396
2440
  tmpdir.mkdir unless tmpdir.directory?
2397
2441
  path.open('w') do |output|
2442
+ output.set_encoding Encoding::ASCII_8BIT
2398
2443
  while buf = input.read(2 ** 16)
2399
2444
  output.write buf
2400
2445
  end
@@ -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
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.9
4
+ version: 0.3.14
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-29 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