ruby-processing 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rpextras.jar +0 -0
- data/lib/ruby-processing.rb +1 -1
- data/lib/ruby-processing/app.rb +4 -18
- data/lib/ruby-processing/exporters/application_exporter.rb +2 -2
- data/lib/ruby-processing/exporters/base_exporter.rb +15 -10
- data/lib/ruby-processing/exporters/creator.rb +92 -35
- data/lib/ruby-processing/helper_methods.rb +102 -8
- data/lib/ruby-processing/helpers/numeric.rb +1 -2
- data/lib/ruby-processing/helpers/string.rb +7 -8
- data/lib/ruby-processing/runner.rb +13 -7
- data/lib/ruby-processing/runners/watch.rb +0 -3
- data/lib/ruby-processing/version.rb +1 -1
- data/lib/templates/create/basic.rb.erb +10 -0
- data/lib/templates/create/basic_mode.rb.erb +10 -0
- data/lib/templates/create/basic_wrap.rb.erb +15 -0
- data/lib/templates/create/inner_class.rb.erb +9 -0
- data/lib/templates/create/mode_wrap.rb.erb +15 -0
- data/library/control_panel/control_panel.rb +53 -43
- data/library/file_chooser/file_chooser.rb +14 -20
- data/samples/external_library/java_processing/guido/slider.rb +54 -0
- data/samples/processing_app/library/file_chooser/image_viewer.rb +0 -1
- data/samples/processing_app/library/vecmath/vec3d/note.txt +1 -0
- metadata +9 -4
- data/lib/templates/create/blank_sketch.rb.erb +0 -7
- data/lib/templates/create/p3d_sketch.rb.erb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0e7df4d8034c02dcfe15463749d38214bbe608f
|
4
|
+
data.tar.gz: e4a17499eeb39eadc078e071eb05b277afd2c03f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bfc1d032a6c94051c9a727f4daa0523dc4429cb02744a34c0f6f20c84a220a653d3ba1b6716a9745622a1fd1465d9ce5506b1fe1f238980dfb64181c2f03686
|
7
|
+
data.tar.gz: d555e878a9d35ea17fc64ae4f713413364c943e92be126e2b9683b503ab4db7d03b3ac8c1b68a775770a7c9a636e059614f4a4109b8e9757ec1a10865e5f93ab
|
data/lib/rpextras.jar
CHANGED
Binary file
|
data/lib/ruby-processing.rb
CHANGED
data/lib/ruby-processing/app.rb
CHANGED
@@ -10,7 +10,8 @@ require_relative '../ruby-processing/config'
|
|
10
10
|
Dir["#{Processing::RB_CONFIG["PROCESSING_ROOT"]}/core/library/\*.jar"].each { |jar| require jar }
|
11
11
|
|
12
12
|
# Include some core processing classes that we'd like to use:
|
13
|
-
%w(PApplet PConstants PFont PImage PShape PShapeOBJ PShapeSVG PStyle
|
13
|
+
%w(PApplet PConstants PFont PImage PShape PShapeOBJ PShapeSVG PStyle
|
14
|
+
PGraphicsJava2D PGraphics PFont PVector PMatrix2D PMatrix3D).each do |klass|
|
14
15
|
java_import "processing.core.#{klass}"
|
15
16
|
end
|
16
17
|
|
@@ -50,26 +51,11 @@ module Processing
|
|
50
51
|
key_released: :keyReleased,
|
51
52
|
key_typed: :keyTyped
|
52
53
|
}
|
53
|
-
if methods_to_alias.
|
54
|
+
if methods_to_alias.key?(method_name)
|
54
55
|
alias_method methods_to_alias[method_name], method_name
|
55
56
|
end
|
56
57
|
end
|
57
|
-
|
58
|
-
# Some class methods made available in the instance.
|
59
|
-
[:day, :month, :year, :sq, :mag, :println, :hex, :abs, :binary, :ceil,
|
60
|
-
:nf, :nfc, :nfp, :nfs, :round, :trim, :unbinary, :unhex ].each do |meth|
|
61
|
-
method = <<-EOS
|
62
|
-
def #{meth}(*args)
|
63
|
-
self.class.#{meth}(*args)
|
64
|
-
end
|
65
|
-
EOS
|
66
|
-
eval method
|
67
|
-
end
|
68
|
-
|
69
|
-
# Above block deprecated from processing-2.5.1, you should in general prefer
|
70
|
-
# ruby alternatives (eg t = Time.now and t.sec to second):-
|
71
|
-
# constrain, dist, map, norm, lerp and blend_color are implemented directly
|
72
|
-
|
58
|
+
|
73
59
|
# Handy getters and setters on the class go here:
|
74
60
|
def self.sketch_class; @sketch_class; end
|
75
61
|
@@full_screen = false
|
@@ -55,7 +55,7 @@ module Processing
|
|
55
55
|
cp_r(@libraries, File.join(@dest, @prefix, 'library')) unless @libraries.empty?
|
56
56
|
# Then move the icon
|
57
57
|
potential_icon = Dir.glob(File.join(@dest, @prefix, 'data/*.icns'))[0]
|
58
|
-
move(potential_icon, File.join(@dest, 'Contents/Resources/sketch.icns'), force: true) if potential_icon
|
58
|
+
move(potential_icon, File.join(@dest, 'Contents/Resources/sketch.icns'), force: true) if potential_icon
|
59
59
|
end
|
60
60
|
|
61
61
|
def calculate_substitutions
|
@@ -66,7 +66,7 @@ module Processing
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def create_executables
|
69
|
-
render_erb_in_path_with_binding(@dest, binding, :
|
69
|
+
render_erb_in_path_with_binding(@dest, binding, delete: true)
|
70
70
|
rm Dir.glob(@dest + '/**/*.java')
|
71
71
|
runnable = @dest + '/' + File.basename(@main_file, '.rb')
|
72
72
|
move @dest + '/run', runnable
|
@@ -4,10 +4,9 @@ require_relative '../../ruby-processing/library_loader'
|
|
4
4
|
|
5
5
|
module Processing
|
6
6
|
# This base exporter implements some of the common
|
7
|
-
# code-munging needed to generate apps.
|
7
|
+
# code-munging needed to generate apps/ blank sketches.
|
8
8
|
class BaseExporter
|
9
9
|
include FileUtils
|
10
|
-
## hashes with strings as keys need to retain old hash syntax
|
11
10
|
DEFAULT_DIMENSIONS = { 'width' => '100', 'height' => '100' }
|
12
11
|
DEFAULT_DESCRIPTION = ''
|
13
12
|
NECESSARY_FOLDERS = %w(data lib vendor)
|
@@ -43,17 +42,20 @@ module Processing
|
|
43
42
|
|
44
43
|
# Searches the source for a title.
|
45
44
|
def extract_title(source)
|
46
|
-
|
45
|
+
filter = /#{@info[:class_name]}\.new.*?:title\s=>\s["'](.+?)["']/m
|
46
|
+
match = source.match(filter)
|
47
47
|
match ? match[1] : File.basename(@file, '.rb').titleize
|
48
48
|
end
|
49
49
|
|
50
50
|
# Searches the source for the width and height of the sketch.
|
51
51
|
def extract_dimension(source, dimension)
|
52
|
-
|
53
|
-
|
52
|
+
filter = /#{@info[:class_name]}\.new.*?:#{dimension}\s?=>\s?(\d+)/m
|
53
|
+
match = source.match(filter)
|
54
|
+
sz_match = source.match(/^[^#]*size\(?\s*(\d+)\s*,\s*(\d+)\s*\)?/)
|
54
55
|
return match[1] if match
|
55
|
-
return (dimension == 'width' ?
|
56
|
-
warn 'using default dimensions for export, please use constants integer
|
56
|
+
return (dimension == 'width' ? sz_match[1] : sz_match[2]) if sz_match
|
57
|
+
warn 'using default dimensions for export, please use constants integer'\
|
58
|
+
'values in size() call instead of computed ones'
|
57
59
|
DEFAULT_DIMENSIONS[dimension]
|
58
60
|
end
|
59
61
|
|
@@ -83,11 +85,14 @@ module Processing
|
|
83
85
|
requirements = []
|
84
86
|
partial_paths = []
|
85
87
|
loop do
|
86
|
-
matchdata = code.match(
|
88
|
+
matchdata = code.match(
|
89
|
+
/^.*[^::\.\w](require_relative|require|load)\b.*$/
|
90
|
+
)
|
87
91
|
break unless matchdata
|
88
92
|
line = matchdata[0].gsub('__FILE__', "'#{@main_file_path}'")
|
89
|
-
|
90
|
-
|
93
|
+
req = /\b(require_relative|require|load)\b/
|
94
|
+
if req =~ line
|
95
|
+
ln = line.gsub(req, '')
|
91
96
|
partial_paths << ln
|
92
97
|
where = "{#{local_dir}/,}{#{partial_paths.join(',')}}"
|
93
98
|
where += '.{rb,jar}' unless line =~ /\.[^.]+$/
|
@@ -1,56 +1,113 @@
|
|
1
1
|
module Processing
|
2
2
|
require_relative '../../ruby-processing/exporters/base_exporter'
|
3
|
-
|
3
|
+
Param = Struct.new(:name, :file_name, :title, :width, :height, :mode)
|
4
|
+
# An abstract class providing common methods for real creators
|
4
5
|
class Creator < BaseExporter
|
5
6
|
|
6
7
|
ALL_DIGITS = /\A\d+\Z/
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def already_exist(path)
|
10
|
+
new_file = "#{File.dirname(path)}/#{path.underscore}.rb"
|
11
|
+
if !File.exist?(path) && !File.exist?(new_file)
|
12
|
+
return
|
13
|
+
else
|
14
|
+
puts 'That file already exists!'
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@title = main_file.titleize
|
19
|
+
# Show the help/usage message for create.
|
20
|
+
def usage
|
21
|
+
puts <<-USAGE
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
Usage: rp5 create <sketch_to_generate> <width> <height> <mode>
|
24
|
+
mode can be P2D / P3D.
|
25
|
+
Use --wrap for a sketch wrapped as a class
|
26
|
+
Use --inner to generated a ruby version of 'java' Inner class
|
27
|
+
Examples: rp5 create fancy_drawing/app 800 600
|
28
|
+
rp5 create fancy_drawing/app 800 600 P3D --wrap
|
29
|
+
rp5 create inner_class --inner
|
24
30
|
|
31
|
+
USAGE
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_file(path, param, rendered, type)
|
25
35
|
# Make the file
|
26
36
|
dir = File.dirname path
|
27
37
|
mkdir_p dir
|
28
|
-
|
38
|
+
ful_path = File.join(dir, "#{param.file_name}.rb")
|
39
|
+
File.open(ful_path, 'w') { |f| f.print(rendered) }
|
40
|
+
puts "Created #{type} \"#{param.title}\" in #{ful_path.sub(/\A\.\//, '')}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# This class creates bare sketches, with an optional render mode
|
45
|
+
class BasicSketch < Creator
|
46
|
+
# Create a blank sketch, given a path.
|
47
|
+
def create!(path, args)
|
48
|
+
return usage if /\?/ =~ path || /--help/ =~ path
|
49
|
+
main_file = File.basename(path, '.rb')
|
50
|
+
# Check to make sure that the main file doesn't exist already
|
51
|
+
already_exist(path)
|
52
|
+
@param = Param.new(
|
53
|
+
main_file.camelize,
|
54
|
+
main_file.underscore,
|
55
|
+
main_file.titleize,
|
56
|
+
args[0],
|
57
|
+
args[1],
|
58
|
+
args[2]
|
59
|
+
)
|
60
|
+
@with_size = @param.width && @param.width.match(ALL_DIGITS) &&
|
61
|
+
@param.height && @param.height.match(ALL_DIGITS)
|
62
|
+
template_name = @param.mode.nil? ? 'basic.rb.erb' : 'basic_mode.rb.erb'
|
29
63
|
template = File.new("#{RP5_ROOT}/lib/templates/create/#{template_name}")
|
30
64
|
rendered = render_erb_from_string_with_binding(template.read, binding)
|
31
|
-
|
32
|
-
File.open(full_path, 'w') { |f| f.print(rendered) }
|
33
|
-
puts "Created a new Sketch in #{full_path.sub(/\A\.\//, '')}"
|
65
|
+
create_file(path, @param, rendered, 'Sketch')
|
34
66
|
end
|
67
|
+
end
|
35
68
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
69
|
+
# This class creates class wrapped sketches, with an optional render mode
|
70
|
+
class ClassSketch < Creator
|
71
|
+
# Create a bare blank sketch, given a path.
|
72
|
+
def create!(path, args)
|
73
|
+
return usage if /\?/ =~ path || /--help/ =~ path
|
74
|
+
main_file = File.basename(path, '.rb')
|
75
|
+
# Check to make sure that the main file doesn't exist already
|
76
|
+
already_exist(path)
|
77
|
+
@param = Param.new(
|
78
|
+
main_file.camelize,
|
79
|
+
main_file.underscore,
|
80
|
+
main_file.titleize,
|
81
|
+
args[0],
|
82
|
+
args[1],
|
83
|
+
args[2]
|
84
|
+
)
|
85
|
+
@with_size = @param.width && @param.width.match(ALL_DIGITS) &&
|
86
|
+
@param.height && @param.height.match(ALL_DIGITS)
|
87
|
+
t_name = @param.mode.nil? ? 'basic_wrap.rb.erb' : 'mode_wrap.rb.erb'
|
88
|
+
template = File.new("#{RP5_ROOT}/lib/templates/create/#{t_name}")
|
89
|
+
rendered = render_erb_from_string_with_binding(template.read, binding)
|
90
|
+
create_file(path, @param, rendered, 'Sketch')
|
41
91
|
end
|
92
|
+
end
|
42
93
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
94
|
+
# This class creates a ruby-processing class that mimics java inner class
|
95
|
+
class Inner < Creator
|
96
|
+
# Create a blank sketch, given a path.
|
97
|
+
def create!(path, _args_)
|
98
|
+
return usage if /\?/ =~ path || /--help/ =~ path
|
99
|
+
main_file = File.basename(path, '.rb')
|
100
|
+
# Check to make sure that the main file doesn't exist already
|
101
|
+
already_exist(path)
|
102
|
+
@param = Param.new(
|
103
|
+
main_file.camelize,
|
104
|
+
main_file.underscore,
|
105
|
+
main_file.titleize
|
106
|
+
)
|
107
|
+
template_name = 'inner_class.rb.erb'
|
108
|
+
template = File.new("#{RP5_ROOT}/lib/templates/create/#{template_name}")
|
109
|
+
rendered = render_erb_from_string_with_binding(template.read, binding)
|
110
|
+
create_file(path, @param, rendered, "\"Inner Class\"")
|
54
111
|
end
|
55
112
|
end
|
56
113
|
end
|
@@ -33,7 +33,7 @@ module Processing
|
|
33
33
|
# convert to signed int
|
34
34
|
if args.length == 1
|
35
35
|
if a.is_a?(Fixnum) && a >= 2**31
|
36
|
-
args = [
|
36
|
+
args = [a - 2**32]
|
37
37
|
elsif a.is_a?(String) && a[0].eql?('#')
|
38
38
|
h = a[1..-1].rjust(6, '0').prepend('ff')
|
39
39
|
return color(h.hex)
|
@@ -64,7 +64,13 @@ module Processing
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
# Explicitly provides 'processing.org' map instance method, in which
|
68
|
+
# value is mapped from range 1, to range 2 (NB: values are not clamped to
|
69
|
+
# range 1). It may be better to explicitly write your own interpolate function
|
70
|
+
# @param [float] value input
|
71
|
+
# @param [range] start1, stop1
|
72
|
+
# @param [range] start1, stop2
|
73
|
+
# @return [float] mapped value
|
68
74
|
def map(value, start1, stop1, start2, stop2)
|
69
75
|
start2 + (stop2 - start2) * ((value - start1).to_f / (stop1 - start1))
|
70
76
|
end
|
@@ -92,6 +98,24 @@ module Processing
|
|
92
98
|
def max(*args)
|
93
99
|
args.max { |a, b| a <=> b }
|
94
100
|
end
|
101
|
+
|
102
|
+
# explicitly provide 'processing.org' abs instance method
|
103
|
+
def abs(val)
|
104
|
+
warn 'abs(val) is deprecated use val.abs to avoid this warning'
|
105
|
+
val.abs
|
106
|
+
end
|
107
|
+
|
108
|
+
# explicitly provide 'processing.org' ceil instance method
|
109
|
+
def ceil(val)
|
110
|
+
warn 'ceil(val) is deprecated use val.ceil to avoid this warning'
|
111
|
+
val.ceil
|
112
|
+
end
|
113
|
+
|
114
|
+
# explicitly provide 'processing.org' round instance method
|
115
|
+
def round(val)
|
116
|
+
warn 'round(val) is deprecated use val.round to avoid this warning'
|
117
|
+
val.round
|
118
|
+
end
|
95
119
|
|
96
120
|
# explicitly provide 'processing.org' dist instance method
|
97
121
|
def dist(*args)
|
@@ -111,28 +135,98 @@ module Processing
|
|
111
135
|
|
112
136
|
# explicitly provide 'processing.org' pow instance method
|
113
137
|
def pow(x, exp)
|
114
|
-
|
138
|
+
warn 'pow(x, exp) is deprecated use x**exp to avoid this warning'
|
115
139
|
x**exp
|
116
140
|
end
|
117
141
|
|
118
142
|
# explicitly provide 'processing.org' radians instance method
|
119
143
|
def radians(theta)
|
120
|
-
|
144
|
+
warn 'radians(theta) is deprecated use theta.radians to avoid this warning'
|
121
145
|
theta.radians
|
122
146
|
end
|
123
147
|
|
148
|
+
# explicitly provide 'processing.org' degrees instance method
|
149
|
+
def degrees(theta)
|
150
|
+
warn 'degrees(theta) is deprecated use theta.radians to avoid this warning'
|
151
|
+
theta.degrees
|
152
|
+
end
|
153
|
+
|
154
|
+
# explicitly provide 'processing.org' hex instance method
|
155
|
+
def hex(x)
|
156
|
+
warn 'hex(x) is deprecated use x.hex to avoid this warning'
|
157
|
+
x.hex
|
158
|
+
end
|
159
|
+
|
160
|
+
# explicitly provide 'processing.org' unhex instance method
|
161
|
+
def unhex(str)
|
162
|
+
warn 'unhex(str) is deprecated use str.to_i(base=16)'
|
163
|
+
str.to_i(base=16)
|
164
|
+
end
|
165
|
+
|
166
|
+
# explicitly provide 'processing.org' binary instance method
|
167
|
+
def binary(x)
|
168
|
+
warn 'binary(x) is deprecated use x.to_s(2) to avoid this warning'
|
169
|
+
x.to_s(2)
|
170
|
+
end
|
171
|
+
|
172
|
+
# explicitly provide 'processing.org' unbinary instance method
|
173
|
+
def unhex(str)
|
174
|
+
warn 'unbinary(str) is deprecated use str.to_i(base=2)'
|
175
|
+
str.to_i(base=2)
|
176
|
+
end
|
177
|
+
|
178
|
+
# explicitly provide 'processing.org' nf instance method
|
179
|
+
def nf(*args)
|
180
|
+
warn 'nf(num, digits) is deprecated use num.to_s.rjust(digits) '\
|
181
|
+
'to avoid this warning'
|
182
|
+
if args.length == 2
|
183
|
+
return args[0].to_s.rjust(args[1], '0')
|
184
|
+
elsif args.length == 3
|
185
|
+
return args[0].to_s.rjust(args[1], '0').ljust(args[1] + args[2], '0')
|
186
|
+
else
|
187
|
+
fail ArgumentError, 'takes 2 or 3 parameters'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# explicitly provide 'processing.org' mag instance method
|
192
|
+
def mag(*vec)
|
193
|
+
warn 'mag(x, y) is deprecated use hypot(x, y)'
|
194
|
+
if vec.length == 2
|
195
|
+
return hypot(vec[0], vec[1])
|
196
|
+
elsif vec.length == 3
|
197
|
+
return Math.sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2])
|
198
|
+
else
|
199
|
+
fail ArgumentError, 'takes 2 or 3 parameters'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# explicitly provide 'processing.org' trim instance method
|
204
|
+
def trim(str)
|
205
|
+
warn 'deprecated use str.strip'
|
206
|
+
str.strip
|
207
|
+
end
|
208
|
+
|
209
|
+
# explicitly provide 'processing.org' println instance method
|
210
|
+
def println(str)
|
211
|
+
warn 'deprecated use puts(str)'
|
212
|
+
puts str
|
213
|
+
end
|
214
|
+
|
215
|
+
# explicitly provide 'processing.org' hour instance method
|
124
216
|
def hour
|
125
|
-
|
217
|
+
warn 'deprecated use t = Time.now and t.hour'
|
126
218
|
PApplet.hour
|
127
219
|
end
|
128
220
|
|
221
|
+
# explicitly provide 'processing.org' second instance method
|
129
222
|
def second
|
130
|
-
|
223
|
+
warn 'deprecated use t = Time.now and t.sec'
|
131
224
|
PApplet.second
|
132
225
|
end
|
133
226
|
|
227
|
+
# explicitly provide 'processing.org' minute instance method
|
134
228
|
def minute
|
135
|
-
|
229
|
+
'deprecated use t = Time.now and t.min'
|
136
230
|
PApplet.minute
|
137
231
|
end
|
138
232
|
|
@@ -218,4 +312,4 @@ module Processing
|
|
218
312
|
@declared_fields['keyPressed'].value(java_self)
|
219
313
|
end
|
220
314
|
end
|
221
|
-
end
|
315
|
+
end
|
@@ -1,26 +1,25 @@
|
|
1
1
|
class String #:nodoc:
|
2
|
-
|
3
2
|
def titleize
|
4
|
-
|
3
|
+
underscore.humanize.gsub(/\b([a-z])/) { $1.capitalize }
|
5
4
|
end
|
6
5
|
|
7
|
-
def humanize
|
8
|
-
|
6
|
+
def humanize
|
7
|
+
gsub(/_id$/, '').gsub(/_/, ' ').capitalize
|
9
8
|
end
|
10
9
|
|
11
10
|
def camelize(first_letter_in_uppercase = true)
|
12
11
|
if first_letter_in_uppercase
|
13
|
-
|
12
|
+
gsub(/\/(.?)/) { '::' + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
14
13
|
else
|
15
|
-
|
14
|
+
first + camelize[1..-1]
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
18
|
def underscore
|
20
|
-
|
19
|
+
gsub(/::/, '/')
|
21
20
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
22
21
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
23
22
|
.tr('-', '_')
|
24
23
|
.downcase
|
25
24
|
end
|
26
|
-
end
|
25
|
+
end
|
@@ -23,7 +23,7 @@ module Processing
|
|
23
23
|
run: run sketch once
|
24
24
|
watch: watch for changes on the file and relaunch it on the fly
|
25
25
|
live: launch sketch and give an interactive IRB shell
|
26
|
-
create [width height]: create a new sketch.
|
26
|
+
create [width height][mode][flag]: create a new sketch.
|
27
27
|
app: create an application version of the sketch
|
28
28
|
setup: check setup, install jruby-complete, unpack samples
|
29
29
|
|
@@ -34,8 +34,8 @@ module Processing
|
|
34
34
|
Examples:
|
35
35
|
rp5 setup unpack_samples
|
36
36
|
rp5 run samples/contributed/jwishy.rb
|
37
|
-
rp5 create some_new_sketch 640 480
|
38
|
-
rp5 create some_new_sketch --
|
37
|
+
rp5 create some_new_sketch 640 480 p3d (P3D mode example)
|
38
|
+
rp5 create some_new_sketch 640 480 --wrap (a class wrapped default sketch)
|
39
39
|
rp5 watch some_new_sketch.rb
|
40
40
|
|
41
41
|
Everything Else:
|
@@ -56,7 +56,7 @@ module Processing
|
|
56
56
|
when 'run' then run(@options.path, @options.args)
|
57
57
|
when 'watch' then watch(@options.path, @options.args)
|
58
58
|
when 'live' then live(@options.path, @options.args)
|
59
|
-
when 'create' then create(@options.path, @options.args
|
59
|
+
when 'create' then create(@options.path, @options.args)
|
60
60
|
when 'app' then app(@options.path)
|
61
61
|
when 'setup' then setup(@options.path)
|
62
62
|
when /-v/ then show_version
|
@@ -69,7 +69,8 @@ module Processing
|
|
69
69
|
# Parse the command-line options. Keep it simple.
|
70
70
|
def parse_options(args)
|
71
71
|
@options = OpenStruct.new
|
72
|
-
@options.
|
72
|
+
@options.wrap = !args.delete('--wrap').nil?
|
73
|
+
@options.inner = !args.delete('--inner').nil?
|
73
74
|
@options.jruby = !args.delete('--jruby').nil?
|
74
75
|
@options.nojruby = !args.delete('--nojruby').nil?
|
75
76
|
@options.action = args[0] || nil
|
@@ -79,9 +80,14 @@ module Processing
|
|
79
80
|
|
80
81
|
# Create a fresh Ruby-Processing sketch, with the necessary
|
81
82
|
# boilerplate filled out.
|
82
|
-
def create(sketch, args
|
83
|
+
def create(sketch, args)
|
83
84
|
require_relative '../ruby-processing/exporters/creator'
|
84
|
-
Processing::
|
85
|
+
return Processing::Inner.new.create!(sketch, args) if @options.inner
|
86
|
+
if @options.wrap
|
87
|
+
Processing::ClassSketch.new.create!(sketch, args)
|
88
|
+
else
|
89
|
+
Processing::BasicSketch.new.create!(sketch, args)
|
90
|
+
end
|
85
91
|
end
|
86
92
|
|
87
93
|
# Just simply run a ruby-processing sketch.
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require_relative '../runners/base'
|
2
2
|
|
3
3
|
module Processing
|
4
|
-
|
5
4
|
# A sketch loader, observer, and reloader, to tighten
|
6
5
|
# the feedback between code and effect.
|
7
6
|
class Watcher
|
8
|
-
|
9
7
|
# Sic a new Processing::Watcher on the sketch
|
10
8
|
def initialize
|
11
9
|
reload_files_to_watch
|
@@ -13,7 +11,6 @@ module Processing
|
|
13
11
|
start_watching
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
14
|
# Kicks off a thread to watch the sketch, reloading Ruby-Processing
|
18
15
|
# and restarting the sketch whenever it changes.
|
19
16
|
def start_watching
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# <%= @param.file_name %>.rb
|
2
|
+
|
3
|
+
class <%= @param.name %> < Processing::App
|
4
|
+
|
5
|
+
def setup
|
6
|
+
<%= "size #{@param.width}, #{@param.height}, #{@param.mode.upcase}" if @with_size %>
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
<%= @param.name %>.new(x: 20, y: 30)
|
@@ -6,15 +6,17 @@
|
|
6
6
|
# (optionally) pass the range and default value.
|
7
7
|
|
8
8
|
module ControlPanel
|
9
|
-
|
9
|
+
# class used to create slider elements for control_panel
|
10
10
|
class Slider < javax.swing.JSlider
|
11
|
-
def initialize(control_panel, name, range, initial_value, proc=nil)
|
11
|
+
def initialize(control_panel, name, range, initial_value, proc = nil)
|
12
12
|
min = range.begin * 100
|
13
|
-
max = (
|
13
|
+
max = (
|
14
|
+
(range.exclude_end? && range.begin.respond_to?(:succ)) ?
|
15
|
+
range.max : range.end) * 100
|
14
16
|
super(min, max)
|
15
17
|
set_minor_tick_spacing((max - min).abs / 10)
|
16
18
|
set_paint_ticks true
|
17
|
-
paint_labels = true
|
19
|
+
# paint_labels = true
|
18
20
|
set_preferred_size(java.awt.Dimension.new(190, 30))
|
19
21
|
label = control_panel.add_element(self, name)
|
20
22
|
add_change_listener do
|
@@ -22,22 +24,22 @@ module ControlPanel
|
|
22
24
|
$app.instance_variable_set("@#{name}", value) unless value.nil?
|
23
25
|
proc.call(value) if proc
|
24
26
|
end
|
25
|
-
set_value(initial_value ? initial_value*100 : min)
|
27
|
+
set_value(initial_value ? initial_value * 100 : min)
|
26
28
|
fire_state_changed
|
27
29
|
end
|
28
|
-
|
30
|
+
|
29
31
|
def value
|
30
32
|
get_value / 100.0
|
31
33
|
end
|
32
|
-
|
34
|
+
|
33
35
|
def update_label(label, name, value)
|
34
36
|
value = value.to_s
|
35
37
|
value << '0' if value.length < 4
|
36
|
-
label.set_text "<html><br><b>#{name
|
38
|
+
label.set_text "<html><br><b>#{name}: #{value}</b></html>"
|
37
39
|
end
|
38
40
|
end
|
39
|
-
|
40
|
-
|
41
|
+
|
42
|
+
# class used to combo_box menu elements for control_panel
|
41
43
|
class Menu < javax.swing.JComboBox
|
42
44
|
def initialize(control_panel, name, elements, initial_value, proc = nil)
|
43
45
|
super(elements.to_java(:String))
|
@@ -49,13 +51,13 @@ module ControlPanel
|
|
49
51
|
end
|
50
52
|
set_selected_index(initial_value ? elements.index(initial_value) : 0)
|
51
53
|
end
|
52
|
-
|
54
|
+
|
53
55
|
def value
|
54
56
|
get_selected_item
|
55
57
|
end
|
56
58
|
end
|
57
|
-
|
58
|
-
|
59
|
+
|
60
|
+
# Creates check-box elements for control_panel
|
59
61
|
class Checkbox < javax.swing.JCheckBox
|
60
62
|
def initialize(control_panel, name, proc=nil)
|
61
63
|
@control_panel = control_panel
|
@@ -68,15 +70,15 @@ module ControlPanel
|
|
68
70
|
proc.call(value) if proc
|
69
71
|
end
|
70
72
|
end
|
71
|
-
|
73
|
+
|
72
74
|
def value
|
73
75
|
is_selected
|
74
76
|
end
|
75
77
|
end
|
76
|
-
|
77
|
-
|
78
|
+
|
79
|
+
# Creates button elements for control_panel
|
78
80
|
class Button < javax.swing.JButton
|
79
|
-
def initialize(control_panel, name, proc=nil)
|
81
|
+
def initialize(control_panel, name, proc = nil)
|
80
82
|
super(name.to_s)
|
81
83
|
set_preferred_size(java.awt.Dimension.new(170, 64))
|
82
84
|
control_panel.add_element(self, name, false, true)
|
@@ -86,19 +88,20 @@ module ControlPanel
|
|
86
88
|
end
|
87
89
|
end
|
88
90
|
end
|
89
|
-
|
90
|
-
|
91
|
+
|
92
|
+
# class used to contain control_panel elements
|
91
93
|
class Panel < javax.swing.JFrame
|
92
94
|
java_import javax.swing.UIManager
|
93
|
-
|
95
|
+
|
94
96
|
attr_accessor :elements, :panel
|
95
|
-
|
96
|
-
def initialize
|
97
|
+
|
98
|
+
def initialize
|
97
99
|
super()
|
98
100
|
@elements = []
|
99
101
|
@panel = javax.swing.JPanel.new(java.awt.FlowLayout.new(1, 0, 0))
|
102
|
+
set_feel
|
100
103
|
end
|
101
|
-
|
104
|
+
|
102
105
|
def display
|
103
106
|
add panel
|
104
107
|
set_size 200, 30 + (64 * elements.size)
|
@@ -107,49 +110,57 @@ module ControlPanel
|
|
107
110
|
set_location($app.width + 10, 0) unless ($app.width + 10 > $app.displayWidth)
|
108
111
|
panel.visible = true
|
109
112
|
end
|
110
|
-
|
111
|
-
def add_element(element, name, has_label=true,
|
113
|
+
|
114
|
+
def add_element(element, name, has_label = true, _button_ = false)
|
112
115
|
if has_label
|
113
116
|
label = javax.swing.JLabel.new("<html><br><b>#{name}</b></html>")
|
114
117
|
panel.add label
|
115
118
|
end
|
116
119
|
elements << element
|
117
120
|
panel.add element
|
118
|
-
|
121
|
+
has_label ? label : nil
|
119
122
|
end
|
120
|
-
|
123
|
+
|
121
124
|
def remove
|
122
125
|
remove_all
|
123
126
|
dispose
|
124
127
|
end
|
125
|
-
|
126
|
-
def slider(name, range=0..100, initial_value = nil, &block)
|
127
|
-
|
128
|
+
|
129
|
+
def slider(name, range = 0..100, initial_value = nil, &block)
|
130
|
+
Slider.new(self, name, range, initial_value, block || nil)
|
128
131
|
end
|
129
|
-
|
132
|
+
|
130
133
|
def menu(name, elements, initial_value = nil, &block)
|
131
|
-
|
134
|
+
Menu.new(self, name, elements, initial_value, block || nil)
|
132
135
|
end
|
133
|
-
|
136
|
+
|
134
137
|
def checkbox(name, initial_value = nil, &block)
|
135
138
|
checkbox = Checkbox.new(self, name, block || nil)
|
136
139
|
checkbox.do_click if initial_value == true
|
137
140
|
end
|
138
|
-
|
141
|
+
|
139
142
|
def button(name, &block)
|
140
|
-
|
143
|
+
Button.new(self, name, block || nil)
|
141
144
|
end
|
142
|
-
|
143
|
-
def look_feel(lf
|
144
|
-
|
145
|
-
javax.swing.UIManager::setLookAndFeel(lafs[0].getClassName) if lafs.size > 0
|
145
|
+
|
146
|
+
def look_feel(lf)
|
147
|
+
set_feel(lf)
|
146
148
|
end
|
147
149
|
|
150
|
+
private
|
151
|
+
|
152
|
+
def set_feel(lf = 'metal')
|
153
|
+
lafinfo = javax.swing.UIManager.getInstalledLookAndFeels
|
154
|
+
laf = lafinfo.select do |info|
|
155
|
+
info.getName.eql? lf.capitalize
|
156
|
+
end
|
157
|
+
javax.swing.UIManager.setLookAndFeel(laf[0].getClassName)
|
158
|
+
end
|
148
159
|
end
|
149
|
-
|
150
|
-
|
160
|
+
|
161
|
+
# instance methods module
|
151
162
|
module InstanceMethods
|
152
|
-
def control_panel
|
163
|
+
def control_panel
|
153
164
|
@control_panel = ControlPanel::Panel.new unless @control_panel
|
154
165
|
return @control_panel unless block_given?
|
155
166
|
yield(@control_panel)
|
@@ -158,5 +169,4 @@ module ControlPanel
|
|
158
169
|
end
|
159
170
|
end
|
160
171
|
|
161
|
-
|
162
172
|
Processing::App.send :include, ControlPanel::InstanceMethods
|
@@ -1,33 +1,32 @@
|
|
1
1
|
# Here's a little library for using swing JFileChooser.
|
2
|
-
# in ruby-processing,
|
2
|
+
# in ruby-processing, borrows heavily from control_panel
|
3
3
|
|
4
4
|
module FileChooser
|
5
5
|
##
|
6
6
|
# FileFilter is abstract, requires accept and getDescription
|
7
7
|
##
|
8
|
-
|
8
|
+
|
9
9
|
require 'pathname'
|
10
10
|
JXChooser = Java::javax::swing::JFileChooser
|
11
|
-
JFile = Java::java::io::File
|
11
|
+
JFile = Java::java::io::File
|
12
12
|
System = Java::JavaLang::System
|
13
|
-
|
13
|
+
|
14
14
|
class Filter < Java::javax::swing::filechooser::FileFilter
|
15
15
|
attr_reader :description, :extensions
|
16
16
|
def define(description, extensions)
|
17
17
|
@description, @extensions = description, extensions
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def accept(fobj)
|
21
|
-
return true if extensions.include?
|
21
|
+
return true if extensions.include? File.extname(fobj.to_s).downcase
|
22
22
|
return true if fobj.isDirectory
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
25
|
def getDescription
|
27
26
|
description
|
28
27
|
end
|
29
28
|
end
|
30
|
-
|
29
|
+
|
31
30
|
class RXChooser
|
32
31
|
java_import javax.swing.UIManager
|
33
32
|
require 'rbconfig'
|
@@ -39,29 +38,25 @@ module FileChooser
|
|
39
38
|
when /darwin/ then OS = :mac
|
40
39
|
when /mswin|mingw/ then OS = :windows
|
41
40
|
end
|
42
|
-
|
41
|
+
|
43
42
|
def initialize
|
43
|
+
javax.swing.UIManager.setLookAndFeel(
|
44
|
+
javax.swing.UIManager.getSystemLookAndFeelClassName)
|
44
45
|
@chooser = JXChooser.new
|
45
46
|
end
|
46
|
-
|
47
|
-
def look_feel(lf = 'Metal')
|
48
|
-
lafs = javax.swing.UIManager::getInstalledLookAndFeels.select{ |info|
|
49
|
-
info.getName.eql? lf }
|
50
|
-
javax.swing.UIManager::setLookAndFeel(lafs[0].getClassName) if lafs.size > 0
|
51
|
-
end
|
52
|
-
|
47
|
+
|
53
48
|
def set_filter(description, extensions)
|
54
49
|
filter = FileChooser::Filter.new
|
55
50
|
filter.define(description, extensions)
|
56
51
|
@chooser.setFileFilter(filter)
|
57
52
|
end
|
58
|
-
|
53
|
+
|
59
54
|
def display
|
60
55
|
if :windows == OS
|
61
56
|
@chooser.setCurrentDirectory(JFile.new(System.getProperty(UDIR)))
|
62
57
|
else
|
63
58
|
@chooser.setCurrentDirectory(JFile.new(System.getProperty(UHOME)))
|
64
|
-
end
|
59
|
+
end
|
65
60
|
success = @chooser.show_open_dialog($app)
|
66
61
|
if success == JXChooser::APPROVE_OPTION
|
67
62
|
return Pathname.new(@chooser.get_selected_file.get_absolute_path).to_s
|
@@ -73,9 +68,8 @@ module FileChooser
|
|
73
68
|
def dispose
|
74
69
|
@chooser = nil
|
75
70
|
end
|
76
|
-
|
77
71
|
end
|
78
|
-
|
72
|
+
|
79
73
|
module InstanceMethods
|
80
74
|
def file_chooser
|
81
75
|
@chooser = RXChooser.new
|
@@ -0,0 +1,54 @@
|
|
1
|
+
load_library :guido
|
2
|
+
import 'de.bezier.guido'
|
3
|
+
|
4
|
+
def setup
|
5
|
+
size 400, 400
|
6
|
+
Interactive.make self
|
7
|
+
@slider = Slider.new 10, height - 20, width - 20, 10
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw
|
11
|
+
background 180
|
12
|
+
fill 255
|
13
|
+
v = 10 + @slider.value * (width - 30)
|
14
|
+
ellipse width / 2, height / 2, v, v
|
15
|
+
end
|
16
|
+
|
17
|
+
class Slider < ActiveElement
|
18
|
+
|
19
|
+
attr_reader :value
|
20
|
+
|
21
|
+
def initialize (x, y, w, h)
|
22
|
+
super x, y, w, h
|
23
|
+
@x = x
|
24
|
+
@y = y
|
25
|
+
@width = w
|
26
|
+
@height = h
|
27
|
+
@hover = false
|
28
|
+
@value = 0
|
29
|
+
@value_x = x
|
30
|
+
end
|
31
|
+
|
32
|
+
def mouseEntered(mx, my)
|
33
|
+
@hover = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def mouseExited(mx, my)
|
37
|
+
@hover = false
|
38
|
+
end
|
39
|
+
|
40
|
+
def mouseDragged(mx, my, dx, dy)
|
41
|
+
@value_x = mx - @height / 2
|
42
|
+
@value_x = @x if (@value_x < @x)
|
43
|
+
@value_x = @x + @width - @height if (@value_x > @x + @width - @height)
|
44
|
+
@value = map(@value_x, @x, @x + @width - @height, 0, 1)
|
45
|
+
end
|
46
|
+
|
47
|
+
def draw
|
48
|
+
no_stroke
|
49
|
+
fill @hover ? 220 : 150
|
50
|
+
rect @x, @y, @width, @height
|
51
|
+
fill 120
|
52
|
+
rect @value_x, @y, @height, @height
|
53
|
+
end
|
54
|
+
end
|
@@ -11,7 +11,6 @@ attr_reader :img
|
|
11
11
|
|
12
12
|
def setup
|
13
13
|
file_chooser do |fc|
|
14
|
-
fc.look_feel "Metal" # optional, "Metal" might be best linux (Gtk+ theme)
|
15
14
|
fc.set_filter "Image Files", [".png", ".jpg"] # easily customizable chooser
|
16
15
|
@img = load_image(fc.display) # fc.display returns a path String
|
17
16
|
size(img.width, img.height)
|
@@ -0,0 +1 @@
|
|
1
|
+
retained menger requires compat.version=2.0 (jruby-1.7.xx)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ashkenas
|
@@ -18,7 +18,7 @@ authors:
|
|
18
18
|
autorequire:
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
|
-
date: 2014-08-
|
21
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: bundler
|
@@ -130,8 +130,11 @@ files:
|
|
130
130
|
- lib/templates/application/lib/library/library.txt
|
131
131
|
- lib/templates/application/run.erb
|
132
132
|
- lib/templates/application/run.exe
|
133
|
-
- lib/templates/create/
|
134
|
-
- lib/templates/create/
|
133
|
+
- lib/templates/create/basic.rb.erb
|
134
|
+
- lib/templates/create/basic_mode.rb.erb
|
135
|
+
- lib/templates/create/basic_wrap.rb.erb
|
136
|
+
- lib/templates/create/inner_class.rb.erb
|
137
|
+
- lib/templates/create/mode_wrap.rb.erb
|
135
138
|
- library/boids/boids.rb
|
136
139
|
- library/control_panel/control_panel.rb
|
137
140
|
- library/fastmath/fastmath.rb
|
@@ -195,6 +198,7 @@ files:
|
|
195
198
|
- samples/external_library/java_processing/grafica/default_plot.rb
|
196
199
|
- samples/external_library/java_processing/grafica/multiple_panels.rb
|
197
200
|
- samples/external_library/java_processing/grafica/oktoberfest_example.rb
|
201
|
+
- samples/external_library/java_processing/guido/slider.rb
|
198
202
|
- samples/external_library/java_processing/hemesh/data/java_args.txt
|
199
203
|
- samples/external_library/java_processing/hemesh/library/vbo/mesh_to_vbo.rb
|
200
204
|
- samples/external_library/java_processing/hemesh/twin_iso.rb
|
@@ -464,6 +468,7 @@ files:
|
|
464
468
|
- samples/processing_app/library/vecmath/vec3d/library/geometry/lib/mat4.rb
|
465
469
|
- samples/processing_app/library/vecmath/vec3d/library/geometry/lib/plane.rb
|
466
470
|
- samples/processing_app/library/vecmath/vec3d/library/hilbert/hilbert.rb
|
471
|
+
- samples/processing_app/library/vecmath/vec3d/note.txt
|
467
472
|
- samples/processing_app/library/vecmath/vec3d/retained_menger.rb
|
468
473
|
- samples/processing_app/topics/advanced_data/README
|
469
474
|
- samples/processing_app/topics/advanced_data/Rakefile
|