rubysketch 0.5.30 → 0.5.32
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 +4 -4
- data/ChangeLog.md +11 -0
- data/VERSION +1 -1
- data/examples/physics.rb +2 -1
- data/examples/toon.rb +181 -0
- data/lib/rubysketch/all.rb +1 -0
- data/lib/rubysketch/context.rb +38 -31
- data/lib/rubysketch/shape.rb +123 -0
- data/lib/rubysketch/sprite.rb +51 -16
- data/rubysketch.gemspec +5 -5
- metadata +14 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96ae60d6cddfaf8e77134a40cd35024a252278bc9b87755eb235ad6ef96151b5
|
|
4
|
+
data.tar.gz: c3bb6f454cfb2d5f6c9f872571842a82affe84e08bde8d7b68e4a95b46dd65a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38bbd11f37d0541d94ad2e06c468116e0f215561c6e53798a6adb1b5a1bba7a5b634b39415387f354f3e6907d4cb4685417a86c865d9e20f3fe1c2161ad353dd
|
|
7
|
+
data.tar.gz: 6f7664cd66b93f54897c0904a41b64ec0c79060c4d661a3b8f6858298c64ef0cbb6e7f4e8c9fe115ee50f7cbb00e02b75bee0949396e5514dd3b44d43146b9e8
|
data/ChangeLog.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# rubysketch ChangeLog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## [v0.5.32] - 2023-10-29
|
|
5
|
+
|
|
6
|
+
- Add Shape class
|
|
7
|
+
- Add Circle shape class and Sprite can take 'shape' parameter
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [v0.5.31] - 2023-10-25
|
|
11
|
+
|
|
12
|
+
- Add toon.rb
|
|
13
|
+
|
|
14
|
+
|
|
4
15
|
## [v0.5.30] - 2023-08-24
|
|
5
16
|
|
|
6
17
|
- Fix failed test
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.5.
|
|
1
|
+
0.5.32
|
data/examples/physics.rb
CHANGED
data/examples/toon.rb
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
|
|
9
|
+
class Canvas < Sprite
|
|
10
|
+
|
|
11
|
+
def initialize(width, height, scale: 1)
|
|
12
|
+
super 0, 0, width, height
|
|
13
|
+
|
|
14
|
+
@width, @height, @scale = width, height, scale
|
|
15
|
+
@images, @frame = [], 0
|
|
16
|
+
|
|
17
|
+
brushSize 1
|
|
18
|
+
brushColor 0, 0, 0, 255
|
|
19
|
+
|
|
20
|
+
self.draw do
|
|
21
|
+
drawImage self.image, 0, 0, self.width * self.scale, self.height * self.scale
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
self.mousePressed {brushStarted self.mouseX / self.scale, self.mouseY / self.scale}
|
|
25
|
+
self.mouseReleased {brushEnded self.mouseX / self.scale, self.mouseY / self.scale}
|
|
26
|
+
self.mouseDragged {brushMoved self.mouseX / self.scale, self.mouseY / self.scale}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
attr_reader :width, :height, :scale
|
|
30
|
+
|
|
31
|
+
def image()
|
|
32
|
+
@images.insert @frame, createImage(width, height) if @frame >= @images.size
|
|
33
|
+
@images[@frame]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def play()
|
|
37
|
+
setInterval 0.2, id: :play do
|
|
38
|
+
@frame += 1
|
|
39
|
+
@frame = 0 if @frame >= @images.size
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def stop()
|
|
44
|
+
clearInterval :play
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def nextFrame()
|
|
48
|
+
@frame += 1
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def prevFrame()
|
|
52
|
+
@frame -= 1
|
|
53
|
+
@frame = 0 if @frame < 0
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def brushSize(size)
|
|
57
|
+
@brushSize = size
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def brushColor(r, g, b, a = 255)
|
|
61
|
+
@brushColor = [r, g, b, a]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def drawPoint(x, y)
|
|
65
|
+
image.beginDraw do |g|
|
|
66
|
+
g.noFill
|
|
67
|
+
g.strokeWeight @brushSize
|
|
68
|
+
g.stroke *@brushColor
|
|
69
|
+
g.point x, y
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def drawLine(x1, y1, x2, y2)
|
|
74
|
+
image.beginDraw do |g|
|
|
75
|
+
g.noFill
|
|
76
|
+
g.strokeWeight @brushSize
|
|
77
|
+
g.stroke *@brushColor
|
|
78
|
+
g.line x1, y1, x2, y2
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def brushStarted(x, y)
|
|
83
|
+
drawPoint x, y
|
|
84
|
+
@prevPoint = [x, y]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def brushEnded(x, y)
|
|
88
|
+
@prevPoint = nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def brushMoved(x, y)
|
|
92
|
+
return unless @prevPoint
|
|
93
|
+
drawLine *@prevPoint, x, y
|
|
94
|
+
@prevPoint = [x, y]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def createImage(w, h)
|
|
100
|
+
createGraphics(w, h).tap do |g|
|
|
101
|
+
g.beginDraw do
|
|
102
|
+
g.background 255
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end# Canvas
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class Button < Sprite
|
|
111
|
+
|
|
112
|
+
def initialize(label, x = 0, y = 0, w = 100, h = 44, rgb: [200, 200, 200], &block)
|
|
113
|
+
super x, y, w, h
|
|
114
|
+
|
|
115
|
+
draw do
|
|
116
|
+
round, offset = 12, 8
|
|
117
|
+
ww, hh = self.w, self.h - offset
|
|
118
|
+
yy = mousePressed ? 6 : 0
|
|
119
|
+
|
|
120
|
+
fill *rgb.map {_1 - 32}
|
|
121
|
+
rect 0, offset, ww, hh, round
|
|
122
|
+
|
|
123
|
+
fill *rgb
|
|
124
|
+
rect 0, yy, ww, hh, round
|
|
125
|
+
|
|
126
|
+
textAlign CENTER, CENTER
|
|
127
|
+
fill 0
|
|
128
|
+
text label, 0, yy, ww, hh
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
mouseClicked do
|
|
132
|
+
block.call
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
end# Button
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class App
|
|
140
|
+
|
|
141
|
+
MARGIN = 10
|
|
142
|
+
|
|
143
|
+
def initialize()
|
|
144
|
+
setTitle 'Toon!'
|
|
145
|
+
size 800, 600
|
|
146
|
+
noStroke
|
|
147
|
+
|
|
148
|
+
@canvas = Canvas.new 160, 120, scale: 3
|
|
149
|
+
@buttons = [
|
|
150
|
+
Button.new('Play', rgb: [240, 180, 180]) {@canvas.play},
|
|
151
|
+
Button.new('Stop', rgb: [240, 180, 180]) {@canvas.stop},
|
|
152
|
+
Button.new('Next', rgb: [180, 240, 180]) {@canvas.nextFrame},
|
|
153
|
+
Button.new('Previous', rgb: [180, 240, 180]) {@canvas.prevFrame},
|
|
154
|
+
Button.new('Brush 1px', rgb: [180, 180, 240]) {@canvas.brushSize 1},
|
|
155
|
+
Button.new('Brush 3px', rgb: [180, 180, 240]) {@canvas.brushSize 3},
|
|
156
|
+
Button.new('Brush 5px', rgb: [180, 180, 240]) {@canvas.brushSize 5},
|
|
157
|
+
]
|
|
158
|
+
@sprites = [@canvas, *@buttons]
|
|
159
|
+
@sprites.each {addSprite _1}
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def draw()
|
|
163
|
+
background 100
|
|
164
|
+
sprite *@sprites
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def resized()
|
|
168
|
+
@buttons.first.pos = [MARGIN, MARGIN]
|
|
169
|
+
@buttons.each_cons(2) {_2.pos = [MARGIN, _1.bottom + MARGIN]}
|
|
170
|
+
|
|
171
|
+
@canvas.pos = [@buttons.first.right + MARGIN, MARGIN]
|
|
172
|
+
@canvas.right = windowWidth
|
|
173
|
+
@canvas.bottom = windowHeight
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end# App
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
setup {$app = App.new}
|
|
180
|
+
draw {$app.draw}
|
|
181
|
+
windowResized {$app.resized if $app}
|
data/lib/rubysketch/all.rb
CHANGED
data/lib/rubysketch/context.rb
CHANGED
|
@@ -4,6 +4,7 @@ module RubySketch
|
|
|
4
4
|
class Context < Processing::Context
|
|
5
5
|
|
|
6
6
|
Sprite = RubySketch::Sprite
|
|
7
|
+
Circle = RubySketch::Circle
|
|
7
8
|
Sound = RubySketch::Sound
|
|
8
9
|
|
|
9
10
|
# @private
|
|
@@ -141,31 +142,49 @@ module RubySketch
|
|
|
141
142
|
|
|
142
143
|
# Creates a new sprite and add it to physics engine.
|
|
143
144
|
#
|
|
145
|
+
# @overload createSprite(x, y, w, h)
|
|
146
|
+
# pos(x, y), size: [w, h]
|
|
147
|
+
# @param [Numeric] x x of the sprite position
|
|
148
|
+
# @param [Numeric] y y of the sprite position
|
|
149
|
+
# @param [Numeric] w width of the sprite
|
|
150
|
+
# @param [Numeric] h height of the sprite
|
|
151
|
+
#
|
|
144
152
|
# @overload createSprite(image: img)
|
|
145
153
|
# pos: [0, 0], size: [image.width, image.height]
|
|
146
154
|
# @param [Image] img sprite image
|
|
147
155
|
#
|
|
148
156
|
# @overload createSprite(x, y, image: img)
|
|
149
157
|
# pos: [x, y], size: [image.width, image.height]
|
|
150
|
-
# @param [Numeric] x x of sprite position
|
|
151
|
-
# @param [Numeric] y y of sprite position
|
|
158
|
+
# @param [Numeric] x x of the sprite position
|
|
159
|
+
# @param [Numeric] y y of the sprite position
|
|
152
160
|
# @param [Image] img sprite image
|
|
153
161
|
#
|
|
154
|
-
# @overload createSprite(x, y,
|
|
155
|
-
# pos
|
|
156
|
-
# @param [Numeric] x
|
|
157
|
-
# @param [Numeric] y
|
|
158
|
-
# @param [
|
|
159
|
-
# @param [
|
|
160
|
-
#
|
|
161
|
-
# @overload createSprite(x, y,
|
|
162
|
-
# pos: [x, y], size: [
|
|
163
|
-
# @param [Numeric] x x of sprite position
|
|
164
|
-
# @param [Numeric] y y of sprite position
|
|
165
|
-
# @param [Numeric] w width of sprite
|
|
166
|
-
# @param [Numeric] h height of sprite
|
|
162
|
+
# @overload createSprite(x, y, image: img, offset: off)
|
|
163
|
+
# pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
|
|
164
|
+
# @param [Numeric] x x of the sprite position
|
|
165
|
+
# @param [Numeric] y y of the sprite position
|
|
166
|
+
# @param [Image] img sprite image
|
|
167
|
+
# @param [Vector] off offset of the sprite image
|
|
168
|
+
#
|
|
169
|
+
# @overload createSprite(x, y, image: img, shape: shp)
|
|
170
|
+
# pos: [x, y], size: [image.width, image.height]
|
|
171
|
+
# @param [Numeric] x x of the sprite position
|
|
172
|
+
# @param [Numeric] y y of the sprite position
|
|
167
173
|
# @param [Image] img sprite image
|
|
168
|
-
#
|
|
174
|
+
#
|
|
175
|
+
# @overload createSprite(x, y, image: img, offset: off, shape: shp)
|
|
176
|
+
# pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
|
|
177
|
+
# @param [Numeric] x x of the sprite position
|
|
178
|
+
# @param [Numeric] y y of the sprite position
|
|
179
|
+
# @param [Image] img sprite image
|
|
180
|
+
# @param [Vector] off offset of the sprite image
|
|
181
|
+
# @param [Shape] shp shape of the sprite for physics calculations
|
|
182
|
+
#
|
|
183
|
+
# @overload createSprite(x, y, shape: shp)
|
|
184
|
+
# pos: [x, y], size: [shape.width, shape.height]
|
|
185
|
+
# @param [Numeric] x x of the sprite position
|
|
186
|
+
# @param [Numeric] y y of the sprite position
|
|
187
|
+
# @param [Shape] shp shape of the sprite for physics calculations
|
|
169
188
|
#
|
|
170
189
|
def createSprite(*args, **kwargs)
|
|
171
190
|
addSprite Sprite.new(*args, **kwargs, context: self)
|
|
@@ -210,16 +229,16 @@ module RubySketch
|
|
|
210
229
|
translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
|
|
211
230
|
rotate fromDegrees__ degrees
|
|
212
231
|
translate (-pivot.x) * f.w, (-pivot.y) * f.h
|
|
213
|
-
draw.call {
|
|
232
|
+
draw.call {sp.draw__ self, 0, 0, f.w, f.h}
|
|
214
233
|
end
|
|
215
234
|
elsif degrees == 0
|
|
216
|
-
|
|
235
|
+
sp.draw__ self, f.x, f.y, f.w, f.h
|
|
217
236
|
else
|
|
218
237
|
pushMatrix do
|
|
219
238
|
translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
|
|
220
239
|
rotate fromDegrees__ degrees
|
|
221
240
|
translate (-pivot.x) * f.w, (-pivot.y) * f.h
|
|
222
|
-
|
|
241
|
+
sp.draw__ self, 0, 0, f.w, f.h
|
|
223
242
|
end
|
|
224
243
|
end
|
|
225
244
|
end
|
|
@@ -228,18 +247,6 @@ module RubySketch
|
|
|
228
247
|
|
|
229
248
|
alias drawSprite sprite
|
|
230
249
|
|
|
231
|
-
# @private
|
|
232
|
-
def drawSprite__(sp, x, y, w, h)
|
|
233
|
-
img, off = sp.image, sp.offset
|
|
234
|
-
if img && off
|
|
235
|
-
copy img, off.x, off.y, w, h, x, y, w, h
|
|
236
|
-
elsif img
|
|
237
|
-
image img, x, y
|
|
238
|
-
else
|
|
239
|
-
rect x, y, w, h
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
|
|
243
250
|
# Loads sound file.
|
|
244
251
|
#
|
|
245
252
|
# @param [String] path path for sound file
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
module RubySketch
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# Shape class for physics calculations.
|
|
5
|
+
#
|
|
6
|
+
class Shape
|
|
7
|
+
|
|
8
|
+
include Xot::Inspectable
|
|
9
|
+
|
|
10
|
+
# @private
|
|
11
|
+
def initialize(shape)
|
|
12
|
+
@shape = shape or raise ArgumentError
|
|
13
|
+
@shape.instance_variable_set :@owner__, self
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns the width of the shape.
|
|
17
|
+
#
|
|
18
|
+
# @return [Numeric] width
|
|
19
|
+
#
|
|
20
|
+
def width()
|
|
21
|
+
@shape.width
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns the height of the shape.
|
|
25
|
+
#
|
|
26
|
+
# @return [Numeric] height
|
|
27
|
+
#
|
|
28
|
+
def height()
|
|
29
|
+
@shape.height
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
alias w width
|
|
33
|
+
alias h height
|
|
34
|
+
|
|
35
|
+
# Set this shape as a sensor object.
|
|
36
|
+
# Sensor object receives contact events, but no collisions.
|
|
37
|
+
#
|
|
38
|
+
# @return [Boolean] sensor or not
|
|
39
|
+
#
|
|
40
|
+
def sensor=(state)
|
|
41
|
+
@shape.sensor = state
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Returns weather the shape is a sensor or not.
|
|
45
|
+
#
|
|
46
|
+
# @return [Boolean] sensor or not
|
|
47
|
+
#
|
|
48
|
+
def sensor?()
|
|
49
|
+
@shape.sensor?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Defines contact block.
|
|
53
|
+
#
|
|
54
|
+
# @example Score increases when the shape touches a coin
|
|
55
|
+
# shape.contact do |o|
|
|
56
|
+
# score += 1 if o.coin?
|
|
57
|
+
# end
|
|
58
|
+
#
|
|
59
|
+
# @return [nil] nil
|
|
60
|
+
#
|
|
61
|
+
def contact(&block)
|
|
62
|
+
@shape.contact_begin do |other|
|
|
63
|
+
block.call other.instance_variable_get :@owner__ if block
|
|
64
|
+
end
|
|
65
|
+
nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Defines contact_end block.
|
|
69
|
+
#
|
|
70
|
+
# @example Call jumping() when the shape leaves the ground sprite
|
|
71
|
+
# shape.contact_end do |o|
|
|
72
|
+
# jumping if o == groundSprite
|
|
73
|
+
# end
|
|
74
|
+
#
|
|
75
|
+
# @return [nil] nil
|
|
76
|
+
#
|
|
77
|
+
def contact_end(&block)
|
|
78
|
+
@shape.contact_end do |other|
|
|
79
|
+
block.call other.instance_variable_get :@owner__ if block
|
|
80
|
+
end
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @private
|
|
85
|
+
def getInternal__()
|
|
86
|
+
@shape
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# @private
|
|
90
|
+
def draw__(context, x, y, width, height)
|
|
91
|
+
raise NotImplementedError
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end# Shape
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# Circle shape object.
|
|
98
|
+
#
|
|
99
|
+
class Circle < Shape
|
|
100
|
+
|
|
101
|
+
# Initialize circle object.
|
|
102
|
+
#
|
|
103
|
+
# @param [Numeric] x x of the circle shape position
|
|
104
|
+
# @param [Numeric] y y of the circle shape position
|
|
105
|
+
# @param [Numeric] size width and height of the circle shape
|
|
106
|
+
#
|
|
107
|
+
def initialize(x, y, size)
|
|
108
|
+
super Reflex::EllipseShape.new(frame: [x, y, size, size])
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @private
|
|
112
|
+
def draw__(c, x, y, w, h)
|
|
113
|
+
f = @shape.frame
|
|
114
|
+
c.pushStyle do
|
|
115
|
+
c.ellipseMode CORNER
|
|
116
|
+
c.ellipse x + f.x, y + f.y, f.w, f.h
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
end# Circle
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
end# RubySketch
|
data/lib/rubysketch/sprite.rb
CHANGED
|
@@ -9,6 +9,13 @@ module RubySketch
|
|
|
9
9
|
|
|
10
10
|
# Initialize sprite object.
|
|
11
11
|
#
|
|
12
|
+
# @overload new(x, y, w, h)
|
|
13
|
+
# pos(x, y), size: [w, h]
|
|
14
|
+
# @param [Numeric] x x of the sprite position
|
|
15
|
+
# @param [Numeric] y y of the sprite position
|
|
16
|
+
# @param [Numeric] w width of the sprite
|
|
17
|
+
# @param [Numeric] h height of the sprite
|
|
18
|
+
#
|
|
12
19
|
# @overload new(image: img)
|
|
13
20
|
# pos: [0, 0], size: [image.width, image.height]
|
|
14
21
|
# @param [Image] img sprite image
|
|
@@ -19,36 +26,49 @@ module RubySketch
|
|
|
19
26
|
# @param [Numeric] y y of the sprite position
|
|
20
27
|
# @param [Image] img sprite image
|
|
21
28
|
#
|
|
22
|
-
# @overload new(x, y,
|
|
23
|
-
# pos
|
|
24
|
-
# @param [Numeric] x
|
|
25
|
-
# @param [Numeric] y
|
|
26
|
-
# @param [
|
|
27
|
-
# @param [
|
|
29
|
+
# @overload new(x, y, image: img, offset: off)
|
|
30
|
+
# pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
|
|
31
|
+
# @param [Numeric] x x of the sprite position
|
|
32
|
+
# @param [Numeric] y y of the sprite position
|
|
33
|
+
# @param [Image] img sprite image
|
|
34
|
+
# @param [Vector] off offset of the sprite image
|
|
35
|
+
#
|
|
36
|
+
# @overload new(x, y, image: img, shape: shp)
|
|
37
|
+
# pos: [x, y], size: [image.width, image.height]
|
|
38
|
+
# @param [Numeric] x x of the sprite position
|
|
39
|
+
# @param [Numeric] y y of the sprite position
|
|
40
|
+
# @param [Image] img sprite image
|
|
28
41
|
#
|
|
29
|
-
# @overload new(x, y,
|
|
30
|
-
# pos: [x, y], size: [
|
|
42
|
+
# @overload new(x, y, image: img, offset: off, shape: shp)
|
|
43
|
+
# pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
|
|
31
44
|
# @param [Numeric] x x of the sprite position
|
|
32
45
|
# @param [Numeric] y y of the sprite position
|
|
33
|
-
# @param [Numeric] w width of the sprite
|
|
34
|
-
# @param [Numeric] h height of the sprite
|
|
35
46
|
# @param [Image] img sprite image
|
|
36
47
|
# @param [Vector] off offset of the sprite image
|
|
48
|
+
# @param [Shape] shp shape of the sprite for physics calculations
|
|
49
|
+
#
|
|
50
|
+
# @overload new(x, y, shape: shp)
|
|
51
|
+
# pos: [x, y], size: [shape.width, shape.height]
|
|
52
|
+
# @param [Numeric] x x of the sprite position
|
|
53
|
+
# @param [Numeric] y y of the sprite position
|
|
54
|
+
# @param [Shape] shp shape of the sprite for physics calculations
|
|
37
55
|
#
|
|
38
56
|
def initialize(
|
|
39
|
-
x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil,
|
|
57
|
+
x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil, shape: nil,
|
|
40
58
|
physics: true, context: nil)
|
|
41
59
|
|
|
42
|
-
w ||= (image&.width || 0)
|
|
43
|
-
h ||= (image&.height || 0)
|
|
60
|
+
w ||= (image&.width || shape&.width || 0)
|
|
61
|
+
h ||= (image&.height || shape&.height || 0)
|
|
44
62
|
raise 'invalid size' unless w >= 0 && h >= 0
|
|
45
63
|
raise 'invalid image' if image && !image.getInternal__.is_a?(Rays::Image)
|
|
64
|
+
raise 'invalid shape' if shape && !shape.getInternal__.is_a?(Reflex::Shape)
|
|
46
65
|
|
|
47
66
|
@context__ = context || Context.context__
|
|
67
|
+
@shape__ = shape
|
|
48
68
|
@view__ = SpriteView.new(
|
|
49
69
|
self, x: x, y: y, w: w, h: h,
|
|
50
|
-
|
|
51
|
-
|
|
70
|
+
shape: @shape__, physics: physics, back: :white)
|
|
71
|
+
@view__.set density: 1, friction: 0, restitution: 0
|
|
52
72
|
|
|
53
73
|
self.image = image if image
|
|
54
74
|
self.offset = offset if offset
|
|
@@ -878,6 +898,20 @@ module RubySketch
|
|
|
878
898
|
@view__
|
|
879
899
|
end
|
|
880
900
|
|
|
901
|
+
# @private
|
|
902
|
+
def draw__(c, x, y, w, h)
|
|
903
|
+
img, off = @image__, @offset__
|
|
904
|
+
if img && off
|
|
905
|
+
c.copy img, off.x, off.y, w, h, x, y, w, h
|
|
906
|
+
elsif img
|
|
907
|
+
c.image img, x, y
|
|
908
|
+
elsif @shape__
|
|
909
|
+
@shape__.draw__ c, x, y, w, h
|
|
910
|
+
else
|
|
911
|
+
c.rect x, y, w, h
|
|
912
|
+
end
|
|
913
|
+
end
|
|
914
|
+
|
|
881
915
|
end# Sprite
|
|
882
916
|
|
|
883
917
|
|
|
@@ -891,7 +925,7 @@ module RubySketch
|
|
|
891
925
|
|
|
892
926
|
attr_reader :sprite, :touches
|
|
893
927
|
|
|
894
|
-
def initialize(sprite, *args, physics:, **kwargs, &block)
|
|
928
|
+
def initialize(sprite, *args, shape:, physics:, **kwargs, &block)
|
|
895
929
|
@sprite = sprite
|
|
896
930
|
super(*args, **kwargs, &block)
|
|
897
931
|
|
|
@@ -902,6 +936,7 @@ module RubySketch
|
|
|
902
936
|
@pointersReleased = []
|
|
903
937
|
@touches = []
|
|
904
938
|
|
|
939
|
+
self.shape = shape.getInternal__ if shape
|
|
905
940
|
self.static = true if physics
|
|
906
941
|
end
|
|
907
942
|
|
data/rubysketch.gemspec
CHANGED
|
@@ -26,11 +26,11 @@ Gem::Specification.new do |s|
|
|
|
26
26
|
s.required_ruby_version = '>= 3.0.0'
|
|
27
27
|
|
|
28
28
|
s.add_runtime_dependency 'xot', '~> 0.1.39'
|
|
29
|
-
s.add_runtime_dependency 'rucy', '~> 0.1.
|
|
30
|
-
s.add_runtime_dependency 'beeps', '~> 0.1.
|
|
31
|
-
s.add_runtime_dependency 'rays', '~> 0.1.
|
|
32
|
-
s.add_runtime_dependency 'reflexion', '~> 0.1.
|
|
33
|
-
s.add_runtime_dependency 'processing', '~> 0.5.
|
|
29
|
+
s.add_runtime_dependency 'rucy', '~> 0.1.40'
|
|
30
|
+
s.add_runtime_dependency 'beeps', '~> 0.1.42'
|
|
31
|
+
s.add_runtime_dependency 'rays', '~> 0.1.45'
|
|
32
|
+
s.add_runtime_dependency 'reflexion', '~> 0.1.52'
|
|
33
|
+
s.add_runtime_dependency 'processing', '~> 0.5.28'
|
|
34
34
|
|
|
35
35
|
s.add_development_dependency 'rake'
|
|
36
36
|
s.add_development_dependency 'test-unit'
|
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.5.
|
|
4
|
+
version: 0.5.32
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- xordog
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-
|
|
11
|
+
date: 2023-10-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: xot
|
|
@@ -30,70 +30,70 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.1.
|
|
33
|
+
version: 0.1.40
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.1.
|
|
40
|
+
version: 0.1.40
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: beeps
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.1.
|
|
47
|
+
version: 0.1.42
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.1.
|
|
54
|
+
version: 0.1.42
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: rays
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 0.1.
|
|
61
|
+
version: 0.1.45
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 0.1.
|
|
68
|
+
version: 0.1.45
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: reflexion
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0.1.
|
|
75
|
+
version: 0.1.52
|
|
76
76
|
type: :runtime
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 0.1.
|
|
82
|
+
version: 0.1.52
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: processing
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.5.
|
|
89
|
+
version: 0.5.28
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0.5.
|
|
96
|
+
version: 0.5.28
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: rake
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -158,12 +158,14 @@ files:
|
|
|
158
158
|
- examples/hello.rb
|
|
159
159
|
- examples/physics.rb
|
|
160
160
|
- examples/sprite.rb
|
|
161
|
+
- examples/toon.rb
|
|
161
162
|
- lib/rubysketch.rb
|
|
162
163
|
- lib/rubysketch/all.rb
|
|
163
164
|
- lib/rubysketch/context.rb
|
|
164
165
|
- lib/rubysketch/easings.rb
|
|
165
166
|
- lib/rubysketch/extension.rb
|
|
166
167
|
- lib/rubysketch/helper.rb
|
|
168
|
+
- lib/rubysketch/shape.rb
|
|
167
169
|
- lib/rubysketch/sound.rb
|
|
168
170
|
- lib/rubysketch/sprite.rb
|
|
169
171
|
- pod.rake
|