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
@@ -0,0 +1,57 @@
|
|
1
|
+
# Provides the classes and methods for a Processing sketch
|
2
|
+
module Processing
|
3
|
+
def self.load_library(name)
|
4
|
+
if load_jars(File.join(SketchRunner::SKETCH_LIBS_DIR, name, 'library')) ||
|
5
|
+
load_jars(File.join(SketchRunner::PROCESSING_DIR, name, 'library'))
|
6
|
+
else
|
7
|
+
fail "library not found -- #{name}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.load_jars(dir)
|
12
|
+
is_success = false
|
13
|
+
|
14
|
+
if File.directory?(dir)
|
15
|
+
Dir.glob(File.join(dir, '*.jar')).each do |jar|
|
16
|
+
require jar
|
17
|
+
is_success = true
|
18
|
+
puts "jar file loaded -- #{File.basename(jar)}"
|
19
|
+
end
|
20
|
+
|
21
|
+
return true if is_success
|
22
|
+
end
|
23
|
+
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.import_package(package, module_name)
|
28
|
+
code = "module #{module_name}; include_package '#{package}'; end"
|
29
|
+
Object::TOPLEVEL_BINDING.eval(code)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.sketch_path(path)
|
33
|
+
File.join(SketchRunner::SKETCH_DIR, path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.start(sketch, opts = {})
|
37
|
+
title = opts[:title] || SketchRunner::SKETCH_NAME
|
38
|
+
topmost = opts[:topmost]
|
39
|
+
pos = opts[:pos]
|
40
|
+
|
41
|
+
PApplet.run_sketch([title], sketch)
|
42
|
+
|
43
|
+
if topmost
|
44
|
+
request = { command: :topmost, sketch: sketch }
|
45
|
+
SketchRunner.system_requests << request
|
46
|
+
end
|
47
|
+
|
48
|
+
if pos
|
49
|
+
request = { command: :pos, sketch: sketch, pos: pos }
|
50
|
+
SketchRunner.system_requests << request
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.reload
|
55
|
+
SketchRunner.system_requests << { command: :reload }
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Runs a sketch and reloads it when related files change
|
2
|
+
module SketchRunner
|
3
|
+
VERSION = '1.1.1'
|
4
|
+
|
5
|
+
CONFIG_MTIME = File.stat(__FILE__).mtime
|
6
|
+
|
7
|
+
PACKAGE_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
|
8
|
+
|
9
|
+
APPDATA_ROOT = File.expand_path('~/.processing.rb')
|
10
|
+
APPDATA_CHECK_FILE = File.join(APPDATA_ROOT, '.complete')
|
11
|
+
|
12
|
+
JRUBY_URL = 'https://s3.amazonaws.com/jruby.org/downloads/9.0.0.0.pre1/jruby-complete-9.0.0.0.pre1.jar'
|
13
|
+
JRUBY_FILE = File.join(APPDATA_ROOT, 'jruby/jruby.jar')
|
14
|
+
|
15
|
+
if RUBY_PLATFORM == 'java'
|
16
|
+
BIT_SIZE = java.lang.System.getProperty('sun.arch.data.model') == '64' ?
|
17
|
+
64 : 32
|
18
|
+
else
|
19
|
+
require 'open3'
|
20
|
+
BIT_SIZE = Open3.capture3('java -version')[1].include?('64-Bit') ? 64 : 32
|
21
|
+
end
|
22
|
+
|
23
|
+
if RUBY_PLATFORM == 'java'
|
24
|
+
PLATFORM = :JAVA
|
25
|
+
elsif /darwin/ =~ RUBY_PLATFORM
|
26
|
+
PLATFORM = :MACOSX
|
27
|
+
elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
|
28
|
+
PLATFORM = BIT_SIZE == 32 ? :WIN32 : :WIN64
|
29
|
+
else
|
30
|
+
PLATFORM = BIT_SIZE == 32 ? :LINUX32 : :LINUX64
|
31
|
+
end
|
32
|
+
|
33
|
+
PROCESSING_URL = {
|
34
|
+
MACOSX: 'http://download.processing.org/processing-2.2.1-macosx.zip',
|
35
|
+
WIN32: 'http://download.processing.org/processing-2.2.1-windows32.zip',
|
36
|
+
WIN64: 'http://download.processing.org/processing-2.2.1-windows64.zip',
|
37
|
+
LINUX32: 'http://download.processing.org/processing-2.2.1-linux32.tgz',
|
38
|
+
LINUX64: 'http://download.processing.org/processing-2.2.1-linux64.tgz'
|
39
|
+
}[PLATFORM]
|
40
|
+
|
41
|
+
if PLATFORM == :MACOSX
|
42
|
+
PROCESSING_CORE_PATH = 'Processing.app/Contents/Java/core'
|
43
|
+
PROCESSING_LIBS_PATH = 'Processing.app/Contents/Java/modes/java/libraries'
|
44
|
+
else
|
45
|
+
PROCESSING_CORE_PATH = 'processing-2.2.1/core'
|
46
|
+
PROCESSING_LIBS_PATH = 'processing-2.2.1/modes/java/libraries'
|
47
|
+
end
|
48
|
+
|
49
|
+
PROCESSING_DIR = File.join(APPDATA_ROOT, 'processing')
|
50
|
+
PROCESSING_ZIP_DIR = File.join(APPDATA_ROOT, 'processing-zip')
|
51
|
+
PROCESSING_ZIP_FILE = File.join(PROCESSING_ZIP_DIR, 'processing.zip')
|
52
|
+
|
53
|
+
EXAMPLES_SRC_DIR = File.join(PACKAGE_ROOT, 'examples')
|
54
|
+
EXAMPLES_DEST_DIR = File.expand_path('~/processingrb_examples')
|
55
|
+
|
56
|
+
LOAD_PATH = File.join(PACKAGE_ROOT, 'lib')
|
57
|
+
STARTUP_FILE = File.join(PACKAGE_ROOT, 'lib/sketch_runner/runner.rb')
|
58
|
+
|
59
|
+
SKETCH_FILE = File.expand_path(ARGV.length > 0 ? ARGV[0] : '')
|
60
|
+
SKETCH_DIR, SKETCH_NAME = File.split(SKETCH_FILE)
|
61
|
+
SKETCH_LIBS_DIR = File.join(SKETCH_DIR, 'libraries')
|
62
|
+
|
63
|
+
WATCH_INTERVAL = 0.1
|
64
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Runs a sketch and reloads it when related files change
|
2
|
+
module SketchRunner
|
3
|
+
def self.launch
|
4
|
+
jruby_opts = "-I#{LOAD_PATH}"
|
5
|
+
jruby_args = "#{STARTUP_FILE} #{$PROGRAM_NAME} #{ARGV.join(' ')}"
|
6
|
+
exec("java -jar #{JRUBY_FILE} #{jruby_opts} #{jruby_args}")
|
7
|
+
end
|
8
|
+
private_class_method :launch
|
9
|
+
|
10
|
+
launch
|
11
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'find'
|
2
|
+
require_relative 'config'
|
3
|
+
|
4
|
+
# Runs a sketch and reloads it when related files change
|
5
|
+
module SketchRunner
|
6
|
+
class << self
|
7
|
+
def system_requests
|
8
|
+
@system_requests ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def sketch_instances
|
12
|
+
@sketch_instances ||= []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.start
|
17
|
+
$PROGRAM_NAME = ARGV.shift
|
18
|
+
|
19
|
+
jars = File.join(PROCESSING_DIR, 'core/library/*.jar')
|
20
|
+
Dir.glob(jars).each { |jar| require jar }
|
21
|
+
|
22
|
+
initial_constants = Object.constants
|
23
|
+
initial_features = $LOADED_FEATURES.dup
|
24
|
+
|
25
|
+
loop do
|
26
|
+
puts '****** START SKETCH ******'
|
27
|
+
|
28
|
+
run_sketch
|
29
|
+
watch_file_changes
|
30
|
+
restore_environment(initial_constants, initial_features)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
private_class_method :start
|
34
|
+
|
35
|
+
def self.run_sketch
|
36
|
+
Thread.new do
|
37
|
+
begin
|
38
|
+
Object::TOPLEVEL_BINDING.eval(File.read(SKETCH_FILE), SKETCH_FILE)
|
39
|
+
rescue Exception => e
|
40
|
+
puts e
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
private_class_method :run_sketch
|
45
|
+
|
46
|
+
def self.watch_file_changes
|
47
|
+
execute_time = Time.now
|
48
|
+
|
49
|
+
catch :break_loop do
|
50
|
+
loop do
|
51
|
+
system_requests.each do |request|
|
52
|
+
system_requests.delete(request) if respond_to_request(request)
|
53
|
+
end
|
54
|
+
|
55
|
+
Find.find(SKETCH_DIR) do |file|
|
56
|
+
is_ruby = FileTest.file?(file) && File.extname(file) == '.rb'
|
57
|
+
throw :break_loop if is_ruby && File.mtime(file) > execute_time
|
58
|
+
end
|
59
|
+
|
60
|
+
sleep(WATCH_INTERVAL)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
private_class_method :watch_file_changes
|
65
|
+
|
66
|
+
def self.respond_to_request(request)
|
67
|
+
case request[:command]
|
68
|
+
when :topmost
|
69
|
+
sketch = request[:sketch]
|
70
|
+
sketch.frame.set_always_on_top(true)
|
71
|
+
|
72
|
+
return sketch.frame.is_always_on_top
|
73
|
+
when :pos
|
74
|
+
sketch = request[:sketch]
|
75
|
+
pos_x, pos_y = request[:pos]
|
76
|
+
sketch.frame.set_location(pos_x, pos_y)
|
77
|
+
|
78
|
+
cur_pos = sketch.frame.get_location
|
79
|
+
return cur_pos.x == pos_x && cur_pos.y == pos_y
|
80
|
+
when :reload
|
81
|
+
throw :break_loop
|
82
|
+
end
|
83
|
+
end
|
84
|
+
private_class_method :respond_to_request
|
85
|
+
|
86
|
+
def self.restore_environment(initial_constants, initial_features)
|
87
|
+
sketch_instances.each do |sketch|
|
88
|
+
sketch.frame.dispose
|
89
|
+
sketch.dispose
|
90
|
+
end
|
91
|
+
|
92
|
+
sketch_instances.clear
|
93
|
+
system_requests.clear
|
94
|
+
|
95
|
+
added_constants = Object.constants - initial_constants
|
96
|
+
added_constants.each do |constant|
|
97
|
+
Object.class_eval { remove_const constant }
|
98
|
+
end
|
99
|
+
|
100
|
+
added_features = $LOADED_FEATURES - initial_features
|
101
|
+
added_features.each { |feature| $LOADED_FEATURES.delete(feature) }
|
102
|
+
|
103
|
+
java.lang.System.gc
|
104
|
+
end
|
105
|
+
private_class_method :restore_environment
|
106
|
+
|
107
|
+
start
|
108
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'open_uri_redirections'
|
3
|
+
require 'openssl'
|
4
|
+
require 'zip'
|
5
|
+
|
6
|
+
# Runs a sketch and reloads it when related files change
|
7
|
+
module SketchRunner
|
8
|
+
def self.setup
|
9
|
+
puts "Processing.rb #{VERSION}"
|
10
|
+
|
11
|
+
return if File.exist?(APPDATA_CHECK_FILE) &&
|
12
|
+
File.stat(APPDATA_CHECK_FILE).mtime > CONFIG_MTIME
|
13
|
+
|
14
|
+
FileUtils.remove_dir(APPDATA_ROOT, true)
|
15
|
+
|
16
|
+
puts 'JRuby and Processing will be downloaded just one time.'
|
17
|
+
puts 'Please input a proxy if necessary, otherwise just press Enter.'
|
18
|
+
print '(e.g. http://proxy.hostname:port): '
|
19
|
+
proxy = $stdin.gets.chomp
|
20
|
+
proxy = nil if proxy == ''
|
21
|
+
|
22
|
+
download(JRUBY_URL, JRUBY_FILE, proxy)
|
23
|
+
|
24
|
+
download(PROCESSING_URL, PROCESSING_ZIP_FILE, proxy)
|
25
|
+
unzip(PROCESSING_ZIP_FILE, PROCESSING_ZIP_DIR)
|
26
|
+
|
27
|
+
FileUtils.mkdir_p(PROCESSING_DIR)
|
28
|
+
processing_core_dir = File.join(PROCESSING_ZIP_DIR, PROCESSING_CORE_PATH)
|
29
|
+
FileUtils.cp_r(processing_core_dir, PROCESSING_DIR)
|
30
|
+
|
31
|
+
processing_libs_dir = File.join(PROCESSING_ZIP_DIR, PROCESSING_LIBS_PATH)
|
32
|
+
Dir.glob(File.join(processing_libs_dir, '*')).each do |dir|
|
33
|
+
FileUtils.cp_r(dir, PROCESSING_DIR)
|
34
|
+
end
|
35
|
+
|
36
|
+
FileUtils.remove_dir(PROCESSING_ZIP_DIR, true)
|
37
|
+
|
38
|
+
FileUtils.touch(APPDATA_CHECK_FILE)
|
39
|
+
end
|
40
|
+
private_class_method :setup
|
41
|
+
|
42
|
+
def self.download(url, file, proxy)
|
43
|
+
print "download #{File.basename(url)} ... "
|
44
|
+
|
45
|
+
FileUtils.mkdir_p(File.dirname(file))
|
46
|
+
|
47
|
+
open(file, 'wb') do |output|
|
48
|
+
begin
|
49
|
+
open(
|
50
|
+
url,
|
51
|
+
proxy: proxy,
|
52
|
+
allow_redirections: :safe,
|
53
|
+
ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
|
54
|
+
) do |data|
|
55
|
+
output.write(data.read)
|
56
|
+
end
|
57
|
+
rescue StandardError
|
58
|
+
puts "\nunable to download file -- #{url}"
|
59
|
+
exit false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
puts 'done'
|
64
|
+
end
|
65
|
+
private_class_method :download
|
66
|
+
|
67
|
+
def self.unzip(file, dest_dir)
|
68
|
+
print "unzip #{File.basename(file)} ... "
|
69
|
+
|
70
|
+
Zip::File.open(file) do |zip|
|
71
|
+
zip.each do |entry|
|
72
|
+
dest_file = File.join(dest_dir, entry.name)
|
73
|
+
|
74
|
+
unless File.basename(dest_file).start_with?('._')
|
75
|
+
entry.extract(dest_file)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
puts 'done'
|
81
|
+
end
|
82
|
+
private_class_method :unzip
|
83
|
+
|
84
|
+
setup
|
85
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'lib/sketch_runner/config'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'processing.rb'
|
5
|
+
spec.version = SketchRunner::VERSION
|
6
|
+
spec.author = 'Takashi Kitao'
|
7
|
+
spec.email = 'takashi.kitao@gmail.com'
|
8
|
+
spec.summary = 'A simple Processing sketch runner for Ruby'
|
9
|
+
spec.description =
|
10
|
+
'Processing.rb runs a Processing sketch written in Ruby, ' \
|
11
|
+
'and reloads it automatically when files in the same directory change.'
|
12
|
+
spec.homepage = 'https://github.com/kitao/processing.rb'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = ['setup_processingrb_examples']
|
16
|
+
spec.requirements = ['java >= 1.8.0_40']
|
17
|
+
spec.add_runtime_dependency 'open_uri_redirections', '~> 0.2.1'
|
18
|
+
spec.add_runtime_dependency 'rubyzip', '~> 1.1.7'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: processing.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi Kitao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: open_uri_redirections
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubyzip
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.7
|
41
|
+
description: Processing.rb runs a Processing sketch written in Ruby, and reloads it
|
42
|
+
automatically when files in the same directory change.
|
43
|
+
email: takashi.kitao@gmail.com
|
44
|
+
executables:
|
45
|
+
- setup_processingrb_examples
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- LICENSE
|
53
|
+
- README.ja.md
|
54
|
+
- README.md
|
55
|
+
- bin/setup_processingrb_examples
|
56
|
+
- examples/01_simple_sketch.rb
|
57
|
+
- examples/02_input_handling.rb
|
58
|
+
- examples/03_multi_file.rb
|
59
|
+
- examples/04_builtin_library.rb
|
60
|
+
- examples/05_external_library.rb
|
61
|
+
- examples/data/cat.mov
|
62
|
+
- examples/data/dog.mov
|
63
|
+
- examples/libraries/handy/library.properties
|
64
|
+
- examples/libraries/handy/library/handy.jar
|
65
|
+
- examples/modules/moving_box.rb
|
66
|
+
- examples/modules/textured_cube.rb
|
67
|
+
- examples/screenshots/01_simple_sketch.png
|
68
|
+
- examples/screenshots/02_input_handling.png
|
69
|
+
- examples/screenshots/03_multi_file.png
|
70
|
+
- examples/screenshots/04_builtin_library.png
|
71
|
+
- examples/screenshots/05_external_library.png
|
72
|
+
- lib/processing.rb
|
73
|
+
- lib/processing/sketch_base.rb
|
74
|
+
- lib/processing/system.rb
|
75
|
+
- lib/sketch_runner/config.rb
|
76
|
+
- lib/sketch_runner/launch.rb
|
77
|
+
- lib/sketch_runner/runner.rb
|
78
|
+
- lib/sketch_runner/setup.rb
|
79
|
+
- processing.rb.gemspec
|
80
|
+
homepage: https://github.com/kitao/processing.rb
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements:
|
99
|
+
- java >= 1.8.0_40
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.0.14
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: A simple Processing sketch runner for Ruby
|
105
|
+
test_files: []
|