rubysketch 0.5.3 → 0.5.5

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: 2aae68b50056538ec9f1de57091af05176af8b629331d40e16b640de83d4a610
4
- data.tar.gz: 8929fd46a62eeb5457f386a72b255d3a6267fc1380bb29aabe9b093a722ecb34
3
+ metadata.gz: 11852910038d162e39601eb01056ee3b4161c4ac0576ac93aef87e25eed557ee
4
+ data.tar.gz: 6d978cf96d2e8d32df00477e77f03c645840bb70985f74e5d254ff5f47f5cd4c
5
5
  SHA512:
6
- metadata.gz: fe6b88ffc3d9ee14f6b9206df4b554d498cd6a4b5b13a21baf8a6b0cfcebec4888322d12f6cee09829cc7a1038ad9ad2854945d5bb4e8706337bbfa310c113ab
7
- data.tar.gz: 56dac7438fb09ed3d8164e390e44dc785be289e6c4a4e5c3b9550fd5363c87f0a5a05f94806b6f68e691019e9297e2be6710435c5b0cafa35b2527ca1d7d1124
6
+ metadata.gz: '0593125c1c609a1f1c38eb45631f558fcb525db85792335524a37718d306c770d12f12012d3ddf5752080318070eb139d8ece676fb436f5a10abd88af02b2c8b'
7
+ data.tar.gz: 2d78202eb29f9541886efc54ec44142caf1cbd192ff58e51a26af5d3a0b8cb242c80be05171013f215b698a01cd70b9878fb10a2364abb4259402c48f6ea8475
@@ -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,29 @@
1
1
  # rubysketch ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.5] - 2023-05-08
5
+
6
+ - Add Sprite#draw()
7
+ - Add Sprite#angle accessor
8
+ - Add Sprite#pivot accessor
9
+ - Add Sprite#ox and Sprite#oy
10
+ - Add mousePressed, mouseReleased, mouseMoved, mouseDragged, mouseClicked, touchStarted, touchEnded, and touchMoved to Sprite class
11
+ - Add inspect() to classes
12
+ - Alias draw methods
13
+ - Sprite has density 1 by default
14
+ - Sprite is static by deault
15
+ - Add sprite.rb and physics.rb as an example
16
+ - Delete Sound class
17
+ - Remove wall collision by default
18
+
19
+
20
+ ## [v0.5.4] - 2023-04-30
21
+
22
+ - Add Sprite#image=() and Sprite#offset=()
23
+ - gravity() takes vector by pixel
24
+ - Add documents for Sprite class and test it
25
+
26
+
4
27
  ## [v0.5.3] - 2023-04-22
5
28
 
6
29
  - Depends on Beeps
data/RubySketch.podspec CHANGED
@@ -23,11 +23,15 @@ Pod::Spec.new do |s|
23
23
  incdirs = exts.map {|x| "#{root}/#{x}/include"}.concat %W[
24
24
  #{root}/src
25
25
  #{root}/beeps/vendor/stk/include
26
+ #{root}/beeps/vendor/AudioFile
27
+ #{root}/beeps/vendor/r8brain-free-src
28
+ #{root}/beeps/vendor/signalsmith-stretch
26
29
  #{root}/rays/vendor/glm
27
30
  #{root}/rays/vendor/clipper/cpp
28
31
  #{root}/rays/vendor/poly2tri/poly2tri
29
32
  #{root}/rays/vendor/splines-lib
30
- #{root}/reflex/vendor/Box2D/Box2D
33
+ #{root}/reflex/vendor/box2d/include
34
+ #{root}/reflex/vendor/box2d/src
31
35
  ${PODS_ROOT}/CRuby/CRuby/include
32
36
  ]
33
37
 
@@ -63,16 +67,25 @@ Pod::Spec.new do |s|
63
67
  end
64
68
 
65
69
  s.subspec "Beeps" do |spec|
66
- spec.source_files = "beeps/src/*.cpp"
67
- spec.frameworks = %w[OpenAL]
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]
68
74
 
69
75
  spec.subspec "STK" do |sub|
70
76
  sub.source_files = "beeps/vendor/stk/src/*.cpp"
71
- sub.exclude_files = %W[Tcp Udp Socket Thread Mutex InetWv Rt].map {|s|
77
+ sub.exclude_files = %w[Tcp Udp Socket Thread Mutex InetWv Rt].map {|s|
72
78
  "beeps/vendor/stk/src/#{s}*.cpp"
73
79
  }
74
80
  end
75
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
+
76
89
  spec.subspec "Ext" do |ext|
77
90
  ext.source_files = "beeps/ext/beeps/*.cpp"
78
91
  end
@@ -108,7 +121,7 @@ Pod::Spec.new do |s|
108
121
  spec.ios.frameworks = %w[CoreMotion]
109
122
 
110
123
  spec.subspec "Box2D" do |sub|
111
- sub.source_files = "reflex/vendor/Box2D/Box2D/Box2D/**/*.cpp"
124
+ sub.source_files = "reflex/vendor/box2d/src/**/*.cpp"
112
125
  end
113
126
 
114
127
  spec.subspec "Ext" do |ext|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.5
@@ -0,0 +1,24 @@
1
+ %w[xot rucy beeps rays reflex processing 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'
6
+ using RubySketch
7
+
8
+ noStroke
9
+ gravity 0, 1000
10
+
11
+ sprites = []
12
+ ground = createSprite 0, height - 10, width, 10
13
+
14
+ draw do
15
+ background 100
16
+ sprite *sprites, ground
17
+ end
18
+
19
+ mousePressed do
20
+ sp = createSprite mouseX, mouseY, 20, 20
21
+ sp.dynamic = true
22
+ sp.restitution = 0.5
23
+ sprites << sp
24
+ end
@@ -0,0 +1,47 @@
1
+ %w[xot rucy beeps rays reflex processing 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'
6
+ using RubySketch
7
+
8
+ sp = createSprite 100, 100, 50, 50
9
+ sp.angle += Math::PI * 0.2
10
+
11
+ red = 0
12
+
13
+ sp.update do
14
+ red = (red + 1) % 255
15
+ end
16
+
17
+ sp.draw do |&draw|
18
+ fill red, 200, 200
19
+ draw.call
20
+ fill 0
21
+ text :hello, 10, 20
22
+ end
23
+
24
+ sp.mousePressed do
25
+ p [:pressed, sp.mouseX, sp.mouseY, sp.mouseButton]
26
+ end
27
+
28
+ sp.mouseReleased do
29
+ p [:released, sp.mouseX, sp.mouseY, sp.mouseButton]
30
+ end
31
+
32
+ sp.mouseMoved do
33
+ p [:moved, sp.mouseX, sp.mouseY, sp.pmouseX, sp.pmouseY]
34
+ end
35
+
36
+ sp.mouseDragged do
37
+ p [:dragged, sp.mouseX, sp.mouseY, sp.pmouseX, sp.pmouseY]
38
+ end
39
+
40
+ sp.mouseClicked do
41
+ p [:clicked, sp.mouseX, sp.mouseY, sp.mouseButton]
42
+ end
43
+
44
+ draw do
45
+ background 0
46
+ sprite sp
47
+ end
@@ -1,4 +1,3 @@
1
- require 'forwardable'
2
1
  require 'beeps'
3
2
  require 'processing/all'
4
3
 
@@ -7,6 +6,12 @@ require 'rubysketch/window'
7
6
  require 'rubysketch/helper'
8
7
 
9
8
  require 'rubysketch/sprite'
10
- require 'rubysketch/sound'
11
- require 'rubysketch/graphics_context'
12
9
  require 'rubysketch/context'
10
+
11
+
12
+ module RubySketch
13
+
14
+ Vector = Processing::Vector
15
+ Image = Processing::Image
16
+
17
+ end# RubySketch
@@ -3,49 +3,152 @@ module RubySketch
3
3
 
4
4
  class Context < Processing::Context
5
5
 
6
- include GraphicsContext
6
+ Sprite = RubySketch::Sprite
7
7
 
8
+ # @private
8
9
  def initialize(window)
9
10
  super
10
- @sprites__ = window.add SpritesView.new
11
+ @layer__ = window.add_overlay SpriteLayer.new
11
12
  end
12
13
 
14
+ # Creates a new sprite and add it to physics engine.
15
+ #
16
+ # @overload createSprite(image: img)
17
+ # pos: [0, 0], size: [image.width, image.height]
18
+ # @param [Image] img sprite image
19
+ #
20
+ # @overload createSprite(x, y, image: img)
21
+ # pos: [x, y], size: [image.width, image.height]
22
+ # @param [Numeric] x x of sprite position
23
+ # @param [Numeric] y y of sprite position
24
+ # @param [Image] img sprite image
25
+ #
26
+ # @overload createSprite(x, y, w, h)
27
+ # pos(x, y), size: [w, h]
28
+ # @param [Numeric] x x of sprite position
29
+ # @param [Numeric] y y of sprite position
30
+ # @param [Numeric] w width of sprite
31
+ # @param [Numeric] h height of sprite
32
+ #
33
+ # @overload createSprite(x, y, w, h, image: img, offset: off)
34
+ # pos: [x, y], size: [w, h], offset: [offset.x, offset.x]
35
+ # @param [Numeric] x x of sprite position
36
+ # @param [Numeric] y y of sprite position
37
+ # @param [Numeric] w width of sprite
38
+ # @param [Numeric] h height of sprite
39
+ # @param [Image] img sprite image
40
+ # @param [Vector] off offset of sprite image
41
+ #
13
42
  def createSprite(*args, **kwargs)
14
- addSprite Sprite.new(*args, **kwargs)
43
+ addSprite Sprite.new(*args, **kwargs, context: self)
15
44
  end
16
45
 
46
+ # Adds the sprite to the physics engine.
47
+ #
48
+ # @param [Sprite] sprite sprite object
49
+ #
50
+ # @return [Sprite] added sprite
51
+ #
17
52
  def addSprite(sprite)
18
- @sprites__.add sprite.getInternal__ if sprite
53
+ @layer__.add sprite.getInternal__ if sprite
19
54
  sprite
20
55
  end
21
56
 
57
+ # Removes the sprite from the physics engine.
58
+ #
59
+ # @param [Sprite] sprite sprite object
60
+ #
61
+ # @return [Sprite] removed sprite
62
+ #
22
63
  def removeSprite(sprite)
23
- @sprites__.remove sprite.getInternal__ if sprite
64
+ @layer__.remove sprite.getInternal__ if sprite
24
65
  sprite
25
66
  end
26
67
 
27
- def loadSound(path)
28
- Sound.load path
68
+ # Draws one or more sprites.
69
+ #
70
+ # @param [Array<Sprite>] sprites
71
+ #
72
+ # @return [nil] nil
73
+ #
74
+ def sprite(*sprites)
75
+ sprites.flatten! if sprites.first&.is_a? Array
76
+ sprites.each do |sp|
77
+ view, draw = sp.getInternal__, sp.instance_variable_get(:@drawBlock__)
78
+ f, degrees, pivot = view.frame, view.angle, view.pivot
79
+ if draw
80
+ push do
81
+ translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
82
+ rotate fromDegrees__ degrees
83
+ translate -pivot.x * f.w, -pivot.y * f.h
84
+ draw.call {drawSprite__ sp, 0, 0, f.w, f.h}
85
+ end
86
+ elsif degrees == 0
87
+ drawSprite__ sp, f.x, f.y, f.w, f.h
88
+ else
89
+ pushMatrix do
90
+ translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
91
+ rotate fromDegrees__ degrees
92
+ translate -pivot.x * f.w, -pivot.y * f.h
93
+ drawSprite__ sp, 0, 0, f.w, f.h
94
+ end
95
+ end
96
+ end
97
+ nil
98
+ end
99
+
100
+ alias drawSprite sprite
101
+
102
+ # @private
103
+ def drawSprite__(sp, x, y, w, h)
104
+ img, off = sp.image, sp.offset
105
+ if img && off
106
+ copy img, off.x, off.y, w, h, x, y, w, h
107
+ elsif img
108
+ image img, x, y
109
+ else
110
+ rect x, y, w, h
111
+ end
29
112
  end
30
113
 
114
+ # Sets gravity for the physics engine.
115
+ #
116
+ # @overload gravity(vec)
117
+ # @param [Vector] vec gracity vector
118
+ #
119
+ # @overload gravity(ary)
120
+ # @param [Array<Numeric>] ary gravityX, gravityY
121
+ #
122
+ # @overload gravity(x, y)
123
+ # @param [Numeric] x x of gravity vector
124
+ # @param [Numeric] y y of gracity vector
125
+ #
31
126
  def gravity(*args)
32
127
  x, y =
33
- case args
34
- when Processing::Vector then args.array
128
+ case arg = args.first
129
+ when Vector then arg.array
130
+ when Array then arg
35
131
  else args
36
132
  end
37
- @sprites__.then do |v|
38
- v.gravity x * v.meter, y * v.meter
39
- end
133
+ @layer__.gravity x, y
40
134
  end
41
135
 
42
- class SpritesView < Reflex::View
43
- def on_draw(e)
44
- e.block
45
- end
136
+ end# Context
137
+
138
+
139
+ # @private
140
+ class SpriteLayer < Reflex::View
141
+
142
+ def initialize(*a, **k, &b)
143
+ super
144
+ remove wall
46
145
  end
47
146
 
48
- end# Context
147
+ def on_draw(e)
148
+ e.block
149
+ end
150
+
151
+ end# SpriteLayer
49
152
 
50
153
 
51
154
  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
@@ -1,3 +1,4 @@
1
+ # @private
1
2
  class Rays::Point
2
3
  def toVector()
3
4
  Processing::Vector.new x, y, z