rubysketch 0.5.2 → 0.5.4

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: ccbb3ec25a88b53bba2570b98bce4e809f6e4cbe68ffe9d3ecd0632934d75e2c
4
- data.tar.gz: 47bc1c14d77513954b4bae6a5611b802c99836ad2474d2232d35ef92def908a1
3
+ metadata.gz: 82a93ef9dac4ae855bfa85f9a076ed05c807875db70be9c5e72419137499434e
4
+ data.tar.gz: 2f432e94c80ad231f50ca11df96ecd6a13c389551f75c426e161701e25d85a23
5
5
  SHA512:
6
- metadata.gz: 2ad5c3d346dfd79446ad795e00c7b148baeb1bdee3600d6b628d1ba6f5c366273aa71986016500649ed36944022e418d1a5f012ccd4d808b6546e6fbed1eb9e2
7
- data.tar.gz: 3c657e0ef7fdefc37d370246d881b0d976805d74c1ee22b99b7470fb502aacf5de1d7bba0991f7b1534e3d8a43114da7b05cf6336bebb43bd9d90d57b8328d69
6
+ metadata.gz: cdf7238a4d07fe88b5d1fe3d68ea6f62d9536b142afda5dad1f4c15538bae2047d4e188bbc88e0777d641650ad9c5f5864720345ad5ec950e2ff18e83f552db9
7
+ data.tar.gz: 310a71a0b3388876bd0c0910a09bb9aa12e5686e5885ec8e4b2a32cb4af629ed18a010731a77b4a8ea1a9a4be41de504098767d0d133e3344554d5078508ad29
@@ -24,7 +24,7 @@ jobs:
24
24
  run: gem install yard
25
25
 
26
26
  - name: test
27
- run: rake test
27
+ run: rake quiet test
28
28
 
29
29
  - name: create gem
30
30
  id: gem
@@ -20,8 +20,9 @@ def setup_dependencies(build: true, only: nil)
20
20
 
21
21
  exts.each do |ext|
22
22
  gem = RENAMES[ext.to_sym].then {|s| s || ext}
23
- clone = "git clone --depth 1 https://github.com/xord/#{ext}.git ../#{ext}"
24
23
  ver = gemspec[/add_runtime_dependency.*['"]#{gem}['"].*['"]\s*~>\s*([\d\.]+)\s*['"]/, 1]
24
+ opts = '-c advice.detachedHead=false --depth 1'
25
+ clone = "git clone #{opts} https://github.com/xord/#{ext}.git ../#{ext}"
25
26
 
26
27
  # 'rake subtree:push' pushes all subrepos, so cloning by new tag
27
28
  # often fails before tagging each new tag
data/ChangeLog.md CHANGED
@@ -1,6 +1,23 @@
1
1
  # rubysketch ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.4] - 2023-04-30
5
+
6
+ - Add Sprite#image=() and Sprite#offset=()
7
+ - gravity() takes vector by pixel
8
+ - Add documents for Sprite class and test it
9
+
10
+
11
+ ## [v0.5.3] - 2023-04-22
12
+
13
+ - Depends on Beeps
14
+ - Update RubySketch.podspec to include beeps, rays, reflex, and processing libs
15
+ - Add RubySketch.h and RubySketch.mm
16
+ - Add Sound class and loadSound()
17
+ - Add vx, vy accessors and will_contact? callback to Sprite class
18
+ - Add RubySketch::Window andd calls Beeps.process_streams!
19
+
20
+
4
21
  ## [v0.5.2] - 2023-03-02
5
22
 
6
23
  - depend to processing-0.5.2 gem
data/RubySketch.podspec CHANGED
@@ -14,16 +14,118 @@ Pod::Spec.new do |s|
14
14
  s.osx.deployment_target = "10.10"
15
15
  s.ios.deployment_target = "10.0"
16
16
 
17
- incdirs = %W[
18
- #{s.name}/src
19
- CRuby/CRuby/include
20
- Reflexion/reflex/include
21
- RubyProcessing/src
22
- ].map {|s| "${PODS_ROOT}/#{s}"}
23
-
24
- s.preserve_paths = "src"
25
- s.source_files = "src/*.mm"
26
- s.xcconfig = {"HEADER_SEARCH_PATHS" => incdirs.join(' ')}
27
-
28
- s.resource_bundles = {'RubySketch' => %w[lib VERSION]}
17
+ root = "${PODS_ROOT}/#{s.name}"
18
+ exts = File.read(File.expand_path 'Rakefile', __dir__)
19
+ .lines(chomp: true)
20
+ .map {|line| line[%r|require\s*['"](\w+)/extension['"]|, 1]}
21
+ .compact - [s.name.downcase]
22
+
23
+ incdirs = exts.map {|x| "#{root}/#{x}/include"}.concat %W[
24
+ #{root}/src
25
+ #{root}/beeps/vendor/stk/include
26
+ #{root}/beeps/vendor/AudioFile
27
+ #{root}/beeps/vendor/r8brain-free-src
28
+ #{root}/beeps/vendor/signalsmith-stretch
29
+ #{root}/rays/vendor/glm
30
+ #{root}/rays/vendor/clipper/cpp
31
+ #{root}/rays/vendor/poly2tri/poly2tri
32
+ #{root}/rays/vendor/splines-lib
33
+ #{root}/reflex/vendor/box2d/include
34
+ #{root}/reflex/vendor/box2d/src
35
+ ${PODS_ROOT}/CRuby/CRuby/include
36
+ ]
37
+
38
+ s.prepare_command = 'rake -f pod.rake setup'
39
+ s.preserve_paths = exts + %w[src]
40
+ s.requires_arc = false
41
+ s.osx.compiler_flags = "-DOSX"
42
+ s.ios.compiler_flags = "-DIOS"
43
+ s.library = %w[c++]
44
+ s.xcconfig = {
45
+ "CLANG_CXX_LANGUAGE_STANDARD" => 'c++20',
46
+ "HEADER_SEARCH_PATHS" => incdirs.join(' ')
47
+ }
48
+
49
+ #s.dependency = 'CRuby', git: 'https://github.com/xord/cruby'
50
+
51
+ s.source_files = "src/*.mm"
52
+ s.resource_bundles =
53
+ exts.each_with_object({'RubySketch' => %w[lib VERSION]}) do |ext, hash|
54
+ hash[ext.capitalize] = %W[#{ext}/lib VERSION]
55
+ end
56
+
57
+ s.subspec "Xot" do |spec|
58
+ spec.source_files = "xot/src/*.cpp"
59
+ end
60
+
61
+ s.subspec "Rucy" do |spec|
62
+ spec.source_files = "rucy/src/*.cpp"
63
+
64
+ spec.subspec "Ext" do |ext|
65
+ ext.source_files = "rucy/ext/rucy/*.cpp"
66
+ end
67
+ end
68
+
69
+ s.subspec "Beeps" do |spec|
70
+ spec .source_files = "beeps/src/*.cpp"
71
+ spec.osx.source_files = "beeps/src/osx/*.{cpp,mm}"
72
+ spec.ios.source_files = "beeps/src/osx/*.{cpp,mm}"
73
+ spec.frameworks = %w[OpenAL AVFoundation]
74
+
75
+ spec.subspec "STK" do |sub|
76
+ sub.source_files = "beeps/vendor/stk/src/*.cpp"
77
+ sub.exclude_files = %w[Tcp Udp Socket Thread Mutex InetWv Rt].map {|s|
78
+ "beeps/vendor/stk/src/#{s}*.cpp"
79
+ }
80
+ end
81
+
82
+ spec.subspec "R8BrainFreeSrc" do |sub|
83
+ sub.source_files = "beeps/vendor/r8brain-free-src/*.cpp"
84
+ sub.exclude_files = %w[example pffft_double/].map {|s|
85
+ "beeps/vendor/r8brain-free-src/#{s}*.cpp"
86
+ }
87
+ end
88
+
89
+ spec.subspec "Ext" do |ext|
90
+ ext.source_files = "beeps/ext/beeps/*.cpp"
91
+ end
92
+ end
93
+
94
+ s.subspec "Rays" do |spec|
95
+ spec .source_files = "rays/src/*.cpp"
96
+ spec.osx.source_files = "rays/src/osx/*.{cpp,mm}"
97
+ spec.ios.source_files = "rays/src/ios/*.{cpp,mm}"
98
+ spec.ios.frameworks = %w[GLKit MobileCoreServices AVFoundation]# ImageIO
99
+
100
+ spec.subspec "Clipper" do |sub|
101
+ sub.source_files = "rays/vendor/clipper/cpp/*.cpp"
102
+ end
103
+
104
+ spec.subspec "Poly2Tri" do |sub|
105
+ sub.source_files = "rays/vendor/poly2tri/poly2tri/**/*.cc"
106
+ end
107
+
108
+ spec.subspec "SplineLib" do |sub|
109
+ sub.source_files = "rays/vendor/splines-lib/Splines.cpp"
110
+ end
111
+
112
+ spec.subspec "Ext" do |ext|
113
+ ext.source_files = "rays/ext/rays/*.cpp"
114
+ end
115
+ end
116
+
117
+ s.subspec "Reflex" do |spec|
118
+ spec .source_files = "reflex/src/*.cpp"
119
+ spec.osx.source_files = "reflex/src/osx/*.{cpp,mm}"
120
+ spec.ios.source_files = "reflex/src/ios/*.{cpp,mm}"
121
+ spec.ios.frameworks = %w[CoreMotion]
122
+
123
+ spec.subspec "Box2D" do |sub|
124
+ sub.source_files = "reflex/vendor/box2d/src/**/*.cpp"
125
+ end
126
+
127
+ spec.subspec "Ext" do |ext|
128
+ ext.source_files = "reflex/ext/reflex/*.cpp"
129
+ end
130
+ end
29
131
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.4
data/examples/hello.rb CHANGED
@@ -1,4 +1,4 @@
1
- %w[xot rays reflex processing rubysketch]
1
+ %w[xot rucy beeps rays reflex processing rubysketch]
2
2
  .map {|s| File.expand_path "../../#{s}/lib", __dir__}
3
3
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
4
4
 
@@ -1,9 +1,19 @@
1
- require 'forwardable'
1
+ require 'beeps'
2
2
  require 'processing/all'
3
3
 
4
4
  require 'rubysketch/extension'
5
+ require 'rubysketch/window'
5
6
  require 'rubysketch/helper'
6
7
 
7
8
  require 'rubysketch/sprite'
9
+ require 'rubysketch/sound'
8
10
  require 'rubysketch/graphics_context'
9
11
  require 'rubysketch/context'
12
+
13
+
14
+ module RubySketch
15
+
16
+ Vector = Processing::Vector
17
+ Image = Processing::Image
18
+
19
+ end# RubySketch
@@ -5,43 +5,103 @@ module RubySketch
5
5
 
6
6
  include GraphicsContext
7
7
 
8
+ Sound = RubySketch::Sound
9
+ Sprite = RubySketch::Sprite
10
+
11
+ # @private
8
12
  def initialize(window)
9
13
  super
10
- @sprites__ = window.add SpritesView.new
14
+ @layer__ = window.add_overlay SpriteLayer.new
11
15
  end
12
16
 
17
+ # Creates a new sprite and add it to physics engine.
18
+ #
19
+ # @overload createSprite(image: img)
20
+ # pos: [0, 0], size: [image.width, image.height]
21
+ # @param [Image] img sprite image
22
+ #
23
+ # @overload createSprite(x, y, image: img)
24
+ # pos: [x, y], size: [image.width, image.height]
25
+ # @param [Numeric] x x of sprite position
26
+ # @param [Numeric] y y of sprite position
27
+ # @param [Image] img sprite image
28
+ #
29
+ # @overload createSprite(x, y, w, h)
30
+ # pos(x, y), size: [w, h]
31
+ # @param [Numeric] x x of sprite position
32
+ # @param [Numeric] y y of sprite position
33
+ # @param [Numeric] w width of sprite
34
+ # @param [Numeric] h height of sprite
35
+ #
36
+ # @overload createSprite(x, y, w, h, image: img, offset: off)
37
+ # pos: [x, y], size: [w, h], offset: [offset.x, offset.x]
38
+ # @param [Numeric] x x of sprite position
39
+ # @param [Numeric] y y of sprite position
40
+ # @param [Numeric] w width of sprite
41
+ # @param [Numeric] h height of sprite
42
+ # @param [Image] img sprite image
43
+ # @param [Vector] off offset of sprite image
44
+ #
13
45
  def createSprite(*args, **kwargs)
14
46
  addSprite Sprite.new(*args, **kwargs)
15
47
  end
16
48
 
49
+ # Adds the sprite to the physics engine.
50
+ #
51
+ # @param [Sprite] sprite sprite object
52
+ #
17
53
  def addSprite(sprite)
18
- @sprites__.add sprite.getInternal__ if sprite
54
+ @layer__.add sprite.getInternal__ if sprite
19
55
  sprite
20
56
  end
21
57
 
58
+ # Removes the sprite from the physics engine.
59
+ #
60
+ # @param [Sprite] sprite sprite object
61
+ #
22
62
  def removeSprite(sprite)
23
- @sprites__.remove sprite.getInternal__ if sprite
63
+ @layer__.remove sprite.getInternal__ if sprite
24
64
  sprite
25
65
  end
26
66
 
67
+ # @private
68
+ def loadSound(path)
69
+ Sound.load path
70
+ end
71
+
72
+ # Sets gravity for the physics engine.
73
+ #
74
+ # @overload gravity(vec)
75
+ # @param [Vector] vec gracity vector
76
+ #
77
+ # @overload gravity(ary)
78
+ # @param [Array<Numeric>] ary gravityX, gravityY
79
+ #
80
+ # @overload gravity(x, y)
81
+ # @param [Numeric] x x of gravity vector
82
+ # @param [Numeric] y y of gracity vector
83
+ #
27
84
  def gravity(*args)
28
85
  x, y =
29
- case args
30
- when Processing::Vector then args.array
86
+ case arg = args.first
87
+ when Vector then arg.array
88
+ when Array then arg
31
89
  else args
32
90
  end
33
- @sprites__.then do |v|
34
- v.gravity x * v.meter, y * v.meter
35
- end
91
+ @layer__.gravity x, y
36
92
  end
37
93
 
38
- class SpritesView < Reflex::View
39
- def on_draw(e)
40
- e.block
41
- end
94
+ end# Context
95
+
96
+
97
+ # @private
98
+ class SpriteLayer < Reflex::View
99
+
100
+ def on_draw(e)
101
+ e.block
42
102
  end
43
103
 
44
- end# Context
104
+ end# SpriteLayer
45
105
 
46
106
 
47
107
  end# RubySketch
@@ -1,6 +1,7 @@
1
1
  module RubySketch
2
2
 
3
3
 
4
+ # @private
4
5
  module Extension
5
6
 
6
7
  module_function
@@ -3,34 +3,27 @@ module RubySketch
3
3
 
4
4
  module GraphicsContext
5
5
 
6
+ # Draws one or more sprites.
7
+ #
8
+ # @param [Array<Sprite>] sprites
9
+ #
6
10
  def sprite(*sprites)
7
11
  sprites.flatten! if sprites.first&.is_a? Array
8
12
  sprites.each do |sp|
9
13
  v = sp.getInternal__
10
- f, angle, img, offset = v.frame, v.angle, sp.image, sp.offset
14
+ f, angle = v.frame, v.angle
11
15
  if angle == 0
12
- drawSprite__ f.x, f.y, f.w, f.h, img, offset
16
+ sp.on_draw__ f.x, f.y, f.w, f.h
13
17
  else
14
18
  pushMatrix do
15
19
  translate f.x, f.y
16
20
  rotate radians(angle)
17
- drawSprite__ 0, 0, f.w, f.h, img, offset
21
+ sp.on_draw__ 0, 0, f.w, f.h
18
22
  end
19
23
  end
20
24
  end
21
25
  end
22
26
 
23
- def drawSprite__(x, y, w, h, img, offset)
24
- if img && offset
25
- ox, oy = offset
26
- copy img, ox, oy, w, h, x, y, w, h
27
- elsif img
28
- image img, x, y
29
- else
30
- rect x, y, w, h
31
- end
32
- end
33
-
34
27
  end# GraphicsContext
35
28
 
36
29
 
@@ -1,3 +1,4 @@
1
+ # @private
1
2
  class Rays::Point
2
3
  def toVector()
3
4
  Processing::Vector.new x, y, z
@@ -0,0 +1,86 @@
1
+ module RubySketch
2
+
3
+
4
+ # @private
5
+ class Sound
6
+
7
+ # @private
8
+ def initialize(sound)
9
+ @sound = sound
10
+ end
11
+
12
+ # Play sound.
13
+ #
14
+ def play()
15
+ old = @player
16
+ @player = @sound.play
17
+ old&.stop
18
+ true
19
+ end
20
+
21
+ # Pause sound.
22
+ #
23
+ def pause()
24
+ return false unless @player
25
+ @player.pause
26
+ true
27
+ end
28
+
29
+ # Stop sound.
30
+ #
31
+ def stop()
32
+ return false unless @player
33
+ @player.stop
34
+ @player = nil
35
+ true
36
+ end
37
+
38
+ # Returns whether the sound is playing or not.
39
+ #
40
+ # @return [Boolean] playing or not
41
+ #
42
+ def playing?()
43
+ @player ? @player.playing? : false
44
+ end
45
+
46
+ # Returns whether the sound is paused or not.
47
+ #
48
+ # @return [Boolean] paused or not
49
+ #
50
+ def paused?()
51
+ @player ? @player.paused? : false
52
+ end
53
+
54
+ # Returns whether the sound is stopped or not.
55
+ #
56
+ # @return [Boolean] stopped or not
57
+ #
58
+ def stopped?()
59
+ @player ? @player.stopped? : true
60
+ end
61
+
62
+ # Save the sound data to a file.
63
+ #
64
+ # @param [String] path file path
65
+ #
66
+ # @return [Sound] self
67
+ #
68
+ def save(path)
69
+ @sound.save path
70
+ end
71
+
72
+ # Load a sound file.
73
+ #
74
+ # @param [String] path file path
75
+ #
76
+ # @return [Sound] sound object
77
+ #
78
+ def self.load(path)
79
+ f = Beeps::FileIn.new path
80
+ self.new Beeps::Sound.new(f, f.seconds, nchannels: f.nchannels)
81
+ end
82
+
83
+ end# Sound
84
+
85
+
86
+ end# RubySketch