processing 0.4.0
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 +7 -0
- data/.github/workflows/release.yml +62 -0
- data/.github/workflows/test.yml +27 -0
- data/.gitignore +6 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +180 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +11 -0
- data/Rakefile +50 -0
- data/RubyProcessing.podspec +28 -0
- data/VERSION +1 -0
- data/examples/breakout.rb +212 -0
- data/examples/camera.rb +14 -0
- data/examples/clock.rb +57 -0
- data/examples/delay_camera.rb +33 -0
- data/examples/hello.rb +12 -0
- data/examples/image.rb +13 -0
- data/examples/shapes.rb +121 -0
- data/lib/processing/app.rb +13 -0
- data/lib/processing/include.rb +25 -0
- data/lib/processing/module.rb +23 -0
- data/lib/processing/processing.rb +3211 -0
- data/lib/processing/window.rb +238 -0
- data/lib/processing.rb +11 -0
- data/lib/rubysketch-processing.rb +1 -0
- data/lib/rubysketch.rb +1 -0
- data/processing.gemspec +38 -0
- data/src/RubyProcessing.h +15 -0
- data/src/RubyProcessing.mm +55 -0
- data/test/helper.rb +19 -0
- data/test/processing/helper.rb +11 -0
- data/test/processing/test_graphics.rb +21 -0
- data/test/processing/test_shader.rb +47 -0
- data/test/processing/test_utility.rb +41 -0
- data/test/processing/test_vector.rb +394 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1b0e4311319c994f90579dafbd3a62b50f623977f6c60c26ba9f0b77a150b564
|
4
|
+
data.tar.gz: d7f5d796d918ed68ba50cb20fc148a7548b8a84dce0901a4ce1f7236740a994a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b176e101c82a244f61fa3210f5d6902c86f92f94eaac24858e4ab6671fc6983015f64d601d4f8e691ae7351002183cd350b31e27231407e7cc0b7aeb732cdbbd
|
7
|
+
data.tar.gz: 6d450c5cfaeb5280ab0f600afd421581ceb2dfe25b672f93ea4bfd9ebefd1afacae8ba54c73408bafe828e4522fe003c676299e501831e77c74fd8ab69efdbb7
|
@@ -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 3.0
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 3.0.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: ./processing-${{ steps.version.outputs.value }}.gem
|
51
|
+
asset_name: processing-${{ 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 3.0
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 3.0.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/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# Processing for CRuby ChangeLog
|
2
|
+
|
3
|
+
|
4
|
+
## [0.4.0] - 2022-12-29
|
5
|
+
|
6
|
+
- renamed from rubysketch.gem to processing.gem
|
7
|
+
- renamed from RubySketch Pod to RubyProcessing Pod
|
8
|
+
- delete glsl mode
|
9
|
+
|
10
|
+
|
11
|
+
## [0.3.22] - 2022-11-14
|
12
|
+
|
13
|
+
RubySketch::Processing
|
14
|
+
- add Shader class
|
15
|
+
- add shader(), resetShader(), createShader(), loadShader(), and filter()
|
16
|
+
- update the pixel density of context if the screen pixel density is changed
|
17
|
+
- setUniform() can also take array of numbers, vector, and texture image.
|
18
|
+
- pushStyle() manages states of textAlign, tint, and filter
|
19
|
+
- push/pushMatrix/pushStyle call pop() on ensure
|
20
|
+
|
21
|
+
RubySketch::GLSL
|
22
|
+
- displays with pixel density 1.0
|
23
|
+
|
24
|
+
|
25
|
+
## [0.3.21] - 2022-09-05
|
26
|
+
|
27
|
+
- add rubysketch-glsl.rb
|
28
|
+
- add blend(), createImage(), setTitle(), tint() and noTint()
|
29
|
+
- add save() that saves screen image to file
|
30
|
+
- circle() function is affected by ellipseMode()
|
31
|
+
- point() draws by line(x, y, x, y)
|
32
|
+
- change initial values for strokeCap and strokeJoin to ROUND and MITER
|
33
|
+
|
34
|
+
|
35
|
+
## [0.3.20] - 2022-07-24
|
36
|
+
|
37
|
+
- add mouseClicked()
|
38
|
+
- add blendMode()
|
39
|
+
- add clip() and noClip()
|
40
|
+
- translate() can take 'z' parameter
|
41
|
+
- fix that resizing canvas consumes too much memory
|
42
|
+
|
43
|
+
|
44
|
+
## [0.3.19] - 2021-12-5
|
45
|
+
|
46
|
+
- fix runtime error
|
47
|
+
|
48
|
+
|
49
|
+
## [0.3.18] - 2021-12-5
|
50
|
+
|
51
|
+
- add 'mouseButton'
|
52
|
+
- pointer cancel event calls pointer_up block
|
53
|
+
|
54
|
+
|
55
|
+
## [0.3.17] - 2021-12-5
|
56
|
+
|
57
|
+
- add Touch#id
|
58
|
+
|
59
|
+
|
60
|
+
## [0.3.16] - 2021-2-14
|
61
|
+
|
62
|
+
- add key, keyCode and keyPressed system values
|
63
|
+
- add keyPressed(), keyReleased() and keyTyped() functions
|
64
|
+
- add motionGravity value and motion() function
|
65
|
+
|
66
|
+
|
67
|
+
## [0.3.15] - 2020-12-12
|
68
|
+
|
69
|
+
- delete temporary directory on launch
|
70
|
+
|
71
|
+
|
72
|
+
## [0.3.14] - 2020-12-12
|
73
|
+
|
74
|
+
- fix loadImage() fails when Encoding.default_internal is not nil
|
75
|
+
|
76
|
+
|
77
|
+
## [0.3.13] - 2020-12-12
|
78
|
+
|
79
|
+
- size(), createCanvas(): default pixelDensity is same as current value
|
80
|
+
|
81
|
+
|
82
|
+
## [0.3.12] - 2020-12-10
|
83
|
+
|
84
|
+
- size() and createCanvas() take 'pixelDensity' parameter and default value is 1
|
85
|
+
|
86
|
+
|
87
|
+
## [0.3.11] - 2020-12-9
|
88
|
+
|
89
|
+
- add size(), createCanvas() and pixelDensity()
|
90
|
+
|
91
|
+
|
92
|
+
## [0.3.10] - 2020-12-1
|
93
|
+
|
94
|
+
- invert angle parameter value for arc() to fix compatibility to processing API
|
95
|
+
|
96
|
+
|
97
|
+
## [0.3.9] - 2020-11-30
|
98
|
+
|
99
|
+
- Graphics#beginDraw() can take block to call endDraw automatically
|
100
|
+
- Capture#start() always returns nil
|
101
|
+
- add delay_camera.rb
|
102
|
+
|
103
|
+
|
104
|
+
## [0.3.8] - 2020-11-27
|
105
|
+
|
106
|
+
- Capture#initialize() can take requestWidth, requestHeight and cameraName
|
107
|
+
- add Capture#width and Capture#height
|
108
|
+
|
109
|
+
|
110
|
+
## [0.3.7] - 2020-11-18
|
111
|
+
|
112
|
+
- add Capture class
|
113
|
+
- add log(), exp(), sqrt() and PI
|
114
|
+
- add examples/camera.rb
|
115
|
+
- add examples/breakout.rb
|
116
|
+
- fix error on calling image()
|
117
|
+
|
118
|
+
|
119
|
+
## [0.3.6] - 2020-08-02
|
120
|
+
|
121
|
+
- random() can take array or nothing
|
122
|
+
- use github actions to release gem package
|
123
|
+
|
124
|
+
|
125
|
+
## [0.3.5] - 2020-08-02
|
126
|
+
|
127
|
+
- add random()
|
128
|
+
- add sin(), cos(), tan(), asin(), acos(), atan() and atan2()
|
129
|
+
- make Vector class accessible from user script context
|
130
|
+
- fix error on calling rotate()
|
131
|
+
|
132
|
+
|
133
|
+
## [0.3.4] - 2020-08-02
|
134
|
+
|
135
|
+
- delete Utility module
|
136
|
+
|
137
|
+
|
138
|
+
## [0.3.3] - 2020-08-01
|
139
|
+
|
140
|
+
- add Vector class
|
141
|
+
|
142
|
+
|
143
|
+
## [0.3.2] - 2020-07-22
|
144
|
+
|
145
|
+
- text() draws to the baseline by default
|
146
|
+
- add textWidth(), textAscent(), textDescent() and textAlign()
|
147
|
+
- change initial color for fill() and stroke()
|
148
|
+
- change initial background color to grayscale 0.8
|
149
|
+
|
150
|
+
|
151
|
+
## [0.3.1] - 2020-07-17
|
152
|
+
|
153
|
+
- add touchStarted(), touchEnded(), touchMoved() and touches()
|
154
|
+
- make all event handler drawable
|
155
|
+
- limit font max size to 256
|
156
|
+
|
157
|
+
|
158
|
+
## [0.3.0] - 2020-05-21
|
159
|
+
|
160
|
+
- add createGraphics()
|
161
|
+
|
162
|
+
|
163
|
+
## [0.2.7] - 2020-04-17
|
164
|
+
|
165
|
+
- add strokeCap() and strokeJoin()
|
166
|
+
|
167
|
+
|
168
|
+
## [0.2.6] - 2020-04-17
|
169
|
+
|
170
|
+
- push(), pushMatrix() and pushStyle() take block to automatic pop
|
171
|
+
- refine startup process
|
172
|
+
- add curve() and bezier()
|
173
|
+
- add imageMode(), Image#resize(), Image#copy() and copy()
|
174
|
+
- add loop(), noLoop() and redraw()
|
175
|
+
|
176
|
+
|
177
|
+
## [0.2.5] - 2020-03-29
|
178
|
+
|
179
|
+
- delete debug prints
|
180
|
+
- show unsupported image type
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 xord.org
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[../xot ../rucy ../rays ../reflex .]
|
5
|
+
.map {|s| File.expand_path "#{s}/lib", __dir__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
|
+
|
8
|
+
require 'rucy/rake'
|
9
|
+
|
10
|
+
require 'xot/module'
|
11
|
+
require 'rucy/module'
|
12
|
+
require 'rays/module'
|
13
|
+
require 'reflex/module'
|
14
|
+
require 'processing/module'
|
15
|
+
|
16
|
+
|
17
|
+
MODULES = [Xot, Rucy, Rays, Reflex, Processing]
|
18
|
+
|
19
|
+
ENV['RDOC'] = 'yardoc --no-private'
|
20
|
+
|
21
|
+
test_ruby_extension
|
22
|
+
generate_documents
|
23
|
+
build_ruby_gem
|
24
|
+
|
25
|
+
task :default
|
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
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
|
3
|
+
|
4
|
+
Pod::Spec.new do |s|
|
5
|
+
s.name = "RubyProcessing"
|
6
|
+
s.version = File.readlines(File.expand_path 'VERSION', __dir__)[0].chomp
|
7
|
+
s.summary = "Yet Another Processing implementation for Ruby"
|
8
|
+
s.description = "Yet Another Processing implementation for Ruby"
|
9
|
+
s.license = "MIT"
|
10
|
+
s.source = {:git => "https://github.com/xord/processing.git"}
|
11
|
+
s.author = {"xordog" => "xordog@gmail.com"}
|
12
|
+
s.homepage = "https://github.com/xord/processing"
|
13
|
+
|
14
|
+
s.osx.deployment_target = "10.10"
|
15
|
+
s.ios.deployment_target = "10.0"
|
16
|
+
|
17
|
+
incdirs = %W[
|
18
|
+
#{s.name}/src
|
19
|
+
CRuby/CRuby/include
|
20
|
+
Reflexion/reflex/include
|
21
|
+
].map {|s| "${PODS_ROOT}/#{s}"}
|
22
|
+
|
23
|
+
s.preserve_paths = "src"
|
24
|
+
s.source_files = "src/*.mm"
|
25
|
+
s.xcconfig = {"HEADER_SEARCH_PATHS" => incdirs.join(' ')}
|
26
|
+
|
27
|
+
s.resource_bundles = {'RubyProcessing' => %w[lib VERSION]}
|
28
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
@@ -0,0 +1,212 @@
|
|
1
|
+
%w[xot rays reflex processing]
|
2
|
+
.map {|s| File.expand_path "../../#{s}/lib", __dir__}
|
3
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
4
|
+
|
5
|
+
require 'processing/include'
|
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 processing]
|
2
|
+
.map {|s| File.expand_path "../../#{s}/lib", __dir__}
|
3
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
4
|
+
|
5
|
+
require 'processing/include'
|
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
|
data/examples/clock.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
%w[xot rays reflex processing]
|
2
|
+
.map {|s| File.expand_path "../../#{s}/lib", __dir__}
|
3
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
4
|
+
|
5
|
+
require 'processing/include'
|
6
|
+
|
7
|
+
COLORS = %w[ #F99292 #FFBC61 #FFC679 #FFF4E0 ]
|
8
|
+
|
9
|
+
def now ()
|
10
|
+
Time.now.to_f
|
11
|
+
end
|
12
|
+
|
13
|
+
start = now
|
14
|
+
|
15
|
+
setup do
|
16
|
+
colorMode RGB, 1
|
17
|
+
angleMode DEGREES
|
18
|
+
end
|
19
|
+
|
20
|
+
draw do
|
21
|
+
background 0
|
22
|
+
|
23
|
+
pushMatrix do
|
24
|
+
translate width / 2, height / 2
|
25
|
+
|
26
|
+
pushMatrix do
|
27
|
+
fill COLORS[0]
|
28
|
+
ellipse 0, 0, 20, 20
|
29
|
+
rotate (now - start) / 60.0 * 360
|
30
|
+
stroke COLORS[0]
|
31
|
+
strokeWeight 5
|
32
|
+
line 0, 0, 200, 0
|
33
|
+
fill 1
|
34
|
+
end
|
35
|
+
|
36
|
+
pushMatrix do
|
37
|
+
strokeWeight 3
|
38
|
+
60.times do
|
39
|
+
rotate 6
|
40
|
+
stroke COLORS[1]
|
41
|
+
line 200, 0, 210, 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
pushMatrix do
|
46
|
+
strokeWeight 5
|
47
|
+
12.times do
|
48
|
+
rotate 30
|
49
|
+
stroke COLORS[3]
|
50
|
+
line 190, 0, 210, 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
textSize 20
|
56
|
+
text "#{frameRate.to_i} FPS", 10, 10
|
57
|
+
end
|