rubysketch 0.3.5 → 0.3.10
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/.github/workflows/release.yml +62 -0
- data/.github/workflows/test.yml +27 -0
- data/ChangeLog.md +33 -0
- data/Gemfile +4 -0
- data/Rakefile +25 -0
- data/VERSION +1 -1
- data/examples/breakout.rb +212 -0
- data/examples/camera.rb +14 -0
- data/examples/delay_camera.rb +33 -0
- data/lib/rubysketch-processing.rb +11 -3
- data/lib/rubysketch/processing.rb +197 -33
- data/rubysketch.gemspec +0 -8
- data/test/helper.rb +0 -5
- data/test/processing/test_utility.rb +17 -8
- metadata +12 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 756b461427f81652025d1b032458a21e02a0405cbe876f93f42868a2a0d63091
|
4
|
+
data.tar.gz: 484f88ebc98855c074c7b2b8a1d11c0384d9acc9267775c9f72b68cd730c3967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbfb538eaf51488a522b98f41e6c193d40aabf960421118cfd63d76072bada647ba3dbb993e23bf52d025701b348c2736a893308a9dc220e4347e7caa91bafff
|
7
|
+
data.tar.gz: 79871d6ed4f4c2fa0799ccfdeb62062a963c9dce05b7b17feafa5b23dba937d69cb3839efb986ed51f9f334c370accf82aebe0417305a9c186ea3f9b05a04415
|
@@ -0,0 +1,62 @@
|
|
1
|
+
name: Release
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags: ['v[0-9]*']
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
release:
|
9
|
+
runs-on: macos-latest
|
10
|
+
|
11
|
+
steps:
|
12
|
+
- name: checkout
|
13
|
+
uses: actions/checkout@v2
|
14
|
+
|
15
|
+
- name: ruby 2.6
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.6.x
|
19
|
+
|
20
|
+
- name: install gems
|
21
|
+
run: |
|
22
|
+
gem install bundler
|
23
|
+
bundle install --jobs 4 --retry 3
|
24
|
+
|
25
|
+
- name: version
|
26
|
+
id: version
|
27
|
+
run: |
|
28
|
+
echo ::set-output name=value::$(ruby -e 'print "${{ github.ref }}"[/\/v([\w\.\-]+)/, 1]')
|
29
|
+
|
30
|
+
- name: create gem
|
31
|
+
run: rake clean gem
|
32
|
+
|
33
|
+
- name: create release
|
34
|
+
id: create_release
|
35
|
+
uses: actions/create-release@v1
|
36
|
+
env:
|
37
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
38
|
+
with:
|
39
|
+
tag_name: ${{ github.ref }}
|
40
|
+
release_name: ${{ github.ref }}
|
41
|
+
draft: false
|
42
|
+
prerelease: false
|
43
|
+
|
44
|
+
- name: upload to releases
|
45
|
+
uses: actions/upload-release-asset@v1
|
46
|
+
env:
|
47
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
48
|
+
with:
|
49
|
+
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
50
|
+
asset_path: ./rubysketch-${{ steps.version.outputs.value }}.gem
|
51
|
+
asset_name: rubysketch-${{ steps.version.outputs.value }}.gem
|
52
|
+
asset_content_type: application/zip
|
53
|
+
|
54
|
+
- name: upload to rubygems
|
55
|
+
env:
|
56
|
+
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
|
57
|
+
run: |
|
58
|
+
mkdir -p $HOME/.gem
|
59
|
+
touch $HOME/.gem/credentials
|
60
|
+
chmod 0600 $HOME/.gem/credentials
|
61
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
62
|
+
rake upload
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: macos-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
|
16
|
+
- name: ruby 2.6
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.6.x
|
20
|
+
|
21
|
+
- name: install gems
|
22
|
+
run: |
|
23
|
+
gem install bundler
|
24
|
+
bundle install --jobs 4 --retry 3
|
25
|
+
|
26
|
+
- name: test
|
27
|
+
run: rake test
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,39 @@
|
|
1
1
|
# RubySketch ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [0.3.10] - 2020-12-1
|
5
|
+
|
6
|
+
- invert angle parameter value for arc() to fix compatibility to processing API
|
7
|
+
|
8
|
+
|
9
|
+
## [0.3.9] - 2020-11-30
|
10
|
+
|
11
|
+
- Graphics#beginDraw() can take block to call endDraw automatically
|
12
|
+
- Capture#start() always returns nil
|
13
|
+
- add delay_camera.rb
|
14
|
+
|
15
|
+
|
16
|
+
## [0.3.8] - 2020-11-27
|
17
|
+
|
18
|
+
- Capture#initialize() can take requestWidth, requestHeight and cameraName
|
19
|
+
- add Capture#width and Capture#height
|
20
|
+
|
21
|
+
|
22
|
+
## [0.3.7] - 2020-11-18
|
23
|
+
|
24
|
+
- add Capture class
|
25
|
+
- add log(), exp(), sqrt() and PI
|
26
|
+
- add examples/camera.rb
|
27
|
+
- add examples/breakout.rb
|
28
|
+
- fix error on calling image()
|
29
|
+
|
30
|
+
|
31
|
+
## [0.3.6] - 2020-08-02
|
32
|
+
|
33
|
+
- random() can take array or nothing
|
34
|
+
- use github actions to release gem package
|
35
|
+
|
36
|
+
|
4
37
|
## [0.3.5] - 2020-08-02
|
5
38
|
|
6
39
|
- add random()
|
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -23,3 +23,28 @@ generate_documents
|
|
23
23
|
build_ruby_gem
|
24
24
|
|
25
25
|
task :default => :test
|
26
|
+
|
27
|
+
|
28
|
+
namespace :version do
|
29
|
+
|
30
|
+
namespace :bump do
|
31
|
+
|
32
|
+
task :major do
|
33
|
+
update_and_tag_version 0
|
34
|
+
end
|
35
|
+
|
36
|
+
task :minor do
|
37
|
+
update_and_tag_version 1
|
38
|
+
end
|
39
|
+
|
40
|
+
task :patch do
|
41
|
+
update_and_tag_version 2
|
42
|
+
end
|
43
|
+
|
44
|
+
task :build do
|
45
|
+
update_and_tag_version 3
|
46
|
+
end
|
47
|
+
|
48
|
+
end# bump
|
49
|
+
|
50
|
+
end# version
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.10
|
@@ -0,0 +1,212 @@
|
|
1
|
+
%w[xot rays reflex 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-processing'
|
6
|
+
|
7
|
+
|
8
|
+
PADDING = 50
|
9
|
+
BRICK_COUNT = 10
|
10
|
+
|
11
|
+
$objs = []
|
12
|
+
$bar = nil
|
13
|
+
$gameover = false
|
14
|
+
|
15
|
+
setup do
|
16
|
+
addWalls
|
17
|
+
addBricks
|
18
|
+
|
19
|
+
colorMode HSB, 360, 100, 100
|
20
|
+
ellipseMode CORNER
|
21
|
+
background 0
|
22
|
+
noStroke
|
23
|
+
fill 0, 0, 100
|
24
|
+
end
|
25
|
+
|
26
|
+
draw do
|
27
|
+
background 0
|
28
|
+
$objs.each do |o|
|
29
|
+
o.update
|
30
|
+
o.draw
|
31
|
+
end
|
32
|
+
drawTexts
|
33
|
+
end
|
34
|
+
|
35
|
+
mousePressed do
|
36
|
+
start unless started?
|
37
|
+
end
|
38
|
+
|
39
|
+
mouseDragged do
|
40
|
+
$bar.pos.x = mouseX - $bar.w / 2 if $bar
|
41
|
+
end
|
42
|
+
|
43
|
+
def start()
|
44
|
+
$bar = Bar.new
|
45
|
+
$objs += [$bar, Ball.new($bar)]
|
46
|
+
end
|
47
|
+
|
48
|
+
def started?()
|
49
|
+
$bar
|
50
|
+
end
|
51
|
+
|
52
|
+
def gameover?()
|
53
|
+
started? &&
|
54
|
+
$objs.count {|o| o.kind_of? Ball} == 0
|
55
|
+
end
|
56
|
+
|
57
|
+
def cleared?()
|
58
|
+
started? && !gameover? &&
|
59
|
+
$objs.count {|o| o.kind_of? Brick} == 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def addWalls()
|
63
|
+
left = Obj.new 0, 0, 10, height
|
64
|
+
top = Obj.new 0, 0, width, 10
|
65
|
+
right = Obj.new width - 10, 0, 10, height
|
66
|
+
bottom = Bottom.new 0, height - 10, width, 10
|
67
|
+
$objs += [top, bottom, left, right]
|
68
|
+
end
|
69
|
+
|
70
|
+
def addBricks()
|
71
|
+
brickW = (width - PADDING * 2) / BRICK_COUNT
|
72
|
+
5.times do |y|
|
73
|
+
BRICK_COUNT.times do |x|
|
74
|
+
xx = PADDING + brickW * x
|
75
|
+
yy = PADDING + 30 * y
|
76
|
+
$objs.push Brick.new(xx, yy, brickW - 5, 20, y * 60)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def drawTexts()
|
82
|
+
push do
|
83
|
+
textAlign CENTER, CENTER
|
84
|
+
|
85
|
+
if !started?
|
86
|
+
fill 50, 100, 100
|
87
|
+
textSize 50
|
88
|
+
text "BREAKOUT", 0, 0, width, height
|
89
|
+
textSize 20
|
90
|
+
translate 0, 100
|
91
|
+
text "Tap to start!", 0, 0, width, height
|
92
|
+
elsif cleared?
|
93
|
+
fill 100, 80, 100
|
94
|
+
textSize 50
|
95
|
+
text "CLEAR!", 0, 0, width, height
|
96
|
+
elsif gameover?
|
97
|
+
fill 0, 20, 100
|
98
|
+
textSize 50
|
99
|
+
text "GAMEOVER", 0, 0, width, height
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class Obj
|
105
|
+
attr_reader :pos, :w, :h, :vel
|
106
|
+
|
107
|
+
def initialize(x, y, w, h, vx = 0, vy = 0)
|
108
|
+
@pos = createVector x, y
|
109
|
+
@w, @h = w, h
|
110
|
+
@vel = createVector vx, vy
|
111
|
+
end
|
112
|
+
|
113
|
+
def update()
|
114
|
+
@pos.add @vel
|
115
|
+
end
|
116
|
+
|
117
|
+
def draw()
|
118
|
+
rect @pos.x, @pos.y, @w, @h
|
119
|
+
end
|
120
|
+
|
121
|
+
def bounds()
|
122
|
+
x, y = @pos.x, @pos.y
|
123
|
+
return x, y, x + @w, y + @h
|
124
|
+
end
|
125
|
+
|
126
|
+
def center()
|
127
|
+
createVector @pos.x + @w / 2, @pos.y + @h / 2
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class Ball < Obj
|
132
|
+
def initialize(bar)
|
133
|
+
super bar.pos.x, bar.pos.y - bar.h, 20, 20
|
134
|
+
self.vel = createVector random(-1, 1), -1
|
135
|
+
end
|
136
|
+
|
137
|
+
def vel=(v)
|
138
|
+
@vel = v.dup.normalize.mult 8
|
139
|
+
end
|
140
|
+
|
141
|
+
def update()
|
142
|
+
b = bounds.dup
|
143
|
+
super
|
144
|
+
checkHit b
|
145
|
+
end
|
146
|
+
|
147
|
+
def checkHit(prevBounds)
|
148
|
+
x1, y1, x2, y2 = prevBounds
|
149
|
+
hitH = hitV = false
|
150
|
+
hits = []
|
151
|
+
$objs.each do |o|
|
152
|
+
next if o == self
|
153
|
+
next unless intersect? o
|
154
|
+
hits.push o
|
155
|
+
ox1, oy1, ox2, oy2 = o.bounds
|
156
|
+
hitH ||= !overlap?(x1, x2, ox1, ox2)
|
157
|
+
hitV ||= !overlap?(y1, y2, oy1, oy2)
|
158
|
+
end
|
159
|
+
vel.x *= -1 if hitH
|
160
|
+
vel.y *= -1 if hitV
|
161
|
+
|
162
|
+
hits.each {|o| hit o}
|
163
|
+
end
|
164
|
+
|
165
|
+
def intersect?(o)
|
166
|
+
x1, y1, x2, y2 = bounds
|
167
|
+
ox1, oy1, ox2, oy2 = o.bounds
|
168
|
+
overlap?(x1, x2, ox1, ox2) && overlap?(y1, y2, oy1, oy2)
|
169
|
+
end
|
170
|
+
|
171
|
+
def overlap?(a1, a2, b1, b2)
|
172
|
+
a1 <= b2 && b1 <= a2
|
173
|
+
end
|
174
|
+
|
175
|
+
def hit(o)
|
176
|
+
case o
|
177
|
+
when Bar then self.vel = center.sub o.center
|
178
|
+
when Brick then $objs.delete o
|
179
|
+
when Bottom then $objs.delete self unless cleared?
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class Bar < Obj
|
185
|
+
def initialize()
|
186
|
+
w = 100
|
187
|
+
super (width - w) / 2, height - 50, w, 20
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class Brick < Obj
|
192
|
+
def initialize(x, y, w, h, hue)
|
193
|
+
super x, y, w, h
|
194
|
+
@hue = hue
|
195
|
+
end
|
196
|
+
|
197
|
+
def draw()
|
198
|
+
push do
|
199
|
+
fill @hue, 50, 100
|
200
|
+
super
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class Bottom < Obj
|
206
|
+
def draw()
|
207
|
+
push do
|
208
|
+
fill 0, 0, 50
|
209
|
+
super
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
data/examples/camera.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
%w[xot rays reflex 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-processing'
|
6
|
+
|
7
|
+
|
8
|
+
cam = Capture.new 300, 300
|
9
|
+
cam.start
|
10
|
+
|
11
|
+
draw do
|
12
|
+
background 0
|
13
|
+
image cam, 0, 0
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
%w[xot rays reflex 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-processing'
|
6
|
+
|
7
|
+
|
8
|
+
w, h = width, height
|
9
|
+
|
10
|
+
cam = Capture.new w, h, Capture.list.last
|
11
|
+
cam.start
|
12
|
+
|
13
|
+
images = 60.times.map {
|
14
|
+
Graphics.new w, h
|
15
|
+
}
|
16
|
+
|
17
|
+
draw do
|
18
|
+
if frameCount % 2 == 0
|
19
|
+
images.unshift images.pop
|
20
|
+
images.first.tap do |image|
|
21
|
+
image.beginDraw {
|
22
|
+
image.image cam, 0, 0
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
background 0
|
28
|
+
segment_h= h / images.size
|
29
|
+
images.each.with_index do |image, i|
|
30
|
+
y = i * segment_h
|
31
|
+
copy image, 0, y, w, segment_h, 0, y, w, segment_h
|
32
|
+
end
|
33
|
+
end
|
@@ -2,10 +2,18 @@ require 'rubysketch'
|
|
2
2
|
|
3
3
|
|
4
4
|
begin
|
5
|
-
|
5
|
+
window = RubySketch::Window.new {start}
|
6
|
+
context = RubySketch::Processing::Context.new window
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
(context.methods - Object.instance_methods).each do |method|
|
9
|
+
define_method method do |*args, &block|
|
10
|
+
context.__send__ method, *args, &block
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context.class.constants.each do |const|
|
15
|
+
self.class.const_set const, context.class.const_get(const)
|
16
|
+
end
|
9
17
|
|
10
18
|
window.__send__ :begin_draw
|
11
19
|
at_exit do
|
@@ -141,9 +141,9 @@ module RubySketch
|
|
141
141
|
#
|
142
142
|
def lerp (*args, amount)
|
143
143
|
v = toVector__ *args
|
144
|
-
self.x =
|
145
|
-
self.y =
|
146
|
-
self.z =
|
144
|
+
self.x = x + (v.x - x) * amount
|
145
|
+
self.y = y + (v.y - y) * amount
|
146
|
+
self.z = z + (v.z - z) * amount
|
147
147
|
self
|
148
148
|
end
|
149
149
|
|
@@ -728,27 +728,127 @@ module RubySketch
|
|
728
728
|
end# Touch
|
729
729
|
|
730
730
|
|
731
|
+
# Camera object.
|
732
|
+
#
|
733
|
+
class Capture
|
734
|
+
|
735
|
+
# Returns a list of available camera device names
|
736
|
+
#
|
737
|
+
# @return [Array] device name list
|
738
|
+
#
|
739
|
+
def self.list ()
|
740
|
+
Rays::Camera.device_names
|
741
|
+
end
|
742
|
+
|
743
|
+
# Initialize camera object.
|
744
|
+
#
|
745
|
+
# @overload Capture.new()
|
746
|
+
# @overload Capture.new(cameraName)
|
747
|
+
# @overload Capture.new(requestWidth, requestHeight)
|
748
|
+
# @overload Capture.new(requestWidth, requestHeight, cameraName)
|
749
|
+
#
|
750
|
+
# @param requestWidth [Integer] captured image width
|
751
|
+
# @param requestHeight [Integer] captured image height
|
752
|
+
# @param cameraName [String] camera device name
|
753
|
+
#
|
754
|
+
def initialize (*args)
|
755
|
+
width, height, name =
|
756
|
+
if args.empty?
|
757
|
+
[-1, -1, nil]
|
758
|
+
elsif args[0].kind_of?(String)
|
759
|
+
[-1, -1, args[0]]
|
760
|
+
elsif args[0].kind_of?(Numeric) && args[1].kind_of?(Numeric)
|
761
|
+
[args[0], args[1], args[2]]
|
762
|
+
else
|
763
|
+
raise ArgumentError
|
764
|
+
end
|
765
|
+
@camera = Rays::Camera.new width, height, device_name: name
|
766
|
+
end
|
767
|
+
|
768
|
+
# Start capturing.
|
769
|
+
#
|
770
|
+
# @return [nil] nil
|
771
|
+
#
|
772
|
+
def start ()
|
773
|
+
raise "Failed to start capture" unless @camera.start
|
774
|
+
nil
|
775
|
+
end
|
776
|
+
|
777
|
+
# Stop capturing.
|
778
|
+
#
|
779
|
+
# @return [nil] nil
|
780
|
+
#
|
781
|
+
def stop ()
|
782
|
+
@camera.stop
|
783
|
+
nil
|
784
|
+
end
|
785
|
+
|
786
|
+
# Returns is the next captured image available?
|
787
|
+
#
|
788
|
+
# @return [Boolean] true means object has next frame
|
789
|
+
#
|
790
|
+
def available ()
|
791
|
+
@camera.active?
|
792
|
+
end
|
793
|
+
|
794
|
+
# Reads next frame image
|
795
|
+
#
|
796
|
+
def read ()
|
797
|
+
@camera.image
|
798
|
+
end
|
799
|
+
|
800
|
+
# Returns the width of captured image
|
801
|
+
#
|
802
|
+
# @return [Numeric] the width of captured image
|
803
|
+
#
|
804
|
+
def width ()
|
805
|
+
@camera.image&.width || 0
|
806
|
+
end
|
807
|
+
|
808
|
+
# Returns the height of captured image
|
809
|
+
#
|
810
|
+
# @return [Numeric] the height of captured image
|
811
|
+
#
|
812
|
+
def height ()
|
813
|
+
@camera.image&.height || 0
|
814
|
+
end
|
815
|
+
|
816
|
+
# @private
|
817
|
+
def getInternal__ ()
|
818
|
+
@camera.image || dummyImage__
|
819
|
+
end
|
820
|
+
|
821
|
+
# @private
|
822
|
+
private def dummyImage__ ()
|
823
|
+
@dummy ||= Rays::Image.new 1, 1
|
824
|
+
end
|
825
|
+
|
826
|
+
end# Capture
|
827
|
+
|
828
|
+
|
731
829
|
# Drawing context
|
732
830
|
#
|
733
831
|
module GraphicsContext
|
734
832
|
|
735
|
-
|
833
|
+
# PI
|
834
|
+
#
|
835
|
+
PI = Math::PI
|
736
836
|
|
737
837
|
# PI / 2
|
738
838
|
#
|
739
|
-
HALF_PI =
|
839
|
+
HALF_PI = PI / 2
|
740
840
|
|
741
841
|
# PI / 4
|
742
842
|
#
|
743
|
-
QUARTER_PI =
|
843
|
+
QUARTER_PI = PI / 4
|
744
844
|
|
745
845
|
# PI * 2
|
746
846
|
#
|
747
|
-
TWO_PI =
|
847
|
+
TWO_PI = PI * 2
|
748
848
|
|
749
849
|
# PI * 2
|
750
850
|
#
|
751
|
-
TAU =
|
851
|
+
TAU = PI * 2
|
752
852
|
|
753
853
|
# RGB mode for colorMode().
|
754
854
|
#
|
@@ -817,7 +917,7 @@ module RubySketch
|
|
817
917
|
@painter__ = painter
|
818
918
|
@painter__.miter_limit = 10
|
819
919
|
|
820
|
-
@
|
920
|
+
@drawing__ = false
|
821
921
|
@hsbColor__ = false
|
822
922
|
@colorMaxes__ = [1.0] * 4
|
823
923
|
@angleScale__ = 1.0
|
@@ -840,14 +940,16 @@ module RubySketch
|
|
840
940
|
stroke 0
|
841
941
|
end
|
842
942
|
|
843
|
-
|
943
|
+
# @private
|
944
|
+
def beginDraw__ ()
|
844
945
|
@matrixStack__.clear
|
845
946
|
@styleStack__.clear
|
846
|
-
@
|
947
|
+
@drawing__ = true
|
847
948
|
end
|
848
949
|
|
849
|
-
|
850
|
-
|
950
|
+
# @private
|
951
|
+
def endDraw__ ()
|
952
|
+
@drawing__ = false
|
851
953
|
end
|
852
954
|
|
853
955
|
def width ()
|
@@ -1267,8 +1369,8 @@ module RubySketch
|
|
1267
1369
|
def arc (a, b, c, d, start, stop)
|
1268
1370
|
assertDrawing__
|
1269
1371
|
x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
|
1270
|
-
start = toAngle__ start
|
1271
|
-
stop = toAngle__ stop
|
1372
|
+
start = toAngle__ -start
|
1373
|
+
stop = toAngle__ -stop
|
1272
1374
|
@painter__.ellipse x, y, w, h, from: start, to: stop
|
1273
1375
|
nil
|
1274
1376
|
end
|
@@ -1411,8 +1513,9 @@ module RubySketch
|
|
1411
1513
|
#
|
1412
1514
|
def image (img, a, b, c = nil, d = nil)
|
1413
1515
|
assertDrawing__
|
1414
|
-
|
1415
|
-
|
1516
|
+
i = img.getInternal__
|
1517
|
+
x, y, w, h = toXYWH__ @imageMode__, a, b, c || i.width, d || i.height
|
1518
|
+
@painter__.image i, x, y, w, h
|
1416
1519
|
nil
|
1417
1520
|
end
|
1418
1521
|
|
@@ -1588,13 +1691,13 @@ module RubySketch
|
|
1588
1691
|
end
|
1589
1692
|
|
1590
1693
|
# @private
|
1591
|
-
|
1694
|
+
def getInternal__ ()
|
1592
1695
|
@image__
|
1593
1696
|
end
|
1594
1697
|
|
1595
1698
|
# @private
|
1596
1699
|
private def assertDrawing__ ()
|
1597
|
-
raise "call beginDraw() before drawing" unless @
|
1700
|
+
raise "call beginDraw() before drawing" unless @drawing__
|
1598
1701
|
end
|
1599
1702
|
|
1600
1703
|
end# GraphicsContext
|
@@ -1606,20 +1709,30 @@ module RubySketch
|
|
1606
1709
|
|
1607
1710
|
include GraphicsContext
|
1608
1711
|
|
1712
|
+
# Initialize graphics object.
|
1713
|
+
#
|
1609
1714
|
def initialize (width, height)
|
1610
1715
|
@image__ = Rays::Image.new width, height
|
1611
1716
|
setup__ @image__.painter
|
1612
1717
|
end
|
1613
1718
|
|
1614
|
-
|
1719
|
+
# Start drawing.
|
1720
|
+
#
|
1721
|
+
def beginDraw (&block)
|
1615
1722
|
@painter__.__send__ :begin_paint
|
1616
|
-
|
1723
|
+
beginDraw__
|
1617
1724
|
push
|
1725
|
+
if block
|
1726
|
+
block.call
|
1727
|
+
endDraw
|
1728
|
+
end
|
1618
1729
|
end
|
1619
1730
|
|
1731
|
+
# End drawing.
|
1732
|
+
#
|
1620
1733
|
def endDraw ()
|
1621
1734
|
pop
|
1622
|
-
|
1735
|
+
endDraw__
|
1623
1736
|
@painter__.__send__ :end_paint
|
1624
1737
|
end
|
1625
1738
|
|
@@ -1628,23 +1741,29 @@ module RubySketch
|
|
1628
1741
|
|
1629
1742
|
# Processing context
|
1630
1743
|
#
|
1631
|
-
|
1744
|
+
class Context
|
1745
|
+
|
1746
|
+
include GraphicsContext
|
1632
1747
|
|
1633
|
-
|
1748
|
+
Vector = Processing::Vector
|
1749
|
+
Capture = Processing::Capture
|
1750
|
+
Graphics = Processing::Graphics
|
1634
1751
|
|
1752
|
+
# @private
|
1635
1753
|
@@context__ = nil
|
1636
1754
|
|
1755
|
+
# @private
|
1637
1756
|
def self.context__ ()
|
1638
1757
|
@@context__
|
1639
1758
|
end
|
1640
1759
|
|
1641
1760
|
# @private
|
1642
|
-
def
|
1761
|
+
def initialize (window)
|
1643
1762
|
@@context__ = self
|
1644
1763
|
|
1645
1764
|
@window__ = window
|
1646
1765
|
@image__ = @window__.canvas
|
1647
|
-
|
1766
|
+
setup__ @window__.canvas_painter.paint {background 0.8}
|
1648
1767
|
|
1649
1768
|
@loop__ = true
|
1650
1769
|
@redraw__ = false
|
@@ -1654,8 +1773,8 @@ module RubySketch
|
|
1654
1773
|
@mousePressed__ = false
|
1655
1774
|
@touches__ = []
|
1656
1775
|
|
1657
|
-
@window__.before_draw = proc {
|
1658
|
-
@window__.after_draw = proc {
|
1776
|
+
@window__.before_draw = proc {beginDraw__}
|
1777
|
+
@window__.after_draw = proc {endDraw__}
|
1659
1778
|
|
1660
1779
|
drawFrame = -> {
|
1661
1780
|
@image__ = @window__.canvas
|
@@ -1865,7 +1984,9 @@ module RubySketch
|
|
1865
1984
|
@redraw__ = true
|
1866
1985
|
end
|
1867
1986
|
|
1868
|
-
|
1987
|
+
#
|
1988
|
+
# Utilities
|
1989
|
+
#
|
1869
1990
|
|
1870
1991
|
# Returns the absolute number of the value.
|
1871
1992
|
#
|
@@ -1907,6 +2028,26 @@ module RubySketch
|
|
1907
2028
|
value.round
|
1908
2029
|
end
|
1909
2030
|
|
2031
|
+
# Returns the natural logarithm (the base-e logarithm) of a number.
|
2032
|
+
#
|
2033
|
+
# @param value [Numeric] number (> 0.0)
|
2034
|
+
#
|
2035
|
+
# @return [Numeric] result number
|
2036
|
+
#
|
2037
|
+
def log (n)
|
2038
|
+
Math.log n
|
2039
|
+
end
|
2040
|
+
|
2041
|
+
# Returns Euler's number e raised to the power of value.
|
2042
|
+
#
|
2043
|
+
# @param value [Numeric] number
|
2044
|
+
#
|
2045
|
+
# @return [Numeric] result number
|
2046
|
+
#
|
2047
|
+
def exp (n)
|
2048
|
+
Math.exp n
|
2049
|
+
end
|
2050
|
+
|
1910
2051
|
# Returns value raised to the power of exponent.
|
1911
2052
|
#
|
1912
2053
|
# @param value [Numeric] base number
|
@@ -1928,6 +2069,16 @@ module RubySketch
|
|
1928
2069
|
value * value
|
1929
2070
|
end
|
1930
2071
|
|
2072
|
+
# Returns squared value.
|
2073
|
+
#
|
2074
|
+
# @param value [Numeric] number
|
2075
|
+
#
|
2076
|
+
# @return [Numeric] squared value
|
2077
|
+
#
|
2078
|
+
def sqrt (value)
|
2079
|
+
Math.sqrt value
|
2080
|
+
end
|
2081
|
+
|
1931
2082
|
# Returns the magnitude (or length) of a vector.
|
1932
2083
|
#
|
1933
2084
|
# @overload mag(x, y)
|
@@ -2169,16 +2320,21 @@ module RubySketch
|
|
2169
2320
|
|
2170
2321
|
# Returns a random number in range low...high
|
2171
2322
|
#
|
2323
|
+
# @overload random()
|
2172
2324
|
# @overload random(high)
|
2173
2325
|
# @overload random(low, high)
|
2326
|
+
# @overload random(choices)
|
2174
2327
|
#
|
2175
|
-
# @param low
|
2176
|
-
# @param high
|
2328
|
+
# @param low [Numeric] lower limit
|
2329
|
+
# @param high [Numeric] upper limit
|
2330
|
+
# @param choices [Array] array to choose from
|
2177
2331
|
#
|
2178
2332
|
# @return [Float] random number
|
2179
2333
|
#
|
2180
|
-
def random (
|
2181
|
-
|
2334
|
+
def random (*args)
|
2335
|
+
return args.first.sample if args.first.kind_of? Array
|
2336
|
+
high, low = args.reverse
|
2337
|
+
rand (low || 0).to_f...(high || 1).to_f
|
2182
2338
|
end
|
2183
2339
|
|
2184
2340
|
# Creates a new vector.
|
@@ -2197,6 +2353,14 @@ module RubySketch
|
|
2197
2353
|
Vector.new *args
|
2198
2354
|
end
|
2199
2355
|
|
2356
|
+
# Creates a camera object as a video input device.
|
2357
|
+
#
|
2358
|
+
# @return [Capture] camera object
|
2359
|
+
#
|
2360
|
+
def createCapture (*args)
|
2361
|
+
Capture.new *args
|
2362
|
+
end
|
2363
|
+
|
2200
2364
|
# Creates a new off-screen graphics context object.
|
2201
2365
|
#
|
2202
2366
|
# @param width [Numeric] width of graphics image
|
data/rubysketch.gemspec
CHANGED
@@ -28,17 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
29
|
s.required_ruby_version = '~> 2'
|
30
30
|
|
31
|
-
s.add_runtime_dependency 'yard'
|
32
|
-
s.add_runtime_dependency 'xot', '~> 0.1'
|
33
|
-
s.add_runtime_dependency 'beeps', '~> 0.1'
|
34
|
-
s.add_runtime_dependency 'rucy', '~> 0.1'
|
35
|
-
s.add_runtime_dependency 'rays', '~> 0.1'
|
36
31
|
s.add_runtime_dependency 'reflexion', '~> 0.1'
|
37
32
|
|
38
33
|
s.files = `git ls-files`.split $/
|
39
34
|
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
40
35
|
s.extra_rdoc_files = rdocs.to_a
|
41
|
-
s.has_rdoc = true
|
42
|
-
|
43
|
-
s.extensions << 'Rakefile'
|
44
36
|
end
|
data/test/helper.rb
CHANGED
@@ -6,22 +6,31 @@ require_relative '../helper'
|
|
6
6
|
|
7
7
|
class TestProcessingUtility < Test::Unit::TestCase
|
8
8
|
|
9
|
-
|
9
|
+
class Context
|
10
|
+
include RubySketch::Processing::Context
|
11
|
+
end
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
+
def context
|
14
|
+
Context.new
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_random ()
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
c = context
|
19
|
+
|
20
|
+
assert_equal Float, c.random(1).class
|
21
|
+
assert_equal Float, c.random(1.0).class
|
22
|
+
assert_equal Symbol, c.random((:a..:z).to_a).class
|
23
|
+
|
24
|
+
assert_not_equal c.random, c.random
|
19
25
|
|
20
26
|
10000.times do
|
21
|
-
n =
|
27
|
+
n = c.random
|
28
|
+
assert 0 <= n && n < 1
|
29
|
+
|
30
|
+
n = c.random 1
|
22
31
|
assert 0 <= n && n < 1
|
23
32
|
|
24
|
-
n =
|
33
|
+
n = c.random 1, 2
|
25
34
|
assert 1.0 <= n && n < 2.0
|
26
35
|
end
|
27
36
|
end
|
metadata
CHANGED
@@ -1,85 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysketch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: yard
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: xot
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.1'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: beeps
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.1'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.1'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rucy
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.1'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.1'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rays
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.1'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.1'
|
83
13
|
- !ruby/object:Gem::Dependency
|
84
14
|
name: reflexion
|
85
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,18 +27,23 @@ dependencies:
|
|
97
27
|
description: Creative Coding Framework have API compatible to Processing API or p5.js.
|
98
28
|
email: xordog@gmail.com
|
99
29
|
executables: []
|
100
|
-
extensions:
|
101
|
-
- Rakefile
|
30
|
+
extensions: []
|
102
31
|
extra_rdoc_files: []
|
103
32
|
files:
|
33
|
+
- ".github/workflows/release.yml"
|
34
|
+
- ".github/workflows/test.yml"
|
104
35
|
- ".gitignore"
|
105
36
|
- ".yardopts"
|
106
37
|
- ChangeLog.md
|
38
|
+
- Gemfile
|
107
39
|
- LICENSE
|
108
40
|
- README.md
|
109
41
|
- Rakefile
|
110
42
|
- VERSION
|
43
|
+
- examples/breakout.rb
|
44
|
+
- examples/camera.rb
|
111
45
|
- examples/clock.rb
|
46
|
+
- examples/delay_camera.rb
|
112
47
|
- examples/glsl.rb
|
113
48
|
- examples/hello.rb
|
114
49
|
- examples/image.rb
|
@@ -126,7 +61,7 @@ files:
|
|
126
61
|
homepage: https://github.com/xord/rubysketch
|
127
62
|
licenses: []
|
128
63
|
metadata: {}
|
129
|
-
post_install_message:
|
64
|
+
post_install_message:
|
130
65
|
rdoc_options: []
|
131
66
|
require_paths:
|
132
67
|
- lib
|
@@ -142,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
77
|
version: '0'
|
143
78
|
requirements: []
|
144
79
|
rubygems_version: 3.0.3
|
145
|
-
signing_key:
|
80
|
+
signing_key:
|
146
81
|
specification_version: 4
|
147
82
|
summary: Processing like Creative Coding Framework.
|
148
83
|
test_files:
|