rubysketch 0.5.28 → 0.5.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +26 -9
- data/VERSION +1 -1
- data/examples/toon.rb +181 -0
- data/lib/rubysketch/context.rb +1 -1
- data/lib/rubysketch/sprite.rb +32 -7
- data/rubysketch.gemspec +5 -5
- data/test/test_sprite.rb +10 -0
- metadata +13 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee4bec833e545d64ac7822c59d7b52e92a507ac23d909fd6143f15dace1ed8c4
|
4
|
+
data.tar.gz: 8151adda147364200efe13a96b2fce82b00c01fa25cb84c69f4de6ba5d9a6a4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d85c90842181d311cee151604fc1c38edc6d5b2d1caba4d3c9f206f512d98b5f93ced450f8ec6aaa760781bdfc61c8d92644cdc2f2b4811c63b7f81f70091ca2
|
7
|
+
data.tar.gz: 94978e5eadf6fbd607c4762adec4049df1930123be74c5cee46dfb582c0ec76f907f8a3e214cc162d779a9b96bc12a4904cd054f60ecae921db3abdb57a5ff0c
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
# rubysketch ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [v0.5.31] - 2023-10-25
|
5
|
+
|
6
|
+
- Add toon.rb
|
7
|
+
|
8
|
+
|
9
|
+
## [v0.5.30] - 2023-08-24
|
10
|
+
|
11
|
+
- Fix failed test
|
12
|
+
|
13
|
+
|
14
|
+
## [v0.5.29] - 2023-08-23
|
15
|
+
|
16
|
+
- Add Sprite#contact_end()
|
17
|
+
- Sprite.new() can take 'physics:' keyword parameter
|
18
|
+
- Fix that calling clearInterval() inside interval timer block would be ignored
|
19
|
+
|
20
|
+
|
4
21
|
## [v0.5.28] - 2023-07-30
|
5
22
|
|
6
23
|
- Update dependencies
|
@@ -8,7 +25,7 @@
|
|
8
25
|
|
9
26
|
## [v0.5.27] - 2023-07-30
|
10
27
|
|
11
|
-
-
|
28
|
+
- Add vibrate()
|
12
29
|
|
13
30
|
|
14
31
|
## [v0.5.26] - 2023-07-26
|
@@ -46,12 +63,12 @@
|
|
46
63
|
|
47
64
|
## [v0.5.20] - 2023-07-09
|
48
65
|
|
49
|
-
-
|
66
|
+
- Fix that calling mousePressed() without block removes mousePressed block
|
50
67
|
|
51
68
|
|
52
69
|
## [v0.5.19] - 2023-06-27
|
53
70
|
|
54
|
-
-
|
71
|
+
- Add loadSound() and RubySketch::Sound class
|
55
72
|
|
56
73
|
|
57
74
|
## [v0.5.18] - 2023-06-22
|
@@ -93,8 +110,8 @@
|
|
93
110
|
|
94
111
|
## [v0.5.11] - 2023-05-26
|
95
112
|
|
96
|
-
-
|
97
|
-
-
|
113
|
+
- Add left, top, right, and bottom accessors to Sprite class
|
114
|
+
- Add show(), hide(), and hidden?() to Sprite class
|
98
115
|
|
99
116
|
|
100
117
|
## [v0.5.10] - 2023-05-21
|
@@ -161,19 +178,19 @@
|
|
161
178
|
|
162
179
|
## [v0.5.2] - 2023-03-02
|
163
180
|
|
164
|
-
-
|
181
|
+
- Depend to processing-0.5.2 gem
|
165
182
|
|
166
183
|
|
167
184
|
## [v0.5.1] - 2023-03-01
|
168
185
|
|
169
|
-
-
|
186
|
+
- Fix bugs
|
170
187
|
|
171
188
|
|
172
189
|
## [v0.5.0] - 2023-02-09
|
173
190
|
|
174
|
-
-
|
191
|
+
- Add Sprite class
|
175
192
|
|
176
193
|
|
177
194
|
## [v0.4.0] - 2023-02-08
|
178
195
|
|
179
|
-
-
|
196
|
+
- First version
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.31
|
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/context.rb
CHANGED
data/lib/rubysketch/sprite.rb
CHANGED
@@ -37,7 +37,7 @@ module RubySketch
|
|
37
37
|
#
|
38
38
|
def initialize(
|
39
39
|
x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil,
|
40
|
-
context: nil)
|
40
|
+
physics: true, context: nil)
|
41
41
|
|
42
42
|
w ||= (image&.width || 0)
|
43
43
|
h ||= (image&.height || 0)
|
@@ -47,7 +47,7 @@ module RubySketch
|
|
47
47
|
@context__ = context || Context.context__
|
48
48
|
@view__ = SpriteView.new(
|
49
49
|
self, x: x, y: y, w: w, h: h,
|
50
|
-
|
50
|
+
physics: physics, density: 1, friction: 0, restitution: 0,
|
51
51
|
back: :white)
|
52
52
|
|
53
53
|
self.image = image if image
|
@@ -842,6 +842,21 @@ module RubySketch
|
|
842
842
|
#
|
843
843
|
def contact(&block)
|
844
844
|
@view__.contact = block if block
|
845
|
+
nil
|
846
|
+
end
|
847
|
+
|
848
|
+
# Defines contact_end block.
|
849
|
+
#
|
850
|
+
# @example Call jumping() when the player sprite leaves the ground sprite
|
851
|
+
# playerSprite.contact_end do |o|
|
852
|
+
# jumping if o == groundSprite
|
853
|
+
# end
|
854
|
+
#
|
855
|
+
# @return [nil] nil
|
856
|
+
#
|
857
|
+
def contact_end(&block)
|
858
|
+
@view__.contact_end = block if block
|
859
|
+
nil
|
845
860
|
end
|
846
861
|
|
847
862
|
# Defines contact? block.
|
@@ -855,6 +870,7 @@ module RubySketch
|
|
855
870
|
#
|
856
871
|
def contact?(&block)
|
857
872
|
@view__.will_contact = block if block
|
873
|
+
nil
|
858
874
|
end
|
859
875
|
|
860
876
|
# @private
|
@@ -871,13 +887,13 @@ module RubySketch
|
|
871
887
|
attr_accessor :update,
|
872
888
|
:mousePressed, :mouseReleased, :mouseMoved, :mouseDragged, :mouseClicked,
|
873
889
|
:touchStarted, :touchEnded, :touchMoved,
|
874
|
-
:contact, :will_contact
|
890
|
+
:contact, :contact_end, :will_contact
|
875
891
|
|
876
892
|
attr_reader :sprite, :touches
|
877
893
|
|
878
|
-
def initialize(sprite, *
|
894
|
+
def initialize(sprite, *args, physics:, **kwargs, &block)
|
879
895
|
@sprite = sprite
|
880
|
-
super(*
|
896
|
+
super(*args, **kwargs, &block)
|
881
897
|
|
882
898
|
@error = nil
|
883
899
|
@pointer = nil
|
@@ -885,6 +901,8 @@ module RubySketch
|
|
885
901
|
@pointersPressed = []
|
886
902
|
@pointersReleased = []
|
887
903
|
@touches = []
|
904
|
+
|
905
|
+
self.static = true if physics
|
888
906
|
end
|
889
907
|
|
890
908
|
def mouseX()
|
@@ -957,8 +975,15 @@ module RubySketch
|
|
957
975
|
end
|
958
976
|
|
959
977
|
def on_contact_begin(e)
|
978
|
+
return unless @contact
|
979
|
+
v = e.view
|
980
|
+
call_block @contact, v.sprite if v.respond_to?(:sprite)
|
981
|
+
end
|
982
|
+
|
983
|
+
def on_contact_end(e)
|
984
|
+
return unless @contact_end
|
960
985
|
v = e.view
|
961
|
-
call_block @
|
986
|
+
call_block @contact_end, v.sprite if v.respond_to?(:sprite)
|
962
987
|
end
|
963
988
|
|
964
989
|
def will_contact?(v)
|
@@ -997,7 +1022,7 @@ module RubySketch
|
|
997
1022
|
end
|
998
1023
|
|
999
1024
|
def mouseClicked?()
|
1000
|
-
return false unless @pointer && @pointerDownStartPos
|
1025
|
+
return false unless parent && @pointer && @pointerDownStartPos
|
1001
1026
|
[to_screen(@pointer.pos), @pointerDownStartPos]
|
1002
1027
|
.map {|pos| Rays::Point.new pos.x, pos.y, 0}
|
1003
1028
|
.then {|pos, startPos| (pos - startPos).length < 3}
|
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.44'
|
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'
|
data/test/test_sprite.rb
CHANGED
@@ -272,21 +272,31 @@ class TestSprite < Test::Unit::TestCase
|
|
272
272
|
v = s.instance_variable_get :@view__
|
273
273
|
assert_nil v.update
|
274
274
|
assert_nil v.contact
|
275
|
+
assert_nil v.contact_end
|
275
276
|
assert_nil v.will_contact
|
276
277
|
|
277
278
|
s.update {}
|
278
279
|
assert_not_nil v.update
|
279
280
|
assert_nil v.contact
|
281
|
+
assert_nil v.contact_end
|
280
282
|
assert_nil v.will_contact
|
281
283
|
|
282
284
|
s.contact {}
|
283
285
|
assert_not_nil v.update
|
284
286
|
assert_not_nil v.contact
|
287
|
+
assert_nil v.contact_end
|
288
|
+
assert_nil v.will_contact
|
289
|
+
|
290
|
+
s.contact_end {}
|
291
|
+
assert_not_nil v.update
|
292
|
+
assert_not_nil v.contact
|
293
|
+
assert_not_nil v.contact_end
|
285
294
|
assert_nil v.will_contact
|
286
295
|
|
287
296
|
s.contact? {}
|
288
297
|
assert_not_nil v.update
|
289
298
|
assert_not_nil v.contact
|
299
|
+
assert_not_nil v.contact_end
|
290
300
|
assert_not_nil v.will_contact
|
291
301
|
end
|
292
302
|
|
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.31
|
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-24 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.44
|
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.44
|
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,6 +158,7 @@ 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
|