processing.rb 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +155 -0
- data/LICENSE +21 -0
- data/README.ja.md +199 -0
- data/README.md +199 -0
- data/bin/setup_processingrb_examples +9 -0
- data/examples/01_simple_sketch.rb +32 -0
- data/examples/02_input_handling.rb +49 -0
- data/examples/03_multi_file.rb +44 -0
- data/examples/04_builtin_library.rb +48 -0
- data/examples/05_external_library.rb +89 -0
- data/examples/data/cat.mov +0 -0
- data/examples/data/dog.mov +0 -0
- data/examples/libraries/handy/library.properties +43 -0
- data/examples/libraries/handy/library/handy.jar +0 -0
- data/examples/modules/moving_box.rb +23 -0
- data/examples/modules/textured_cube.rb +47 -0
- data/examples/screenshots/01_simple_sketch.png +0 -0
- data/examples/screenshots/02_input_handling.png +0 -0
- data/examples/screenshots/03_multi_file.png +0 -0
- data/examples/screenshots/04_builtin_library.png +0 -0
- data/examples/screenshots/05_external_library.png +0 -0
- data/lib/processing.rb +8 -0
- data/lib/processing/sketch_base.rb +54 -0
- data/lib/processing/system.rb +57 -0
- data/lib/sketch_runner/config.rb +64 -0
- data/lib/sketch_runner/launch.rb +11 -0
- data/lib/sketch_runner/runner.rb +108 -0
- data/lib/sketch_runner/setup.rb +85 -0
- data/processing.rb.gemspec +19 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eba7a6fbc01e93d9749d39744cc09d7f864e2270
|
4
|
+
data.tar.gz: 0ff3bd1f4773ccf00c865b5842ef63a9b2d69c9e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47536f2d1cefad288b1970789fb962815621cf5594c622288c0c6cbd8ba40aa558f103d5f66bc34e16efe5dd4036b1526c725a6475e3daa02e4c875bc542fd29
|
7
|
+
data.tar.gz: 8e46387b9f2e219270ebda9e618615cfb287340a185c9a52b23f27e92c23e651e241175ad7c9827742bfed0fc80e5a0252dbfd633127211ea02102b12c3f2175
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 1.1.1
|
4
|
+
- Renamed a constant name
|
5
|
+
- Modified a error message
|
6
|
+
- Updated comments in code
|
7
|
+
|
8
|
+
## 1.1.0
|
9
|
+
- Splited the source code into multiple files
|
10
|
+
- Changed to download Processing automatically
|
11
|
+
- Changed to start automatically when the module is required
|
12
|
+
- Renamed complete_path to sketch_path
|
13
|
+
- Added the utility script to copy the examples
|
14
|
+
- Adapted to both 32-bit and 64-bit architecture
|
15
|
+
- Changed to show an error message for downloading files
|
16
|
+
- Updated the READMEs
|
17
|
+
|
18
|
+
## 1.0.0
|
19
|
+
- Stable release
|
20
|
+
- Modified the out messages
|
21
|
+
|
22
|
+
## 0.9.9
|
23
|
+
- Fixed a bug with downloading JRuby without proxy
|
24
|
+
- Modified the out messages
|
25
|
+
|
26
|
+
## 0.9.8
|
27
|
+
- Updated the READMEs
|
28
|
+
- Modified the .rubocop.yml file
|
29
|
+
- Fixed a bug with downloading JRuby via proxy
|
30
|
+
|
31
|
+
## 0.9.7
|
32
|
+
- Changed the way to check the downloaded data
|
33
|
+
- Modified the ouput messages
|
34
|
+
- Updated the READMEs
|
35
|
+
|
36
|
+
## 0.9.6
|
37
|
+
- Renamed the command name to processing-rb
|
38
|
+
- Modified the output messages
|
39
|
+
- Updated the READMEs
|
40
|
+
|
41
|
+
## 0.9.5
|
42
|
+
- Updated the READMEs
|
43
|
+
- Changed the directories to search for Processing
|
44
|
+
|
45
|
+
## 0.9.4
|
46
|
+
- Enabled to execute from Ruby
|
47
|
+
- Changed to download JRuby automatically
|
48
|
+
- Changed the way to find Processing on Windows
|
49
|
+
|
50
|
+
## 0.9.3
|
51
|
+
- Refactored a variable name
|
52
|
+
- Renamed sketch_path to complete_path
|
53
|
+
|
54
|
+
## 0.9.2
|
55
|
+
- Updated the license text
|
56
|
+
- Fixed the SketchBase#frame_rate method
|
57
|
+
|
58
|
+
## 0.9.1
|
59
|
+
- Changed the link to download in README
|
60
|
+
- Renamed examples/assets to examples/data
|
61
|
+
- Refined the READMEs
|
62
|
+
- Removed unnecessary comments
|
63
|
+
|
64
|
+
## 0.9.0
|
65
|
+
- Added README in Japanese
|
66
|
+
- Resized the screenshots of the examples
|
67
|
+
- Updated README in English
|
68
|
+
- Refined comments
|
69
|
+
|
70
|
+
## 0.8.0
|
71
|
+
- Updated the example #5
|
72
|
+
- Refined the example #3
|
73
|
+
- Added screenshots of the examples
|
74
|
+
|
75
|
+
## 0.7.0
|
76
|
+
- Changed to run with JRuby explicitly
|
77
|
+
- Modified the example #3
|
78
|
+
- Updated the examples #4
|
79
|
+
- Refined comments in the examples
|
80
|
+
|
81
|
+
## 0.6.0
|
82
|
+
- Added an argument to the import_package method
|
83
|
+
- Included the Handy library for the example #5
|
84
|
+
- Added the sketch_path method
|
85
|
+
- Added movie materials for the example #4
|
86
|
+
|
87
|
+
## 0.5.0
|
88
|
+
- Changed the directory structure of the examples
|
89
|
+
- Renamed load_all_jars to load_jars
|
90
|
+
- Renamed import_all_classes to import_package
|
91
|
+
- Updated the example #3
|
92
|
+
- Fixed the way to set the initial window status
|
93
|
+
|
94
|
+
## 0.4.0
|
95
|
+
- Refactored the example #1
|
96
|
+
- Implemented the example #2
|
97
|
+
- Renamed load_jar_files to loar_all_jars
|
98
|
+
- Added the import_all_classes method
|
99
|
+
|
100
|
+
## 0.3.0
|
101
|
+
- Simplified the example #1
|
102
|
+
- Changed to include all of the Processing classes in the module
|
103
|
+
- Enabled to call a class methods as an instance method
|
104
|
+
|
105
|
+
## 0.2.0
|
106
|
+
- Changed the example #1
|
107
|
+
- Added the .rubocop.yml file
|
108
|
+
- Renamed start_sketch to start
|
109
|
+
- Added options to the start method
|
110
|
+
|
111
|
+
## 0.1.1
|
112
|
+
- Refactored the code
|
113
|
+
- Added a library search path for Linux
|
114
|
+
- Started implementing the example #1
|
115
|
+
|
116
|
+
## 0.1.0
|
117
|
+
- Changed the way to undefine the Sketch class
|
118
|
+
- Fixed the frame_rate method
|
119
|
+
- Refactored the way to restore the environment
|
120
|
+
- Changed to wrap the whole code in the Processing module
|
121
|
+
- Added the descriptions to all of the methods
|
122
|
+
|
123
|
+
## 0.0.7
|
124
|
+
- Refactored the way to adapt to the virtual methods
|
125
|
+
- Refactored the way to execute and watch the sketch
|
126
|
+
- Wrote the README.md a little
|
127
|
+
|
128
|
+
## 0.0.6
|
129
|
+
- Wrapped the overloaded fields
|
130
|
+
- Fixed to adapt to the virtual methods in Processing
|
131
|
+
|
132
|
+
## 0.0.5
|
133
|
+
- Added PROCESSING_ROOT check for libraries
|
134
|
+
- Added a requirement to the gemspec file
|
135
|
+
- Changed to call jruby when called from ruby
|
136
|
+
- Fixed to the library load paths in Windows
|
137
|
+
|
138
|
+
## 0.0.4
|
139
|
+
- Renamed a constant variable
|
140
|
+
- Added a shebang to the main script
|
141
|
+
- Changed to use JRuby directly instead of Ruby
|
142
|
+
- Changed the way to find Processing libraries
|
143
|
+
- Added error messages
|
144
|
+
|
145
|
+
## 0.0.3
|
146
|
+
- Fixed to set __FILE__ in the sketch
|
147
|
+
- Removed an unnecessary extension in .gitignore
|
148
|
+
|
149
|
+
## 0.0.2
|
150
|
+
- Added a command existence check
|
151
|
+
- Adapted the load path to the directory of the sketch
|
152
|
+
- Fixed to catch all of the errors in the sketch
|
153
|
+
|
154
|
+
## 0.0.1
|
155
|
+
- Initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Takashi Kitao
|
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.ja.md
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
# Processing.rb
|
2
|
+
|
3
|
+
[ [English](https://github.com/kitao/processing.rb/blob/master/README.md) | [Japanese](https://github.com/kitao/processing.rb/blob/master/README.ja.md) ]
|
4
|
+
|
5
|
+
Processing.rbはRubyで気軽にProcessingのスケッチを作成できるツールです。
|
6
|
+
|
7
|
+
## 特長
|
8
|
+
|
9
|
+
他の類似ツールと比べて、Processing.rbには次のような特長があります。
|
10
|
+
|
11
|
+
- 設定ファイル不要で、Rubyのコードにモジュールを1つ追加するだけで使えます。
|
12
|
+
- スケッチ更新時に自動で再起動し、requireしたモジュールも再ロードします。
|
13
|
+
- 本家のProcessing同様、1〜2行のコード追加で簡単に拡張ライブラリが使えます。
|
14
|
+
- ウィンドウ位置の指定や最前面表示など、ライブコーディングに便利な機能があります。
|
15
|
+
|
16
|
+
## 動作画面
|
17
|
+
|
18
|
+
サンプルの動作画面です。画像をクリックすると実際のコードが確認できます。
|
19
|
+
|
20
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/01_simple_sketch.rb" target="_blank">
|
21
|
+
<img
|
22
|
+
src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/01_simple_sketch.png" width="30%">
|
23
|
+
</a>
|
24
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/02_input_handling.rb" target="_blank">
|
25
|
+
<img
|
26
|
+
src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/02_input_handling.png" width="30%">
|
27
|
+
</a>
|
28
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/03_multi_file.rb" target="_blank">
|
29
|
+
<img src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/03_multi_file.png" width="30%">
|
30
|
+
</a>
|
31
|
+
|
32
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/04_builtin_library.rb" target="_blank">
|
33
|
+
<img src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/04_builtin_library.png" width="30%">
|
34
|
+
</a>
|
35
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/05_external_library.rb" target="_blank">
|
36
|
+
<img src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/05_external_library.png" width="30%">
|
37
|
+
</a>
|
38
|
+
|
39
|
+
## インストール方法
|
40
|
+
|
41
|
+
### 事前準備
|
42
|
+
|
43
|
+
Processing.rbを使うには、RubyとJavaのインストールが必要です。各ツールは以下のサイトから入手できます。
|
44
|
+
|
45
|
+
- [Ruby](https://www.ruby-lang.org/)
|
46
|
+
- [Java](https://java.com/)
|
47
|
+
|
48
|
+
### Processing.rbのインストール
|
49
|
+
|
50
|
+
Processing.rbはRubyの`gem`コマンドからインストールできます。
|
51
|
+
|
52
|
+
```sh
|
53
|
+
ruby gem install processing.rb
|
54
|
+
```
|
55
|
+
|
56
|
+
インストール時にpermissionエラーが出た場合は、`sudo`コマンドを先頭に追加してください。
|
57
|
+
|
58
|
+
また、オフィスなどのプロキシ環境でインストールする場合は、上記コマンドの後ろに、`-p http://proxy.hostname:port`のように[-p オプション](http://guides.rubygems.org/command-reference/#gem-install)でプロキシ設定を追加してください。
|
59
|
+
|
60
|
+
インストール完了後、次のコマンドを実行すると、Processing.rbのサンプルが`~/processingrb_examples`ディレクトリにコピーされます。
|
61
|
+
|
62
|
+
```sh
|
63
|
+
setup_processingrb_examples
|
64
|
+
```
|
65
|
+
|
66
|
+
## 使い方
|
67
|
+
|
68
|
+
### スケッチを作成する
|
69
|
+
|
70
|
+
Processing.rbでは、`Processing::SketchBase`クラスの派生クラスとしてスケッチを作成し、`Processing.#start`関数で描画を開始します。
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
require 'processing'
|
74
|
+
|
75
|
+
class Sketch < Processing::SketchBase
|
76
|
+
def setup
|
77
|
+
# implement your own setup code
|
78
|
+
end
|
79
|
+
|
80
|
+
def draw
|
81
|
+
# implement your own draw code
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Processing.start(Sketch.new)
|
86
|
+
```
|
87
|
+
|
88
|
+
`Processing::SketchBase`クラスでは、`HALF_PI`などの定数はJava版のProcessingと同様に使用できます。また、関数や変数は、`noStroke`であれば`no_stroke`のように、Java版の命令を小文字([スネークケース](http://en.wikipedia.org/wiki/Snake_case))にしたものが使用できます。
|
89
|
+
|
90
|
+
実際のスケッチの作成例は[サンプル](https://github.com/kitao/processing.rb/tree/master/examples)をご覧ください。
|
91
|
+
|
92
|
+
作成したスケッチファイルは通常のRubyコードと同じ方法で起動できます。
|
93
|
+
|
94
|
+
```sh
|
95
|
+
ruby [sketchfile]
|
96
|
+
```
|
97
|
+
|
98
|
+
なお、初回起動時のみ、`~/.processing.rb`ディレクトリにJRubyとProcessingのダウンロードが行われます。その際、ダウンロードのためのプロキシ設定を聞かれるので、必要な場合は入力を、不必要な場合は何も入力せずEnterを押してしばらくお待ちください。
|
99
|
+
|
100
|
+
起動後は、同じディレクトリ以下にある`.rb`ファイルが更新されるたびに、スケッチファイルが自動で再読み込みされます。
|
101
|
+
|
102
|
+
### 入力情報を取得する
|
103
|
+
|
104
|
+
キーボードやマウスの入力情報は、Java版のProcessingと同様の方法で取得できます。
|
105
|
+
|
106
|
+
ただし、Java版の`keyPressed`、`mousePressed`変数は、メソッド名の重複を避けるため、それぞれ`key_pressed?`、`mouse_pressed?`という名前に変更されているのでご注意ください。
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
def draw
|
110
|
+
if mouse_pressed?
|
111
|
+
ellipse(mouse_x, mouse_y, 10, 10)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def key_pressed
|
116
|
+
Processing.reload if key == 'r'
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
この例では、マウスボタンが押されると円を描き、キーボードの`R`が押されるとスケッチを再起動します。
|
121
|
+
|
122
|
+
### 拡張ライブラリを使用する
|
123
|
+
|
124
|
+
Processing向けの拡張ライブラリは、Processing.rbでもそのまま使用できます。
|
125
|
+
|
126
|
+
例えば、次のようなVideoライブラリを使用するコードの場合、
|
127
|
+
|
128
|
+
```java
|
129
|
+
import processing.video.*;
|
130
|
+
Movie movie;
|
131
|
+
|
132
|
+
void setup() {
|
133
|
+
movie = new Movie(this, "sample.mov");
|
134
|
+
movie.loop();
|
135
|
+
}
|
136
|
+
```
|
137
|
+
|
138
|
+
Processing.rbでは以下のようになります。
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
Processing.load_library 'video'
|
142
|
+
Processing.import_package 'processing.video', 'Video'
|
143
|
+
|
144
|
+
class Sketch < Processing::SketchBase
|
145
|
+
def setup
|
146
|
+
@movie = Video::Movie.new(self, Processing.sketch_path('sample.mov'))
|
147
|
+
@movie.loop
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
Javaのライブラリへのファイルの指定は、絶対パスで行う必要があるため、この例では`Processing.#sketch_path`関数を使用して、スケッチファイルからの相対パスを絶対パスに変換しています。
|
152
|
+
|
153
|
+
Processingに標準で付属しない拡張ライブラリを使用する場合は、スケッチファイルと同じディレクトリに`libraries`ディレクトリを作成して、そこに使用するライブラリを置いてください。
|
154
|
+
|
155
|
+
### ライブコーディングする
|
156
|
+
|
157
|
+
`Processing.#start`関数にオプションを指定すると、エディタとスケッチのウィンドウを同時に見やすく表示できます。結果を確認しながらコード編集を行う際に便利です。
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
Processing.start(Sketch.new, topmost: true, pos: [300, 300])
|
161
|
+
```
|
162
|
+
|
163
|
+
`Processing.#start`関数に指定できるオプションは以下のとおりです。
|
164
|
+
|
165
|
+
|オプション|説明|
|
166
|
+
|----|----|
|
167
|
+
|topmost:|`true`にするとウィンドウを常に最前面に表示する|
|
168
|
+
|pos:|`[x, y]`で指定した座標にウィンドウを表示する|
|
169
|
+
|
170
|
+
## APIリファレンス
|
171
|
+
|
172
|
+
### Processingモジュール
|
173
|
+
|
174
|
+
`Processing`モジュールはスケッチのためのクラスやメソッドを提供します。
|
175
|
+
|
176
|
+
|定数|説明|
|
177
|
+
|----|----|
|
178
|
+
|SKETCH_FILE|起動時に指定されたスケッチファイルの絶対パス|
|
179
|
+
|SKETCH_NAME|ディレクトリ名を除いたスケッチファイル名|
|
180
|
+
|SKETCH_DIR|スケッチファイルの絶対パスでのディレクトリ名|
|
181
|
+
|
182
|
+
|クラス|説明|
|
183
|
+
|----|----|
|
184
|
+
|SketchBase|スケッチの基底クラス|
|
185
|
+
|
186
|
+
|特異メソッド|説明|
|
187
|
+
|----|----|
|
188
|
+
|load_library(name)|指定した拡張ライブラリを読み込む|
|
189
|
+
|load_jars(dir)|指定したディレクトリのすべての`.jar`ファイルを読み込む|
|
190
|
+
|import_package(package, module_name)|`module_name`モジュールに、指定したJavaパッケージのすべてのクラスを登録する|
|
191
|
+
|sketch_path(path)|スケッチファイルからの相対パスを絶対パスに変換する|
|
192
|
+
|start(sketch, topmost: false, pos: nil)|指定したスケッチインスタンスの描画を開始する|
|
193
|
+
|reload|スケッチファイルを読み込み直し、再起動する|
|
194
|
+
|
195
|
+
## ライセンス
|
196
|
+
|
197
|
+
Processing.rbは[MITライセンス](http://en.wikipedia.org/wiki/MIT_License)です。無料で自由にご利用ください。
|
198
|
+
|
199
|
+
Have fun!
|
data/README.md
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
# Processing.rb
|
2
|
+
|
3
|
+
[ [English](https://github.com/kitao/processing.rb/blob/master/README.md) | [Japanese](https://github.com/kitao/processing.rb/blob/master/README.ja.md) ]
|
4
|
+
|
5
|
+
Processing.rb enables you to write various Processing sketches in Ruby easily.
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
Compared to similar tools, Processing.rb has the following features:
|
10
|
+
|
11
|
+
- Requires no configuration file and available with just adding a module to your Ruby code
|
12
|
+
- Reloads the sketch file and loaded modules automatically when the related files are updated
|
13
|
+
- Available to use extension libraries for Processing with just adding a few line code in the same way as Processing
|
14
|
+
- Provides useful functions for live coding, such as setting the window position and showing it in the topmost
|
15
|
+
|
16
|
+
## Screenshots
|
17
|
+
|
18
|
+
The following are screenshots of the examples of Processing.rb. Click each image to view the source code.
|
19
|
+
|
20
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/01_simple_sketch.rb" target="_blank">
|
21
|
+
<img
|
22
|
+
src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/01_simple_sketch.png" width="30%">
|
23
|
+
</a>
|
24
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/02_input_handling.rb" target="_blank">
|
25
|
+
<img
|
26
|
+
src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/02_input_handling.png" width="30%">
|
27
|
+
</a>
|
28
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/03_multi_file.rb" target="_blank">
|
29
|
+
<img src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/03_multi_file.png" width="30%">
|
30
|
+
</a>
|
31
|
+
|
32
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/04_builtin_library.rb" target="_blank">
|
33
|
+
<img src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/04_builtin_library.png" width="30%">
|
34
|
+
</a>
|
35
|
+
<a href="https://github.com/kitao/processing.rb/blob/master/examples/05_external_library.rb" target="_blank">
|
36
|
+
<img src="https://raw.githubusercontent.com/kitao/processing.rb/master/examples/screenshots/05_external_library.png" width="30%">
|
37
|
+
</a>
|
38
|
+
|
39
|
+
## How to Install
|
40
|
+
|
41
|
+
### Preparations
|
42
|
+
|
43
|
+
In order to use Processing.rb, installation of Ruby and Java is required. Each tool can be obtained from the following sites:
|
44
|
+
|
45
|
+
- [Ruby](https://www.ruby-lang.org/)
|
46
|
+
- [Java](https://java.com/)
|
47
|
+
|
48
|
+
### Installing Processing.rb
|
49
|
+
|
50
|
+
Processing.rb can be installed with the `gem` command of Ruby.
|
51
|
+
|
52
|
+
```sh
|
53
|
+
gem install processing.rb
|
54
|
+
```
|
55
|
+
|
56
|
+
If a permission error occured while installation, please add the `sudo` command at the head of the above command.
|
57
|
+
|
58
|
+
In a proxy environment such as in an office, please add a proxy configuration as [-p option](http://guides.rubygems.org/command-reference/#gem-install) at the end of the above command, such as `-p http://proxy.hostname:port`.
|
59
|
+
|
60
|
+
After installation, the examples of Processing.rb can be copied to the `~/processingrb_examples` directory with the following command:
|
61
|
+
|
62
|
+
```sh
|
63
|
+
setup_processingrb_examples
|
64
|
+
```
|
65
|
+
|
66
|
+
## How to Use
|
67
|
+
|
68
|
+
### Creating a sketch
|
69
|
+
|
70
|
+
In Processing.rb, a sketch is created as a derived class from the `Processing::SketchBase` class. And it starts rendering by calling the `Processing.#start` function.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
require 'processing'
|
74
|
+
|
75
|
+
class Sketch < Processing::SketchBase
|
76
|
+
def setup
|
77
|
+
# implement your own setup code
|
78
|
+
end
|
79
|
+
|
80
|
+
def draw
|
81
|
+
# implement your own draw code
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Processing.start(Sketch.new)
|
86
|
+
```
|
87
|
+
|
88
|
+
In the `Processing::SketchBase` class, the constants of Processing in Java such as `HALF_PI` can be used as the same name. Regarding the functions and variables of Processing, their names are [snake-cased](http://en.wikipedia.org/wiki/Snake_case). For example, `no_stroke` in the case of `noStroke` in Java.
|
89
|
+
|
90
|
+
Please check the actual code in [the examples](https://github.com/kitao/processing.rb/tree/master/examples).
|
91
|
+
|
92
|
+
A sketch file can be run in the same way as a usual Ruby code.
|
93
|
+
|
94
|
+
```sh
|
95
|
+
ruby [sketchfile]
|
96
|
+
```
|
97
|
+
|
98
|
+
Only for the first time, JRuby and Processing will be downloaded to the `~/.processing.rb` directory. The proxy setting to download will be asked at that moment. Please input it or just press `Enter` without any input if not necessary, and wait for a while.
|
99
|
+
|
100
|
+
While the sketch file is running, it will be reloaded automatically when the `.rb` files in the same directory are updated.
|
101
|
+
|
102
|
+
### Handling input data
|
103
|
+
|
104
|
+
The information of the keyboard and mouse can be obtained in the same way as Processing in Java.
|
105
|
+
|
106
|
+
But please note that the `keyPressed` and `mousePressed` methods in Java are renamed to `key_pressed?` and `mouse_pressed?` to avoid duplication of the method names.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
def draw
|
110
|
+
if mouse_pressed?
|
111
|
+
ellipse(mouse_x, mouse_y, 10, 10)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def key_pressed
|
116
|
+
Processing.reload if key == 'r'
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
This example draws circles when the mouse button is pressed, and restarts the sketch when the `R` key is pressed.
|
121
|
+
|
122
|
+
### Using an extension library
|
123
|
+
|
124
|
+
An extension library for Processing can be used in Processing.rb in the same way as Processing in Java.
|
125
|
+
|
126
|
+
For example, in the case of the sketch uses the video extension library like this:
|
127
|
+
|
128
|
+
```java
|
129
|
+
import processing.video.*;
|
130
|
+
Movie movie;
|
131
|
+
|
132
|
+
void setup() {
|
133
|
+
movie = new Movie(this, "sample.mov");
|
134
|
+
movie.loop();
|
135
|
+
}
|
136
|
+
```
|
137
|
+
|
138
|
+
In Processing.rb, it goes as follow:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
Processing.load_library 'video'
|
142
|
+
Processing.import_package 'processing.video', 'Video'
|
143
|
+
|
144
|
+
class Sketch < Processing::SketchBase
|
145
|
+
def setup
|
146
|
+
@movie = Video::Movie.new(self, Processing.sketch_path('sample.mov'))
|
147
|
+
@movie.loop
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
When a file path for a Java library is specified in Processing.rb, it should be an absolute path. So this example uses the `Processing.#sketch_path` function to convert the relative path from the sketch directory to the absolute path.
|
152
|
+
|
153
|
+
In the case of using an extension library not bundled in Processing, please make the `libraries` directory in the same directory as the sketch file and place the library in it.
|
154
|
+
|
155
|
+
### Live coding
|
156
|
+
|
157
|
+
With passing optional parameters to the `Processing.#start` function, the both an editor screen and a sketch window can get more visible. It helps with editing code in parallel with checking its rendering result.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
Processing.start(Sketch.new, topmost: true, pos: [300, 300])
|
161
|
+
```
|
162
|
+
|
163
|
+
The options of the `Processing.#start` function are as follows:
|
164
|
+
|
165
|
+
|Option|Description|
|
166
|
+
|----|----|
|
167
|
+
|topmost:|When its value is `true`, the sketch window always appears in the topmost.|
|
168
|
+
|pos:|The sketch window appears in the position `[x, y]`.|
|
169
|
+
|
170
|
+
## API Reference
|
171
|
+
|
172
|
+
### Processing module
|
173
|
+
|
174
|
+
The `Processing` module provides the classes and methods for a Processing sketch.
|
175
|
+
|
176
|
+
|Constant|Description|
|
177
|
+
|----|----|
|
178
|
+
|SKETCH_FILE|The path of the sketch file in the absolute path|
|
179
|
+
|SKETCH_NAME|The name of the sketch file without the directory|
|
180
|
+
|SKETCH_DIR|The directory of the sketch file in the absolute path|
|
181
|
+
|
182
|
+
|Class|Description|
|
183
|
+
|----|----|
|
184
|
+
|SketchBase|The base class of a Processing sketch|
|
185
|
+
|
186
|
+
|Method|Description|
|
187
|
+
|----|----|
|
188
|
+
|load_library(name)|Loads the specified Processing library|
|
189
|
+
|load_jars(dir)|Loads all of the `.jar` files in the specified directory|
|
190
|
+
|import_package(package, module_name)|Imports all of the classes in the specified Java package to the specified module|
|
191
|
+
|sketch_path(path)|Converts the relative path from the sketch directory to the absolute path|
|
192
|
+
|start(sketch, topmost: false, pos: nil)|Starts to render the specified sketch instance|
|
193
|
+
|reload|Reloads the sketch file manually|
|
194
|
+
|
195
|
+
## License
|
196
|
+
|
197
|
+
Processing.rb is under [MIT license](http://en.wikipedia.org/wiki/MIT_License). Feel free to use it.
|
198
|
+
|
199
|
+
Have fun!
|