picrate 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
require 'optparse'
|
3
|
+
require_relative 'version'
|
4
|
+
|
5
|
+
module Processing
|
6
|
+
# Utility class to handle the different commands that the 'picrate' offers
|
7
|
+
class Runner
|
8
|
+
attr_reader :options, :argc, :filename
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@options = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Start running a picrate command from the passed-in arguments
|
15
|
+
def self.execute
|
16
|
+
runner = new
|
17
|
+
runner.parse_options(ARGV)
|
18
|
+
runner.execute!
|
19
|
+
end
|
20
|
+
|
21
|
+
# Dispatch central.
|
22
|
+
def execute!
|
23
|
+
show_help if options.empty?
|
24
|
+
show_version if options[:version]
|
25
|
+
create if options[:create]
|
26
|
+
install(filename) if options[:install]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Parse the command-line options. Keep it simple.
|
30
|
+
def parse_options(args)
|
31
|
+
opt_parser = OptionParser.new do |opts|
|
32
|
+
# Set a banner, displayed at the top
|
33
|
+
# of the help screen.
|
34
|
+
opts.banner = 'Usage: picrate [options] [<sketch.rb>]'
|
35
|
+
|
36
|
+
# Define the options, and what they do
|
37
|
+
options[:version] = false
|
38
|
+
opts.on('-v', '--version', 'Processing Version') do
|
39
|
+
options[:version] = true
|
40
|
+
end
|
41
|
+
|
42
|
+
options[:install] = false
|
43
|
+
message = '<Samples><GLVideo><Video><Sound> Install samples or library'
|
44
|
+
opts.on('-i', '--install', message) do
|
45
|
+
options[:install] = true
|
46
|
+
end
|
47
|
+
|
48
|
+
options[:create] = false
|
49
|
+
opts.on('-c', '--create', 'Create new sketch outline') do
|
50
|
+
options[:create] = true
|
51
|
+
end
|
52
|
+
|
53
|
+
# This displays the help screen, all programs are
|
54
|
+
# assumed to have this option.
|
55
|
+
opts.on('-h', '--help', 'Display this screen') do
|
56
|
+
puts opts
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
@argc = opt_parser.parse(args)
|
61
|
+
@filename = argc.shift
|
62
|
+
end
|
63
|
+
|
64
|
+
def create
|
65
|
+
require_relative 'creators/sketch_writer'
|
66
|
+
SketchWriter.new(File.basename(filename, '.rb'), argc).write
|
67
|
+
end
|
68
|
+
|
69
|
+
def show_version
|
70
|
+
v_format = "Processing version %s\nJRuby version %s"
|
71
|
+
puts format(v_format, Processing::VERSION, JRUBY_VERSION)
|
72
|
+
end
|
73
|
+
|
74
|
+
def install(library)
|
75
|
+
choice = library.downcase
|
76
|
+
valid = Regexp.union('samples', 'sound', 'video', 'glvideo')
|
77
|
+
return warn format('No installer for %s', choice) unless valid =~ choice
|
78
|
+
system "cd #{PICRATE_ROOT}/vendors && rake download_and_copy_#{choice}"
|
79
|
+
end
|
80
|
+
end # class Runner
|
81
|
+
end # module Processing
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Boids -- after Tom de Smedt.
|
3
|
+
# See his Python version: http://nodebox.net/code/index.php/Boids
|
4
|
+
# This is an example of how a pure-Ruby library can work. Original for
|
5
|
+
# ruby-processing Jeremy Ashkenas. Reworked, re-factored for JRubyArt 0.9+
|
6
|
+
# by Martin Prout, features forwardable, keyword args, Vec3D and Vec2D.
|
7
|
+
class Boid
|
8
|
+
attr_reader :boids
|
9
|
+
attr_accessor :vel, :pos, :is_perching, :perch_time
|
10
|
+
def initialize(boids, pos)
|
11
|
+
@boids, @flock = boids, boids
|
12
|
+
@pos = pos
|
13
|
+
@vel = Vec3D.new
|
14
|
+
@is_perching = false
|
15
|
+
@perch_time = 0.0
|
16
|
+
end
|
17
|
+
|
18
|
+
def cohesion(d:)
|
19
|
+
# Boids gravitate towards the center of the flock,
|
20
|
+
# Which is the averaged position of the rest of the boids.
|
21
|
+
vect = Vec3D.new
|
22
|
+
@boids.each do |boid|
|
23
|
+
vect += boid.pos unless boid == self
|
24
|
+
end
|
25
|
+
count = @boids.length - 1.0
|
26
|
+
vect /= count
|
27
|
+
(vect - pos) / d
|
28
|
+
end
|
29
|
+
|
30
|
+
def separation(radius:)
|
31
|
+
# Boids don't like to cuddle.
|
32
|
+
vect = Vec3D.new
|
33
|
+
@boids.each do |boid|
|
34
|
+
if boid != self
|
35
|
+
dv = pos - boid.pos
|
36
|
+
vect += dv if dv.mag < radius
|
37
|
+
end
|
38
|
+
end
|
39
|
+
vect
|
40
|
+
end
|
41
|
+
|
42
|
+
def alignment(d:)
|
43
|
+
# Boids like to fly at the speed of traffic.
|
44
|
+
vect = Vec3D.new
|
45
|
+
@boids.each do |boid|
|
46
|
+
vect += boid.vel if boid != self
|
47
|
+
end
|
48
|
+
count = @boids.length - 1.0
|
49
|
+
vect /= count
|
50
|
+
(vect - vel) / d
|
51
|
+
end
|
52
|
+
|
53
|
+
def limit(max:)
|
54
|
+
# Tweet, Tweet! The boid police will bust you for breaking the speed limit.
|
55
|
+
most = [vel.x.abs, vel.y.abs, vel.z.abs].max
|
56
|
+
return if most < max
|
57
|
+
scale = max / most.to_f
|
58
|
+
@vel *= scale
|
59
|
+
end
|
60
|
+
|
61
|
+
def angle
|
62
|
+
Vec2D.new(vel.x, vel.y).heading
|
63
|
+
end
|
64
|
+
|
65
|
+
def goal(target, d = 50.0)
|
66
|
+
# Them boids is hungry.
|
67
|
+
(target - pos) / d
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
require 'forwardable'
|
72
|
+
|
73
|
+
# The Boids class
|
74
|
+
class Boids
|
75
|
+
include Enumerable
|
76
|
+
extend Forwardable
|
77
|
+
def_delegators(:@boids, :reject, :<<, :each, :shuffle!, :length, :next)
|
78
|
+
|
79
|
+
attr_reader :has_goal, :perch, :perch_tm, :perch_y
|
80
|
+
|
81
|
+
def initialize
|
82
|
+
@boids = []
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.flock(n:, x:, y:, w:, h:)
|
86
|
+
flock = Boids.new.setup(n, x, y, w, h)
|
87
|
+
flock.reset_goal(Vec3D.new(w / 2, h / 2, 0))
|
88
|
+
end
|
89
|
+
|
90
|
+
def setup(n, x, y, w, h)
|
91
|
+
n.times do
|
92
|
+
dx, dy = rand(w), rand(h)
|
93
|
+
z = rand(200.0)
|
94
|
+
self << Boid.new(self, Vec3D.new(x + dx, y + dy, z))
|
95
|
+
end
|
96
|
+
@x, @y, @w, @h = x, y, w, h
|
97
|
+
@scattered = false
|
98
|
+
@scatter = 0.005
|
99
|
+
@scatter_time = 50.0
|
100
|
+
@scatter_i = 0.0
|
101
|
+
@perch = 1.0 # Lower this number to divebomb.
|
102
|
+
@perch_y = h
|
103
|
+
@perch_tm = -> { 25.0 + rand(50.0) }
|
104
|
+
@has_goal = false
|
105
|
+
@flee = false
|
106
|
+
@goal = Vec3D.new
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
110
|
+
def scatter(chance = 0.005, frames = 50.0)
|
111
|
+
@scatter = chance
|
112
|
+
@scatter_time = frames
|
113
|
+
end
|
114
|
+
|
115
|
+
def no_scatter
|
116
|
+
@scatter = 0.0
|
117
|
+
end
|
118
|
+
|
119
|
+
def perch(ground = nil, chance = 1.0, frames = nil)
|
120
|
+
@perch_tm = frames.nil? ? -> { 25.0 + rand(50.0) } : frames
|
121
|
+
@perch_y = ground.nil? ? @h : ground
|
122
|
+
@perch = chance
|
123
|
+
end
|
124
|
+
|
125
|
+
def no_perch
|
126
|
+
@perch = 0.0
|
127
|
+
end
|
128
|
+
|
129
|
+
def reset_goal(target)
|
130
|
+
@has_goal = true
|
131
|
+
@flee = false
|
132
|
+
@goal = target
|
133
|
+
self
|
134
|
+
end
|
135
|
+
|
136
|
+
def goal(target:, flee:)
|
137
|
+
@has_goal = true
|
138
|
+
@flee = flee
|
139
|
+
@goal = target
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
def no_goal
|
144
|
+
@has_goal = false
|
145
|
+
end
|
146
|
+
|
147
|
+
def constrain
|
148
|
+
# Put them boids in a cage.
|
149
|
+
dx, dy = @w * 0.1, @h * 0.1
|
150
|
+
each do |b|
|
151
|
+
b.vel.x += rand(dx) if b.pos.x < @x - dx
|
152
|
+
b.vel.y += rand(dy) if b.pos.y < @y - dy
|
153
|
+
b.vel.x -= rand(dx) if b.pos.x > @x + @w + dx
|
154
|
+
b.vel.y -= rand(dy) if b.pos.y > @y + @h + dy
|
155
|
+
b.vel.z += 10.0 if b.pos.z < 0.0
|
156
|
+
b.vel.z -= 10.0 if b.pos.z > 100.0
|
157
|
+
next unless b.pos.y > perch_y && rand < perch
|
158
|
+
b.pos.y = perch_y
|
159
|
+
b.vel.y = b.vel.y.abs * -0.2
|
160
|
+
b.is_perching = true
|
161
|
+
b.perch_time = perch_tm.respond_to?(:call) ? perch_tm.call : perch_tm
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def update(goal: 20.0, limit: 30.0, **args)
|
166
|
+
shuffled = args.fetch(:shuffled, true)
|
167
|
+
cohesion = args.fetch(:cohesion, 100)
|
168
|
+
separation = args.fetch(:separation, 10)
|
169
|
+
alignment = args.fetch(:alignment, 5.0)
|
170
|
+
# Just flutter, little boids ... just flutter away.
|
171
|
+
# Shuffling keeps things flowing smooth.
|
172
|
+
shuffle! if shuffled
|
173
|
+
m1 = 1.0 # cohesion
|
174
|
+
m2 = 1.0 # separation
|
175
|
+
m3 = 1.0 # alignment
|
176
|
+
m4 = 1.0 # goal
|
177
|
+
@scattered = true if !@scattered && rand < @scatter
|
178
|
+
if @scattered
|
179
|
+
m1 = -m1
|
180
|
+
m3 *= 0.25
|
181
|
+
@scatter_i += 1.0
|
182
|
+
end
|
183
|
+
if @scatter_i >= @scatter_time
|
184
|
+
@scattered = false
|
185
|
+
@scatter_i = 0.0
|
186
|
+
end
|
187
|
+
m4 = 0.0 unless has_goal
|
188
|
+
m4 = -m4 if @flee
|
189
|
+
each do |b|
|
190
|
+
if b.is_perching
|
191
|
+
if b.perch_time > 0.0
|
192
|
+
b.perch_time -= 1.0
|
193
|
+
next
|
194
|
+
else
|
195
|
+
b.is_perching = false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
v1 = b.cohesion(d: cohesion)
|
199
|
+
v2 = b.separation(radius: separation)
|
200
|
+
v3 = b.alignment(d: alignment)
|
201
|
+
v4 = b.goal(@goal, goal)
|
202
|
+
# NB: vector must precede scalar in '*' operation below
|
203
|
+
b.vel += (v1 * m1 + v2 * m2 + v3 * m3 + v4 * m4)
|
204
|
+
b.limit(max: limit)
|
205
|
+
b.pos += b.vel
|
206
|
+
end
|
207
|
+
constrain
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Usage:
|
3
|
+
# load_library :chooser
|
4
|
+
#
|
5
|
+
# def setup
|
6
|
+
# java_signature 'void selectInput(String, String)'
|
7
|
+
# selectInput('Select a file to process:', 'fileSelected')
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def fileSelected(selection)
|
11
|
+
# if selection.nil?
|
12
|
+
# puts 'Window was closed or the user hit cancel.'
|
13
|
+
# else
|
14
|
+
# puts format('User selected %s', selection.get_absolute_path)
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
class Processing::App
|
18
|
+
include Java::MonkstoneFilechooser::Chooser
|
19
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# Here's a little library for quickly hooking up controls to sketches.
|
2
|
+
# For messing with the parameters and such.
|
3
|
+
# These controls will set instance variables on the sketches.
|
4
|
+
# You can make sliders, checkboxes, buttons, and drop-down menus.
|
5
|
+
# Optionally pass range and a default value to sliders.
|
6
|
+
module ControlPanel
|
7
|
+
def self.app_value(name, val)
|
8
|
+
Processing.app.instance_variable_set("@#{name}", val)
|
9
|
+
end
|
10
|
+
|
11
|
+
# class used to create slider elements for control_panel
|
12
|
+
class Slider < javax.swing.JSlider
|
13
|
+
def initialize(control_panel, name, range, initial, proc = nil)
|
14
|
+
min = range.begin * 100
|
15
|
+
mx = range.end
|
16
|
+
mx = range.max if range.exclude_end? && range.begin.respond_to?(:succ)
|
17
|
+
max = mx * 100
|
18
|
+
val = range.cover?(initial) ? initial * 100 : (range.first + range.last) * 50
|
19
|
+
super(min, max, val)
|
20
|
+
set_minor_tick_spacing((max - min).abs / 10)
|
21
|
+
set_paint_ticks true
|
22
|
+
# paint_labels = true
|
23
|
+
set_preferred_size(java.awt.Dimension.new(190, 30))
|
24
|
+
label = control_panel.add_element(self, name)
|
25
|
+
add_change_listener do
|
26
|
+
update_label(label, name, value)
|
27
|
+
ControlPanel.app_value(name, value)
|
28
|
+
proc.call(value) if proc
|
29
|
+
end
|
30
|
+
ControlPanel.app_value(name, val)
|
31
|
+
end
|
32
|
+
|
33
|
+
def value
|
34
|
+
get_value / 100.0
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_label(label, name, value)
|
38
|
+
value = value.to_s
|
39
|
+
value << '0' if value.length < 4
|
40
|
+
label.set_text "<html><br><b>#{name}: #{value}</b></html>"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# class used to combo_box menu elements for control_panel
|
45
|
+
class Menu < javax.swing.JComboBox
|
46
|
+
def initialize(control_panel, name, elements, initial_value, proc = nil)
|
47
|
+
super(elements.to_java(:String))
|
48
|
+
set_preferred_size(java.awt.Dimension.new(190, 30))
|
49
|
+
control_panel.add_element(self, name)
|
50
|
+
add_action_listener do
|
51
|
+
ControlPanel.app_value(name, value) unless value.nil?
|
52
|
+
proc.call(value) if proc
|
53
|
+
end
|
54
|
+
set_selected_index(initial_value ? elements.index(initial_value) : 0)
|
55
|
+
end
|
56
|
+
|
57
|
+
def value
|
58
|
+
get_selected_item
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Creates check-box elements for control_panel
|
63
|
+
class Checkbox < javax.swing.JCheckBox
|
64
|
+
def initialize(control_panel, name, proc = nil)
|
65
|
+
@control_panel = control_panel
|
66
|
+
super(name.to_s)
|
67
|
+
set_preferred_size(java.awt.Dimension.new(190, 64))
|
68
|
+
set_horizontal_alignment javax.swing.SwingConstants::CENTER
|
69
|
+
control_panel.add_element(self, name, false)
|
70
|
+
add_action_listener do
|
71
|
+
ControlPanel.app_value(name, value)
|
72
|
+
proc.call(value) if proc
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# define value as checkbox state
|
77
|
+
def value
|
78
|
+
is_selected
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Creates button elements for control_panel
|
83
|
+
class Button < javax.swing.JButton
|
84
|
+
def initialize(control_panel, name, proc = nil)
|
85
|
+
super(name.to_s)
|
86
|
+
set_preferred_size(java.awt.Dimension.new(170, 64))
|
87
|
+
control_panel.add_element(self, name, false, true)
|
88
|
+
add_action_listener do
|
89
|
+
Processing.app.send(name)
|
90
|
+
proc.call(value) if proc
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# class used to contain control_panel elements
|
96
|
+
class Panel < javax.swing.JFrame
|
97
|
+
java_import javax.swing.UIManager
|
98
|
+
|
99
|
+
attr_accessor :elements, :panel
|
100
|
+
|
101
|
+
def initialize
|
102
|
+
super()
|
103
|
+
@elements = []
|
104
|
+
@panel = javax.swing.JPanel.new(java.awt.FlowLayout.new(1, 0, 0))
|
105
|
+
feel
|
106
|
+
end
|
107
|
+
|
108
|
+
def display
|
109
|
+
add panel
|
110
|
+
set_size 200, 30 + (64 * elements.size)
|
111
|
+
set_default_close_operation javax.swing.JFrame::HIDE_ON_CLOSE
|
112
|
+
set_resizable false
|
113
|
+
xoffset = Processing.app.width + 10
|
114
|
+
set_location(xoffset, 0) unless xoffset > Processing.app.displayWidth
|
115
|
+
panel.visible = true
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_element(element, name, has_label = true, _button_ = false)
|
119
|
+
if has_label
|
120
|
+
label = javax.swing.JLabel.new("<html><br><b>#{name}</b></html>")
|
121
|
+
panel.add label
|
122
|
+
end
|
123
|
+
elements << element
|
124
|
+
panel.add element
|
125
|
+
has_label ? label : nil
|
126
|
+
end
|
127
|
+
|
128
|
+
def remove
|
129
|
+
remove_all
|
130
|
+
dispose
|
131
|
+
end
|
132
|
+
|
133
|
+
def title(name)
|
134
|
+
set_title(name)
|
135
|
+
end
|
136
|
+
|
137
|
+
def slider(name, range = 0..100, initial = nil, &block)
|
138
|
+
Slider.new(self, name, range, initial, block || nil)
|
139
|
+
end
|
140
|
+
|
141
|
+
def menu(name, elements, initial_value = nil, &block)
|
142
|
+
Menu.new(self, name, elements, initial_value, block || nil)
|
143
|
+
end
|
144
|
+
|
145
|
+
def checkbox(name, initial_value = false, &block)
|
146
|
+
checkbox = Checkbox.new(self, name, block || nil)
|
147
|
+
checkbox.do_click if initial_value == true
|
148
|
+
end
|
149
|
+
|
150
|
+
def button(name, &block)
|
151
|
+
Button.new(self, name, block || nil)
|
152
|
+
end
|
153
|
+
|
154
|
+
def look_feel(lf)
|
155
|
+
feel(lf)
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def feel(lf = 'metal')
|
161
|
+
lafinfo = javax.swing.UIManager.getInstalledLookAndFeels
|
162
|
+
laf = lafinfo.to_ary.find do |info|
|
163
|
+
info.name =~ Regexp.new(Regexp.escape(lf), Regexp::IGNORECASE)
|
164
|
+
end
|
165
|
+
javax.swing.UIManager.setLookAndFeel(laf.class_name)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# instance methods module
|
170
|
+
module InstanceMethods
|
171
|
+
def control_panel
|
172
|
+
@control_panel ||= ControlPanel::Panel.new
|
173
|
+
return @control_panel unless block_given?
|
174
|
+
yield(@control_panel)
|
175
|
+
@control_panel.display
|
176
|
+
@control_panel.set_visible true
|
177
|
+
@control_panel # for legacy compat
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
Processing::App.include(ControlPanel::InstanceMethods)
|