ruby-processing 2.4.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rpextras.jar +0 -0
- data/lib/ruby-processing.rb +8 -6
- data/lib/ruby-processing/app.rb +54 -67
- data/lib/ruby-processing/config.rb +7 -7
- data/lib/ruby-processing/exporters/application_exporter.rb +37 -38
- data/lib/ruby-processing/exporters/base_exporter.rb +34 -37
- data/lib/ruby-processing/exporters/creator.rb +27 -25
- data/lib/ruby-processing/helper_methods.rb +18 -22
- data/lib/ruby-processing/helpers/numeric.rb +5 -6
- data/lib/ruby-processing/helpers/string.rb +11 -20
- data/lib/ruby-processing/library_loader.rb +33 -35
- data/lib/ruby-processing/runner.rb +118 -65
- data/lib/ruby-processing/runners/base.rb +21 -26
- data/lib/ruby-processing/runners/live.rb +3 -4
- data/lib/ruby-processing/runners/run.rb +1 -3
- data/lib/ruby-processing/runners/watch.rb +8 -8
- data/lib/ruby-processing/version.rb +1 -1
- data/lib/templates/application/lib/args.txt.erb +1 -1
- data/lib/templates/application/run.erb +3 -3
- data/library/control_panel/control_panel.rb +29 -29
- data/library/fastmath/fastmath.rb +3 -0
- data/library/file_chooser/file_chooser.rb +11 -13
- data/library/vecmath/vecmath.rb +6 -35
- data/samples/Rakefile +3 -1
- data/samples/configRP5/configRP5.pde +150 -0
- data/samples/contributed/Rakefile +6 -6
- data/samples/contributed/animator.rb +6 -6
- data/samples/contributed/bezier_playground.rb +29 -68
- data/samples/contributed/circle_collision.rb +6 -13
- data/samples/contributed/elegant_ball.rb +14 -17
- data/samples/contributed/empathy.rb +8 -5
- data/samples/contributed/fibonacci_sphere.rb +10 -49
- data/samples/contributed/full_screen.rb +1 -1
- data/samples/contributed/grapher.rb +10 -9
- data/samples/contributed/gravity.rb +11 -16
- data/samples/contributed/jwishy.rb +18 -20
- data/samples/contributed/quadraticvertex.rb +26 -26
- data/samples/external_library/java_processing/custom/landscape.rb +6 -4
- data/samples/external_library/java_processing/hemesh/twin_iso.rb +69 -71
- data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +57 -0
- data/samples/external_library/java_processing/pbox2d/contact_test.rb +23 -0
- data/samples/external_library/java_processing/pbox2d/data/java_args.txt +2 -0
- data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +158 -0
- data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +212 -0
- data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +154 -0
- data/samples/external_library/java_processing/pbox2d/liquidy.rb +58 -0
- data/samples/external_library/java_processing/pbox2d/polygons.rb +58 -0
- data/samples/external_library/java_processing/toxiclibs/library/vbo/vbo.rb +52 -0
- data/samples/external_library/java_processing/toxiclibs/model_align.rb +9 -16
- data/samples/processing_app/basics/color/color_wheel.rb +1 -1
- data/samples/processing_app/basics/form/regular_polygon.rb +2 -2
- data/samples/processing_app/basics/form/rgb_cube.rb +2 -2
- data/samples/processing_app/basics/form/shape_primitives.rb +1 -1
- data/samples/processing_app/basics/form/star.rb +2 -2
- data/samples/processing_app/basics/input/clock.rb +21 -16
- data/samples/processing_app/basics/input/storing_input.rb +6 -6
- data/samples/processing_app/basics/math/additive_wave.rb +1 -1
- data/samples/processing_app/basics/math/sine.rb +2 -2
- data/samples/processing_app/basics/math/sine_cosine.rb +1 -1
- data/samples/processing_app/basics/math/sine_wave.rb +1 -1
- data/samples/processing_app/basics/objects/inheritance.rb +2 -0
- data/samples/processing_app/basics/objects/inheritance_two.rb +88 -0
- data/samples/processing_app/basics/objects/module.rb +89 -0
- data/samples/processing_app/{library/vecmath/drawolver.rb → basics/objects/module_two.rb} +1 -1
- data/samples/processing_app/basics/objects/multiple_constructors.rb +5 -0
- data/samples/processing_app/basics/objects/struct.rb +38 -0
- data/samples/processing_app/basics/structure/recursion2.rb +1 -1
- data/samples/processing_app/basics/transform/birds.rb +7 -10
- data/samples/processing_app/basics/transform/library/bird/bird.rb +3 -3
- data/samples/processing_app/basics/transform/rotate.rb +1 -1
- data/samples/processing_app/basics/transform/rotate1.rb +1 -1
- data/samples/processing_app/basics/transform/rotate_x_y.rb +1 -1
- data/samples/processing_app/demos/graphics/bezier_patch.rb +1 -38
- data/samples/processing_app/demos/graphics/trefoil.rb +50 -40
- data/samples/processing_app/demos/graphics/wiggling.rb +36 -38
- data/samples/processing_app/demos/performance/cubic_grid_retained.rb +14 -14
- data/samples/processing_app/demos/performance/esfera.rb +27 -39
- data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
- data/samples/processing_app/library/fastmath/clock.rb +44 -0
- data/samples/processing_app/library/pdf/complex_3D.rb +26 -24
- data/samples/processing_app/library/vecmath/{Rakefile → arcball/Rakefile} +6 -6
- data/samples/processing_app/library/vecmath/arcball/arcball_box.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_radius.rb +23 -0
- data/samples/processing_app/library/vecmath/arcball/arcball_shape.rb +29 -0
- data/samples/processing_app/library/vecmath/{README.txt → vec2d/README.txt} +0 -0
- data/samples/processing_app/library/vecmath/vec2d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/{acceleration_with_vectors.rb → vec2d/acceleration_with_vectors.rb} +4 -5
- data/samples/processing_app/library/vecmath/{bouncing_ball.rb → vec2d/bouncing_ball.rb} +9 -15
- data/samples/processing_app/library/vecmath/{circle_collision.rb → vec2d/circle_collision.rb} +46 -51
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/java_args.txt +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/sprite.png +0 -0
- data/samples/processing_app/library/vecmath/{data → vec2d/data}/texture.png +0 -0
- data/samples/processing_app/library/vecmath/{flocking.rb → vec2d/flocking.rb} +3 -6
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/flock/flock.rb +47 -67
- data/samples/processing_app/library/vecmath/{library → vec2d/library}/particle/particle_system.rb +5 -5
- data/samples/processing_app/library/vecmath/vec2d/library/tile/tile.rb +85 -0
- data/samples/processing_app/library/vecmath/{morph.rb → vec2d/morph.rb} +17 -16
- data/samples/processing_app/library/vecmath/{multiple_particle_systems.rb → vec2d/multiple_particle_systems.rb} +11 -28
- data/samples/processing_app/library/vecmath/{particle_system_pshape.rb → vec2d/particle_system_pshape.rb} +4 -6
- data/samples/processing_app/library/vecmath/vec2d/penrose.rb +71 -0
- data/samples/processing_app/library/vecmath/{reflection1.rb → vec2d/reflection1.rb} +6 -6
- data/samples/processing_app/library/vecmath/{seeking_neural.rb → vec2d/seeking_neural.rb} +12 -16
- data/samples/processing_app/library/vecmath/{simple_particle_system.rb → vec2d/simple_particle_system.rb} +8 -12
- data/samples/processing_app/library/vecmath/{smoke_particle_system.rb → vec2d/smoke_particle_system.rb} +8 -13
- data/samples/processing_app/library/vecmath/{vector_math.rb → vec2d/vector_math.rb} +0 -0
- data/samples/processing_app/library/vecmath/{library/wiggler/wiggler.rb → vec2d/wiggle_pshape.rb} +28 -4
- data/samples/processing_app/library/vecmath/vec3d/Rakefile +30 -0
- data/samples/processing_app/library/vecmath/vec3d/drawolver.rb +86 -0
- data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +103 -0
- data/samples/processing_app/library/vecmath/{hilbert_fractal.rb → vec3d/hilbert_fractal.rb} +5 -33
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/geometry.rb +3 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/cylinder.rb +44 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/mat4.rb +28 -0
- data/samples/processing_app/library/vecmath/vec3d/library/geometry/lib/plane.rb +60 -0
- data/samples/processing_app/library/vecmath/{library → vec3d/library}/hilbert/hilbert.rb +14 -17
- data/samples/processing_app/library/vecmath/{retained_menger.rb → vec3d/retained_menger.rb} +20 -55
- data/samples/processing_app/topics/advanced_data/Rakefile +6 -6
- data/samples/processing_app/topics/advanced_data/counting_words.rb +7 -7
- data/samples/processing_app/topics/advanced_data/data/data.xml +0 -15
- data/samples/processing_app/topics/advanced_data/data/struct_data.yml +5 -0
- data/samples/processing_app/topics/advanced_data/library/bubble/bubble.rb +8 -8
- data/samples/processing_app/topics/advanced_data/load_save_XML.rb +41 -42
- data/samples/processing_app/topics/advanced_data/load_save_json.rb +11 -11
- data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +22 -23
- data/samples/processing_app/topics/advanced_data/load_save_table.rb +12 -12
- data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +10 -12
- data/samples/processing_app/topics/advanced_data/regex.rb +5 -6
- data/samples/processing_app/topics/advanced_data/threads.rb +27 -27
- data/samples/processing_app/topics/advanced_data/threads_two.rb +3 -2
- data/samples/processing_app/topics/advanced_data/word_frequency.rb +18 -16
- data/samples/processing_app/topics/advanced_data/yahoo_weather.rb +6 -5
- data/samples/processing_app/topics/animation/animated_sprite.rb +9 -7
- data/samples/processing_app/topics/animation/sequential.rb +19 -19
- data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +1 -1
- data/samples/processing_app/topics/cellular_automata/wolfram.rb +1 -1
- data/samples/processing_app/topics/create_shapes/begin_end_contour.rb +1 -1
- data/samples/processing_app/topics/create_shapes/library/wiggler/wiggler.rb +4 -4
- data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +2 -2
- data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_pshape_oo3.rb +1 -1
- data/samples/processing_app/topics/create_shapes/polygon_shape.rb +3 -3
- data/samples/processing_app/topics/file_io/load_file1.rb +1 -1
- data/samples/processing_app/topics/file_io/save_frames.rb +5 -5
- data/samples/processing_app/topics/file_io/save_one_image.rb +2 -2
- data/samples/processing_app/topics/file_io/tile_images.rb +1 -1
- data/samples/processing_app/topics/gui/scrollbar.rb +3 -3
- data/samples/processing_app/topics/image_processing/blending.rb +13 -13
- data/samples/processing_app/topics/image_processing/blur.rb +1 -1
- data/samples/processing_app/topics/image_processing/brightness.rb +1 -1
- data/samples/processing_app/topics/image_processing/convolution.rb +1 -1
- data/samples/processing_app/topics/image_processing/edge_detection.rb +4 -4
- data/samples/processing_app/topics/image_processing/explode.rb +1 -1
- data/samples/processing_app/topics/image_processing/extrusion.rb +1 -1
- data/samples/processing_app/topics/image_processing/histogram.rb +1 -1
- data/samples/processing_app/topics/image_processing/linear_image.rb +1 -1
- data/samples/processing_app/topics/image_processing/pixel_array.rb +1 -1
- data/samples/processing_app/topics/image_processing/zoom.rb +2 -2
- data/samples/processing_app/topics/lsystems/Rakefile +6 -6
- data/samples/processing_app/topics/lsystems/chequer.rb +4 -10
- data/samples/processing_app/topics/lsystems/csplant.rb +25 -25
- data/samples/processing_app/topics/lsystems/cstest.rb +9 -4
- data/samples/processing_app/topics/lsystems/david_tour.rb +14 -16
- data/samples/processing_app/topics/lsystems/koch.rb +8 -18
- data/samples/processing_app/topics/lsystems/library/cs_grammar/cs_grammar.rb +18 -24
- data/samples/processing_app/topics/lsystems/library/grammar/grammar.rb +7 -9
- data/samples/processing_app/topics/lsystems/library/koch/koch_fractal.rb +75 -94
- data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +11 -13
- data/samples/processing_app/topics/lsystems/mpeano.rb +29 -32
- data/samples/processing_app/topics/lsystems/peano.rb +19 -21
- data/samples/processing_app/topics/lsystems/penrose.rb +31 -37
- data/samples/processing_app/topics/lsystems/penrose_snowflake.rb +10 -15
- data/samples/processing_app/topics/lsystems/pentagonal.rb +20 -23
- data/samples/processing_app/topics/lsystems/snake_kolam.rb +13 -13
- data/samples/processing_app/topics/lsystems/stochastic_test.rb +25 -28
- data/samples/processing_app/topics/lsystems/three_d_tree.rb +25 -24
- data/samples/processing_app/topics/motion/bouncy_bubbles.rb +17 -17
- data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -3
- data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
- data/samples/processing_app/topics/motion/reflection2.rb +1 -1
- data/samples/processing_app/topics/shaders/blur_filter.rb +3 -3
- data/samples/processing_app/topics/shaders/bw_shader.rb +3 -3
- data/samples/processing_app/topics/shaders/conway.rb +5 -5
- data/samples/processing_app/topics/shaders/deform.rb +5 -5
- data/samples/processing_app/topics/shaders/edge_detect.rb +3 -5
- data/samples/processing_app/topics/shaders/glossy_fish_eye.rb +15 -21
- data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +21 -19
- data/samples/processing_app/topics/shaders/image_mask.rb +6 -6
- data/samples/processing_app/topics/shaders/landscape.rb +4 -4
- data/samples/processing_app/topics/shaders/monjori.rb +15 -15
- data/samples/processing_app/topics/shaders/nebula.rb +3 -3
- data/samples/processing_app/topics/shaders/sep_blur.rb +15 -15
- data/samples/processing_app/topics/shaders/toon_shading.rb +2 -2
- data/samples/processing_app/topics/simulate/chain.rb +16 -14
- data/samples/processing_app/topics/simulate/smoke_particle_system.rb +3 -3
- data/samples/processing_app/topics/vectors/acceleration_with_vectors.rb +3 -2
- data/samples/processing_app/topics/vectors/bouncing_ball.rb +1 -0
- data/samples/processing_app/topics/vectors/vector_math.rb +2 -1
- data/vendors/Rakefile +15 -3
- metadata +99 -86
- data/.gitignore +0 -13
- data/.travis.yml +0 -6
- data/.yardopts +0 -5
- data/CHANGELOG +0 -316
- data/CONTRIBUTING.md +0 -35
- data/Gemfile +0 -6
- data/LICENSE.md +0 -39
- data/README.md +0 -119
- data/Rakefile +0 -37
- data/bin/install_jruby_complete +0 -13
- data/lib/ruby-processing/exporters/exporters.rb +0 -7
- data/library/vecmath/lib/arcball.rb +0 -64
- data/library/vecmath/lib/quaternion.rb +0 -62
- data/library/vecmath/lib/vec.rb +0 -232
- data/ruby-processing.gemspec +0 -54
- data/samples/processing_app/library/pdf/.gitignore +0 -1
- data/samples/processing_app/library/vecmath/retained_test.rb +0 -65
- data/samples/processing_app/library/vecmath/retained_test2.rb +0 -65
- data/samples/processing_app/library/vecmath/wiggle_pshape.rb +0 -22
- data/test/README.md +0 -6
- data/test/basic.rb +0 -14
- data/test/draw_ex.rb +0 -12
- data/test/graphics.rb +0 -7
- data/test/p2d.rb +0 -14
- data/test/p3d.rb +0 -14
- data/test/rp5_test.rb +0 -86
- data/test/setup_ex.rb +0 -12
data/CONTRIBUTING.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
## Contributing
|
|
2
|
-
In the spirit of [free software][free-sw], **everyone** is encouraged to help improve this project.
|
|
3
|
-
|
|
4
|
-
Here are some ways *you* can contribute:
|
|
5
|
-
|
|
6
|
-
* by reporting bugs
|
|
7
|
-
* by suggesting/implementing new features ( _export to ruboto would be cool_ )
|
|
8
|
-
* by writing or editing documentation ( _expert Windows users could help write install instructions_ )
|
|
9
|
-
* by contributing examples ( _show your creativity, or translate someone elses masterpiece_ )
|
|
10
|
-
* by refactoring examples to be more rubyfied
|
|
11
|
-
* by closing [issues][]
|
|
12
|
-
* by proselytizing ruby-processing, we need more champions
|
|
13
|
-
* by supporting [Processing.org][], nothing to do with us but we rely on them
|
|
14
|
-
* by figuring out if we could replace swing with javafx for control_panel etc
|
|
15
|
-
* by testing / contributing to the [development branch][]
|
|
16
|
-
|
|
17
|
-
## Submitting an Issue
|
|
18
|
-
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
|
19
|
-
submitting a bug report or feature request, check to make sure it hasn't
|
|
20
|
-
already been submitted. When submitting a bug report, ideally include a [Gist][]
|
|
21
|
-
that includes a stack trace and any details that may be necessary to reproduce
|
|
22
|
-
the bug, including your gem version, Ruby version, and operating system.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## Submitting a Pull Request
|
|
26
|
-
1. [Fork the repository.][fork]
|
|
27
|
-
2. [Submit a pull request.][pr]
|
|
28
|
-
|
|
29
|
-
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
|
30
|
-
[issues]: https://github.com/rubygems/gems/issues
|
|
31
|
-
[gist]: https://gist.github.com/
|
|
32
|
-
[fork]: http://help.github.com/fork-a-repo/
|
|
33
|
-
[pr]: http://help.github.com/send-pull-requests/
|
|
34
|
-
[processing.org]: http://processing.org/foundation/
|
|
35
|
-
[development branch]: https://github.com/monkstone/JRubyArt
|
data/Gemfile
DELETED
data/LICENSE.md
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
Ruby-Processing is released under the MIT License.
|
|
2
|
-
You can do pretty much whatever you'd like with it.
|
|
3
|
-
|
|
4
|
-
___
|
|
5
|
-
|
|
6
|
-
Copyright (c) 2008-2014 omygawshkenas
|
|
7
|
-
|
|
8
|
-
Permission is hereby granted, free of charge,
|
|
9
|
-
to any person obtaining a copy of this software
|
|
10
|
-
and associated documentation files (the "Software"),
|
|
11
|
-
to deal in the Software without restriction,
|
|
12
|
-
including without limitation the rights to use,
|
|
13
|
-
copy, modify, merge, publish, distribute, sublicense,
|
|
14
|
-
and/or sell copies of the Software, and to permit
|
|
15
|
-
persons to whom the Software is furnished to do so,
|
|
16
|
-
subject to the following conditions:
|
|
17
|
-
|
|
18
|
-
The above copyright notice and this permission
|
|
19
|
-
notice shall be included in all copies or substantial
|
|
20
|
-
portions of the Software.
|
|
21
|
-
|
|
22
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
|
|
23
|
-
OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
24
|
-
LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
27
|
-
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
28
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
29
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
30
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
31
|
-
|
|
32
|
-
___
|
|
33
|
-
|
|
34
|
-
Ruby-Processing also distributes core components
|
|
35
|
-
of both [JRuby][] and [Processing][] both of which are
|
|
36
|
-
licensed under the GNU lesser public license
|
|
37
|
-
|
|
38
|
-
[jruby]: http://www.jruby.org/
|
|
39
|
-
[processing]: http://www.processing.org/
|
data/README.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# Ruby-Processing
|
|
2
|
-
[](http://badge.fury.io/rb/ruby-processing)
|
|
3
|
-
|
|
4
|
-
Is a ruby wrapper around the [Processing][] code art framework, built using [JRuby][].
|
|
5
|
-
|
|
6
|
-
[Processing][] provides a tidy API, with a bunch of handy methods you can call
|
|
7
|
-
from Ruby-Processing. Here's a smattering:
|
|
8
|
-
|
|
9
|
-
alpha, arc, background, blend, blue, ellipse, frame_rate, hue, lerp,
|
|
10
|
-
load_image, load_pixels, mouse_pressed, noise, rect, saturation, shape,
|
|
11
|
-
smooth, text_align, translate, triangle...
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
MacOSX users please try out this new [method](https://github.com/jashkenas/ruby-processing/wiki/Installing-ruby-processing-on-the-mac)
|
|
15
|
-
|
|
16
|
-
Ideally you should install [jruby](http://jruby.org/download), at the very least you will have at least ruby-1.9.3 installed. You should [download][] and install vanilla [processing-2.0.3](https://processing.org/download/) (MacOSX) or [processing-2.1.0](https://processing.org/download/) (Windows, Linux) prior to installing this version of ruby-processing. You must also set the `PROCESSING_ROOT` in the .rp5rc yaml configuration file, the easiest way to do this is by running the [SetProcessingRoot.pde](https://gist.github.com/monkstone/7438749) sketch in the processing ide.
|
|
17
|
-
|
|
18
|
-
Then install ruby-processing (from rubygems-org) in the usual way
|
|
19
|
-
|
|
20
|
-
`gem install ruby-processing` some systems eg Ubuntu may require `sudo` access
|
|
21
|
-
|
|
22
|
-
To install jruby-complete use our built in tool (relies on `wget` to download [jruby-complete-1.7.11](http://jruby.org/download))
|
|
23
|
-
|
|
24
|
-
`install_jruby_complete`
|
|
25
|
-
|
|
26
|
-
If you haven't got `wget` just download jruby-complete-1.7.11 to the vendors folder (then run above tool)
|
|
27
|
-
|
|
28
|
-
The vendored jruby-complete-1.7.11 is only required for application export, and running certain sketches (eg shader sketches see wiki).
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## Documentation
|
|
32
|
-
|
|
33
|
-
See [Wiki][]
|
|
34
|
-
|
|
35
|
-
See also [FAQs][], [Contributing][] and [Samples][]
|
|
36
|
-
|
|
37
|
-
# Usage Example
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
rp5 run my_sketch.rb
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
or if not using system jruby
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
rp5 --nojruby run my_sketch.rb
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
where a simple ``my_sketch.rb`` could look like this
|
|
50
|
-
|
|
51
|
-
```ruby
|
|
52
|
-
def setup
|
|
53
|
-
size 400, 400
|
|
54
|
-
fill 255
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def draw
|
|
58
|
-
background 0
|
|
59
|
-
ellipse mouse_x, mouse_y, 100, 100
|
|
60
|
-
end
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
or a simple 3D sketch ``cube.rb``
|
|
64
|
-
|
|
65
|
-
```ruby
|
|
66
|
-
def setup
|
|
67
|
-
size 640, 360, P3D
|
|
68
|
-
@xmag = 0
|
|
69
|
-
@ymag = 0
|
|
70
|
-
@new_xmag = 0
|
|
71
|
-
@new_ymag = 0
|
|
72
|
-
fill 200, 50, 50
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def draw
|
|
76
|
-
background 100
|
|
77
|
-
push_matrix
|
|
78
|
-
translate width/2, height/2, -30
|
|
79
|
-
@new_xmag = mouse_x.to_f / width * TWO_PI
|
|
80
|
-
@new_ymag = mouse_y.to_f / height * TWO_PI
|
|
81
|
-
diff = @xmag - @new_xmag
|
|
82
|
-
@xmag -= diff / 4 if diff.abs > 0.01
|
|
83
|
-
diff = @ymag - @new_ymag
|
|
84
|
-
@ymag -= diff / 4 if diff.abs > 0.01
|
|
85
|
-
rotate_x(-@ymag)
|
|
86
|
-
rotate_y(-@xmag)
|
|
87
|
-
box 150, 150, 150
|
|
88
|
-
pop_matrix
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Supported Ruby Version
|
|
94
|
-
|
|
95
|
-
This library has been tested with the following ruby implementations
|
|
96
|
-
|
|
97
|
-
* Ruby 1.9.3
|
|
98
|
-
* Ruby 2.0.0
|
|
99
|
-
* Ruby 2.1.0
|
|
100
|
-
* [JRuby][] preferred (required to use rubygems in sketches)
|
|
101
|
-
|
|
102
|
-
[License][]
|
|
103
|
-
|
|
104
|
-
[license]:LICENSE.md
|
|
105
|
-
[contributing]:CONTRIBUTING.md
|
|
106
|
-
[jruby]:http://www.jruby.org/
|
|
107
|
-
[processing]: http://www.processing.org/
|
|
108
|
-
[download]:https://processing.org/download/
|
|
109
|
-
[samples]:https://github.com/jashkenas/ruby-processing/tree/master/samples/
|
|
110
|
-
[wiki]:http://github.com/jashkenas/ruby-processing/wikis/
|
|
111
|
-
[FAQs]:http://github.com/jashkenas/ruby-processing/wikis/FAQs/
|
|
112
|
-
[release]:https://github.com/jashkenas/ruby-processing/releases/
|
|
113
|
-
|
|
114
|
-
## What's new
|
|
115
|
-
|
|
116
|
-
New capabilities since processing-2.0 include ability to use OPENGL VBO (PShape) and GLSL shaders (PShader), to keep abreast of latest shader developments for processing check out the [codeanticode blog](http://codeanticode.wordpress.com/2013/06/04/processing-2-0-is-out-processing-2-0-is-in/). Some worked examples using new feature are included in the samples. The update to the latest jruby is also significant as the default is to run with ruby-1.9 support (or even use ruby-2.0 syntax with `compat.version=2.0` in your `.jrubyrc` config), and there have been many performance improvements. Some performance improvements will not be available on the Mac as they require at least java-7+, and there is even more to come with java-8+ (adventurous Mac users can read more about [Oracle java here](http://www.java.com/en/download/faq/java_mac.xml) ). More than 330 worked examples are included in the [Samples][], many of which are rubified version of the examples included with vanilla processing, and or the contributed libraries, additions are welcome. In my experience ruby-processing works even better with the recently released jdk-8 (try `-XX:+TieredCompilation` option in java_args.txt). But please note you will not be able to use jdk-8 with vanilla-processing, at least for the forseeable future.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
data/Rakefile
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
desc 'build and test'
|
|
3
|
-
task :default => [:build_and_test]
|
|
4
|
-
|
|
5
|
-
task :build_and_test do
|
|
6
|
-
Rake::Task["build"].execute
|
|
7
|
-
Rake::Task["test"].execute
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
desc 'Build and install gem'
|
|
11
|
-
task :install => :build do
|
|
12
|
-
sh "gem install #{Dir.glob('*.gem').join(' ')} --no-ri --no-rdoc"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
desc 'Uninstall gem'
|
|
16
|
-
task :uninstall do
|
|
17
|
-
sh "gem uninstall -x ruby-processing"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
desc 'Install jruby-complete'
|
|
21
|
-
task :install_jruby_complete do
|
|
22
|
-
begin
|
|
23
|
-
sh "cd vendors && rake"
|
|
24
|
-
rescue
|
|
25
|
-
warn("WARNING: you may not have wget installed")
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
desc 'Build gem'
|
|
30
|
-
task :build do
|
|
31
|
-
sh "gem build ruby-processing.gemspec"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
desc 'Test'
|
|
35
|
-
task :test do
|
|
36
|
-
ruby "test/rp5_test.rb"
|
|
37
|
-
end
|
data/bin/install_jruby_complete
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
file = __FILE__
|
|
4
|
-
if test(?l,file)
|
|
5
|
-
require "pathname"
|
|
6
|
-
file = Pathname.new(file).realpath
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
begin
|
|
10
|
-
system "cd #{File.expand_path(File.dirname(file) +"/../vendors")} && rake"
|
|
11
|
-
rescue
|
|
12
|
-
warn("WARNING: you may not have wget installed, you could just copy jruby complete to vendors folder instead of installing wget")
|
|
13
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require_relative 'vec'
|
|
2
|
-
require_relative 'quaternion'
|
|
3
|
-
|
|
4
|
-
class ArcBall
|
|
5
|
-
attr_reader :center_x, :center_y, :v_down, :v_drag, :q_now, :q_drag, :q_down, :axis, :axis_set, :radius
|
|
6
|
-
|
|
7
|
-
def initialize(cx, cy, radius)
|
|
8
|
-
@center_x = cx
|
|
9
|
-
@center_y = cy
|
|
10
|
-
@radius = radius
|
|
11
|
-
@v_down = Vec3D.new
|
|
12
|
-
@v_drag = Vec3D.new
|
|
13
|
-
@q_now = Quaternion.new
|
|
14
|
-
@q_down = Quaternion.new
|
|
15
|
-
@q_drag = Quaternion.new
|
|
16
|
-
@axis_set = [Vec3D.new(1.0, 0.0, 0.0), Vec3D.new(0.0, 1.0, 0.0), Vec3D.new(0.0, 0.0, 1.0)]
|
|
17
|
-
@axis = -1
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def select_axis(axis)
|
|
21
|
-
@axis = axis
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def mouse2sphere(x, y)
|
|
25
|
-
v = Vec3D.new((x - center_x) / radius, (y - center_y) / radius, 0)
|
|
26
|
-
mag = v.mag
|
|
27
|
-
if (mag > 1.0)
|
|
28
|
-
v.normalize!
|
|
29
|
-
else
|
|
30
|
-
v.z = Math.sqrt(1.0 - mag)
|
|
31
|
-
end
|
|
32
|
-
v = constrain(v, axis_set[axis]) unless (axis == -1)
|
|
33
|
-
return v
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def mouse_pressed(x, y)
|
|
37
|
-
@v_down = mouse2sphere(x, y)
|
|
38
|
-
@q_down.copy(q_now)
|
|
39
|
-
@q_drag.reset
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def mouse_dragged(x, y)
|
|
43
|
-
@v_drag = mouse2sphere(x, y)
|
|
44
|
-
@q_drag.set(v_down.dot(v_drag), v_down.cross(v_drag))
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def constrain(vector, axis)
|
|
49
|
-
res = vector - (axis * axis.dot(vector))
|
|
50
|
-
res.normalize!
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def update
|
|
54
|
-
@q_now = q_drag * q_down
|
|
55
|
-
quat2matrix(q_now)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def quat2matrix(q)
|
|
59
|
-
q.get_value
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require_relative 'vec'
|
|
2
|
-
|
|
3
|
-
class Quaternion
|
|
4
|
-
EPSILON = 9.999999747378752e-05 # a value used by processing.org
|
|
5
|
-
attr_reader :w, :x, :y, :z
|
|
6
|
-
|
|
7
|
-
def initialize(w = 1.0, x = 0, y = 0, z = 0)
|
|
8
|
-
@w, @x, @y, @z = w, x, y, z
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def ==(quat)
|
|
12
|
-
(w - quat.w).abs < EPSILON && (x - quat.x).abs < EPSILON && (y - quat.y).abs < EPSILON && (z - quat.z).abs < EPSILON
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def reset
|
|
17
|
-
@w = 1.0
|
|
18
|
-
@x = 0.0
|
|
19
|
-
@y = 0.0
|
|
20
|
-
@z = 0.0
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def set(w, v)
|
|
24
|
-
@w, @x, @y, @z = w, v.x, v.y, v.z
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def copy(q)
|
|
28
|
-
@w, @x, @y, @z = q.w, q.x, q.y, q.z
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def self.mult(q1, q2) # class method
|
|
32
|
-
x0 = q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y
|
|
33
|
-
y0 = q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z
|
|
34
|
-
z0 = q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x
|
|
35
|
-
w0 = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z
|
|
36
|
-
Quaternion.new(w0, x0, y0, z0)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def * (q1) # instance method
|
|
40
|
-
x0 = w * q1.x + x * q1.w + y * q1.z - z * q1.y
|
|
41
|
-
y0 = w * q1.y + y * q1.w + z * q1.x - x * q1.z
|
|
42
|
-
z0 = w * q1.z + z * q1.w + x * q1.y - y * q1.x
|
|
43
|
-
w0 = w * q1.w - x * q1.x - y * q1.y - z * q1.z
|
|
44
|
-
Quaternion.new(w0, x0, y0, z0)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def get_value
|
|
48
|
-
sa = Math.sqrt(1.0 - w * w)
|
|
49
|
-
sa = 1.0 unless (sa >= EPSILON)
|
|
50
|
-
[Math.acos(w) * 2, x / sa, y / sa, z / sa]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def to_s
|
|
54
|
-
"#{self.class}(w=#{w}, x=#{x}, y=#{y}, z=#{z})"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def inspect
|
|
58
|
-
self.to_s
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
|
data/library/vecmath/lib/vec.rb
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
class Vec2D
|
|
2
|
-
EPSILON = 9.999999747378752e-05 # a value used by processing.org
|
|
3
|
-
attr_accessor :x, :y, :z
|
|
4
|
-
|
|
5
|
-
def initialize(x = 0 ,y = 0, z = 0)
|
|
6
|
-
@x, @y, @z = x, y, z
|
|
7
|
-
post_initialize
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def post_initialize
|
|
11
|
-
nil
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def ==(vec)
|
|
15
|
-
(x - vec.x).abs < EPSILON && (y - vec.y).abs < EPSILON && (z - vec.z).abs < EPSILON
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def self.dist_squared(vec_a, vec_b)
|
|
19
|
-
(vec_a.x - vec_b.x)**2 + (vec_a.y - vec_b.y)**2 + (vec_a.z - vec_b.z)**2
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def self.dist(vec_a, vec_b)
|
|
23
|
-
Math.sqrt((vec_a.x - vec_b.x)**2 + (vec_a.y - vec_b.y)**2 + (vec_a.z - vec_b.z)**2)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def inspect
|
|
27
|
-
self.to_s
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def self.from_angle scalar
|
|
32
|
-
Vec2D.new(Math.cos(scalar), Math.sin(scalar))
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def modulus
|
|
36
|
-
Math.hypot(x, y)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def mag_squared
|
|
40
|
-
x**2 + y**2
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# vanilla processing PVector returns a Vector, rather than Scalar (defaults to 3D result with z = 0)
|
|
44
|
-
def cross(vec)
|
|
45
|
-
x * vec.y - y * vec.x
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Scalar product, also known as inner product or dot product
|
|
49
|
-
def dot(vec)
|
|
50
|
-
x * vec.x + y * vec.y
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def collinear_with?(vec)
|
|
54
|
-
cross(vec).abs < EPSILON
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def +(vec)
|
|
58
|
-
Vec2D.new(x + vec.x, y + vec.y)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def -(vec)
|
|
62
|
-
Vec2D.new(x - vec.x, y - vec.y)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def *(scalar)
|
|
66
|
-
Vec2D.new(x * scalar, y * scalar)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def / (scalar)
|
|
70
|
-
Vec2D.new(x / scalar, y / scalar) unless scalar == 0
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# @param [Vec2D] vec
|
|
74
|
-
# The target vector
|
|
75
|
-
# @param [Float] scalar
|
|
76
|
-
# @return [Vec2D]
|
|
77
|
-
# A new Vec2D on the way to the target (all the way if scalar not in 0 .. 1.0)
|
|
78
|
-
|
|
79
|
-
def lerp(vec, scalar)
|
|
80
|
-
if (0 .. 1.0).include? scalar
|
|
81
|
-
x0, y0 = x * scalar + vec.x * (1 - scalar), y * scalar + vec.y * (1 - scalar)
|
|
82
|
-
else
|
|
83
|
-
x0, y0 = vec.x, vec.y # you will get there rather quicker than you hoped
|
|
84
|
-
end
|
|
85
|
-
Vec2D.new(x0, y0)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Change the values of current Vec2D toward a target
|
|
89
|
-
# @param [Vec2D] vec
|
|
90
|
-
# The target vector
|
|
91
|
-
# @param [Float] scalar
|
|
92
|
-
# @return [Vec2D]
|
|
93
|
-
# self Vec2D on the way to the target (unchanged if scalar not in 0 .. 1.0)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def lerp!(vec, scalar)
|
|
97
|
-
@x, @y = x * scalar + vec.x * (1 - scalar), y * scalar + vec.y * (1 - scalar) if (0 .. 1.0).include? scalar
|
|
98
|
-
return self
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def heading
|
|
102
|
-
Math.atan2(-y, x) * -1.0
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def normalize
|
|
106
|
-
magnitude = Math.hypot(x, y)
|
|
107
|
-
Vec2D.new( x / magnitude, y / magnitude)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def normalize!
|
|
111
|
-
magnitude = Math.hypot(x, y)
|
|
112
|
-
@x, @y = x / magnitude, y / magnitude
|
|
113
|
-
return self
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# The &block option means we can conditionally set_mag to
|
|
117
|
-
# a limit value for example, when given &block returns true.
|
|
118
|
-
|
|
119
|
-
def set_mag(scalar, &block)
|
|
120
|
-
if block_given? && yield == false
|
|
121
|
-
return self
|
|
122
|
-
end
|
|
123
|
-
magnitude = Math.hypot(x, y)
|
|
124
|
-
@x, @y = (x * scalar) / magnitude, (y * scalar) / magnitude
|
|
125
|
-
return self
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def to_a
|
|
129
|
-
[x, y]
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def to_s
|
|
133
|
-
"#{self.class}(x=#{x}, y=#{y})"
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
alias :mag :modulus
|
|
137
|
-
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
class Vec2DR < Vec2D
|
|
141
|
-
|
|
142
|
-
def rotate(rot)
|
|
143
|
-
Vec2D.new((x * Math.cos(rot)) - y * Math.sin(rot),
|
|
144
|
-
(x * Math.sin(rot)) + (y * Math.cos(rot)))
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
# this behaves like PVector rotate (ie changes self, except returns self rather than "void")
|
|
148
|
-
def rotate!(rot)
|
|
149
|
-
@x, @y = (x * Math.cos(rot) - y * Math.sin(rot)), (x * Math.sin(rot) + y * Math.cos(rot))
|
|
150
|
-
return self
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
class Vec3D < Vec2D
|
|
155
|
-
|
|
156
|
-
def mag_squared
|
|
157
|
-
x**2 + y**2 + z**2
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def modulus
|
|
161
|
-
Math.sqrt(x**2 + y**2 + z**2)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def cross(vec)
|
|
165
|
-
xc = y * vec.z - z * vec.y
|
|
166
|
-
yc = z * vec.x - x * vec.z
|
|
167
|
-
zc = x * vec.y - y * vec.x
|
|
168
|
-
Vec3D.new(xc, yc, zc)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
# Scalar product, also known as inner product or dot product
|
|
172
|
-
def dot(vec)
|
|
173
|
-
x * vec.x + y * vec.y + z * vec.z
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def collinear_with?(vec)
|
|
177
|
-
cross(vec) == Vec3D.new
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def to_a
|
|
181
|
-
[x, y, z]
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
def +(vec)
|
|
185
|
-
Vec3D.new(x + vec.x, y + vec.y, z + vec.z)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def -(vec)
|
|
189
|
-
Vec3D.new(x - vec.x, y - vec.y, z - vec.z)
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def * (scalar)
|
|
193
|
-
Vec3D.new(x * scalar, y * scalar, z * scalar)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def / (scalar)
|
|
197
|
-
Vec3D.new(x / scalar, y / scalar, z / scalar) unless scalar.abs < EPSILON
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def normalize
|
|
201
|
-
magnitude = Math.sqrt(x**2 + y**2 + z**2)
|
|
202
|
-
Vec3D.new( x / magnitude, y / magnitude, z / magnitude)
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
def normalize!
|
|
206
|
-
magnitude = Math.sqrt(x**2 + y**2 + z**2)
|
|
207
|
-
@x, @y, @z = x / magnitude, y / magnitude, z / magnitude
|
|
208
|
-
return self
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
# The optional &block should evaluate to a boolean
|
|
212
|
-
# if given, the set_mag becomes conditional (eg set max/min)
|
|
213
|
-
|
|
214
|
-
def set_mag(scalar, &block)
|
|
215
|
-
if block_given? && yield == false
|
|
216
|
-
return self
|
|
217
|
-
end
|
|
218
|
-
magnitude = Math.sqrt(x**2 + y**2 + z**2)
|
|
219
|
-
@x, @y, @z = (x * scalar) / magnitude, (y * scalar) / magnitude, (z * scalar) / magnitude
|
|
220
|
-
return self
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def to_s
|
|
224
|
-
"#{self.class}(x=#{x}, y=#{y}, z=#{z})"
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|