picrate 0.0.2-java → 0.0.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/Rakefile +1 -1
- data/docs/_classes/aabb/aabb.md +28 -0
- data/docs/_classes/app/app.md +38 -0
- data/docs/_classes/app_render/app_render.md +93 -0
- data/docs/_classes/arc_ball/arc_ball.md +33 -0
- data/docs/_classes/chooser/chooser.md +56 -0
- data/docs/_classes/deglut/deglut.md +20 -0
- data/docs/_classes/library_proxy/library_proxy.md +76 -0
- data/docs/_classes/vec2d/vec2d.md +53 -0
- data/docs/_classes/vec3d/vec3d.md +53 -0
- data/docs/_config.yml +36 -7
- data/docs/_editors/vim.md +63 -0
- data/docs/_gems/gems/gems.md +29 -0
- data/docs/_gems/other_gems/other_gems.md +198 -0
- data/docs/_layouts/post.html +6 -6
- data/docs/_libraries/control_panel.md +137 -0
- data/docs/_libraries/custom.md +126 -0
- data/docs/_libraries/custom_java.md +162 -0
- data/docs/_libraries/gems.md +57 -0
- data/docs/_libraries/library_proxy.md +9 -0
- data/docs/_libraries/picrate.md +511 -0
- data/docs/_libraries/processing.md +126 -0
- data/docs/_libraries/vector_utils.md +126 -0
- data/docs/_magic/java.md +30 -0
- data/docs/_magic/jruby.md +105 -0
- data/docs/_magic/processing.md +297 -0
- data/docs/_magic/ruby.md +31 -0
- data/docs/_methods/alternative_methods.md +66 -0
- data/docs/_methods/color.md +109 -0
- data/docs/_methods/data_path.md +109 -0
- data/docs/_methods/draw.md +20 -0
- data/docs/_methods/key_pressed.md +27 -0
- data/docs/_methods/library_loader.md +49 -0
- data/docs/_methods/map1d.md +77 -0
- data/docs/_methods/methods_summary.md +103 -0
- data/docs/_methods/mouse_pressed.md +25 -0
- data/docs/_methods/post_initialize.md +9 -0
- data/docs/_methods/processing_api.md +46 -0
- data/docs/_methods/settings.md +48 -0
- data/docs/_methods/setup.md +36 -0
- data/docs/_methods/sketch_title.md +24 -0
- data/docs/_modules/custom.md +61 -0
- data/docs/_modules/helper_methods.md +10 -0
- data/docs/_modules/interface.md +66 -0
- data/docs/_modules/processing.md +7 -0
- data/docs/_modules/processing_proxy.md +28 -0
- data/docs/_objects/class/class.md +7 -0
- data/docs/_objects/global/global.md +7 -0
- data/docs/_objects/instance/instance.md +74 -0
- data/docs/_objects/numeric/numeric.md +37 -0
- data/docs/_posts/2018-05-06-getting_started.md +60 -0
- data/docs/_posts/2018-05-06-processing-api.md +68 -0
- data/docs/_posts/2018-05-11-arch-linux-arm.md +17 -0
- data/docs/about.md +7 -1
- data/docs/classes.md +10 -0
- data/docs/editors.md +10 -0
- data/docs/gems.md +11 -0
- data/docs/libraries.md +20 -0
- data/docs/magic.md +11 -0
- data/docs/methods.md +10 -0
- data/docs/modules.md +12 -0
- data/docs/objects.md +9 -0
- data/lib/picrate/version.rb +1 -1
- data/lib/picrate-0.0.3.jar +0 -0
- data/picrate.gemspec +2 -2
- data/pom.rb +1 -1
- data/pom.xml +7 -7
- data/src/main/java/monkstone/MathToolModule.java +2 -2
- data/src/main/java/monkstone/videoevent/VideoInterface.java +1 -1
- data/src/main/java/processing/core/PApplet.java +3 -3
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +1 -1
- data/test/respond_to_test.rb +4 -4
- data/test/sketches/key_event.rb +3 -3
- data/vendors/Rakefile +1 -1
- metadata +61 -4
- data/lib/picrate-0.0.2.jar +0 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "color explained"
|
4
|
+
permalink: methods/color.html
|
5
|
+
---
|
6
|
+
### processing ###
|
7
|
+
The `*.pde` files get pre-processed to `java` before compiling, allowing you to write this:-
|
8
|
+
|
9
|
+
```java
|
10
|
+
color c2 = #FFCC00; // this gets pre-processed to `int c2 = 0xffFFCC00`
|
11
|
+
```
|
12
|
+
This is yet another vanilla `processing` convention that you must learn to get around once you leave the processing ide.
|
13
|
+
|
14
|
+
### propane / JRubyArt ###
|
15
|
+
|
16
|
+
in ruby we instead support use of quoted web-string (string is at least a valid type in ruby and java)
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
c2 = color('#FFCC00') # we return a signed java int, note quoted string
|
20
|
+
```
|
21
|
+
|
22
|
+
For propane we enable a convenience method color (based on processing PGraphics color), and for the most part this method behaves as the processing color method (but it is implemented differently under the hood to work with ruby Numeric/Fixnum). Basically the input can be an Array of Fixnum (approximating to a processing int) an Array of Float (approximating to processing float) or a special hexadecimal string or a hexadecimal number. See / try example sketch.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
|
26
|
+
#!/usr/bin/env jruby -w
|
27
|
+
# frozen_string_literal: true
|
28
|
+
# Creating Colors (Homage to Albers).
|
29
|
+
#
|
30
|
+
require 'picrate'
|
31
|
+
|
32
|
+
# Creating variables for colors that may be referred to
|
33
|
+
# in the program by their name, rather than a number.
|
34
|
+
class CreatingColors < Processing::App
|
35
|
+
attr_reader :redder, :yellower, :orangish
|
36
|
+
WEB = %w(#CC6600 #CC9900 #993300)
|
37
|
+
|
38
|
+
def settings
|
39
|
+
size 640, 360
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup
|
43
|
+
sketch_title 'Homage to Albers'
|
44
|
+
palette = web_to_color_array(WEB)
|
45
|
+
@redder = palette[0]
|
46
|
+
@yellower = palette[1]
|
47
|
+
@orangish = palette[2]
|
48
|
+
# These statements are equivalent to the statements above.
|
49
|
+
# Programmers may use the format they prefer.
|
50
|
+
|
51
|
+
# hex color as a String (NB quotes are required)
|
52
|
+
@redder = palette[0]
|
53
|
+
@yellower = palette[1]
|
54
|
+
@orangish = palette[2]
|
55
|
+
|
56
|
+
# @redder = color '#CC6600'
|
57
|
+
# @yellower = color '#CC9900'
|
58
|
+
# @orangish = color '#993300'
|
59
|
+
|
60
|
+
# or alternatively as a hexadecimal
|
61
|
+
|
62
|
+
# @redder = color 0xFFCC6600
|
63
|
+
# @yellower = color 0xFFCC9900
|
64
|
+
# @orangish = color 0xFF993300
|
65
|
+
puts int_to_ruby_colors(palette)
|
66
|
+
end
|
67
|
+
|
68
|
+
def draw
|
69
|
+
no_stroke
|
70
|
+
background 51, 0, 0
|
71
|
+
push_matrix
|
72
|
+
translate 80, 80
|
73
|
+
fill orangish
|
74
|
+
rect 0, 0, 200, 200
|
75
|
+
fill yellower
|
76
|
+
rect 40, 60, 120, 120
|
77
|
+
fill redder
|
78
|
+
rect 60, 90, 80, 80
|
79
|
+
pop_matrix
|
80
|
+
push_matrix
|
81
|
+
translate 360, 80
|
82
|
+
fill redder
|
83
|
+
rect 0, 0, 200, 200
|
84
|
+
fill orangish
|
85
|
+
rect 40, 60, 120, 120
|
86
|
+
fill yellower
|
87
|
+
rect 60, 90, 80, 80
|
88
|
+
pop_matrix
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
```
|
93
|
+
|
94
|
+
### Making Necessity into a Virtue ###
|
95
|
+
|
96
|
+
Many vanilla processing libraries (eg Hype, Wordcram and ColorHarmony) make use of the vanilla processing conventions to define `web` colors. But we have gone one better in JRubyArt and propane to use ruby to quickly create arrays of `web` color and even `dictionaries` of `web` colors. Now such lists would be useless unless we could convert the `web` colors to valid `color` int for use in processing as we have with the [web_to_color_array][web] method.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
WEB = %w(#CC6600 #CC9900 #FFFFFF).freeze
|
100
|
+
web_to_color_array(WEB)
|
101
|
+
# output = [-3381760, -3368704, -1]
|
102
|
+
```
|
103
|
+
|
104
|
+
For creation and use of a hash / dictionary of web colors see this [Wordcram sketch][wordcram]. If you need to convert an array of `color` int (say from ColorHarmony) to ruby string, then use `p52ruby` method that returns a web string of the form '%w(#CC6600 #CC9900 #FFFFFF)' from `[-3381760, -3368704, -1]`. Or if you are more sophisticated and using the `toxiclibs` gem to explore color theory, we have created a method `to_ruby_string` for the `ColorList` class see [palette genertor example][palette]
|
105
|
+
|
106
|
+
[palette]:https://github.com/ruby-processing/picrate-examples/blob/master/gems/toxiclibs/color_utils/palette_generator.rb
|
107
|
+
[wordcram]:https://github.com/ruby-processing/picrate-examples/blob/master/gems/ruby_wordcram/fruits.rb
|
108
|
+
[web]:{{site.github.url}}/summary/
|
109
|
+
[processing]:https://processing.org/reference/color_datatype.html
|
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "data_path"
|
4
|
+
date: 2016-05-23 05:04:00
|
5
|
+
categories: picrate update
|
6
|
+
permalink: methods/data_path.html
|
7
|
+
---
|
8
|
+
The purpose of the `data_path` wrapper is to provide the absolute data path to a sketches `data` folder. In vanilla processing the direct use of this method is discouraged, owing to the way it has been implemented (it is used internally and may be the cause file access issues in PiCrate). The `data_path` method is implemented in PiCrate, and does not rely on the vanilla-processing version.
|
9
|
+
|
10
|
+
It should be used to get around the need to provide an absolute data path on macosx to run sketches that contain `load_image`, `load_shader` etc that otherwise could not find the data.
|
11
|
+
|
12
|
+
### Simple usage ###
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
#!/usr/bin/env jruby -w
|
16
|
+
require 'picrate'
|
17
|
+
class LoadImage < Processing::App
|
18
|
+
def setup
|
19
|
+
sketch_title 'Load Image'
|
20
|
+
# The file "jelly.jpg" must be in the data folder
|
21
|
+
# of the current sketch to load successfully
|
22
|
+
@a = load_image(data_path('jelly.jpg'))
|
23
|
+
no_loop # Makes draw only run once
|
24
|
+
end
|
25
|
+
|
26
|
+
def draw
|
27
|
+
image @a, 0, 0
|
28
|
+
image @a, @a.width, 0, @a.width / 2, @a.height / 2
|
29
|
+
end
|
30
|
+
|
31
|
+
def settings
|
32
|
+
size 300, 200
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
LoadImage.new
|
37
|
+
```
|
38
|
+
|
39
|
+
NB: it is equally valid to use `data_path` to provide an absolute path to the data folder on save (even when the data folder needs to be created on save).
|
40
|
+
|
41
|
+
### More sophisticated usage ###
|
42
|
+
You can use your ruby knowledge to 'dry up' vanilla processing sketches and to remove the need to type `data_path` many times in a sketch. Please note that we cannot rely on JRuby to convert an array of ruby-string to an array of java-string, this is why we need `glsl_files.to_java(:string)`. However the array of images does not require such an explicit conversion, _JRuby generally just does the right thing_.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
#!/usr/bin/env jruby -w
|
46
|
+
require 'picrate'
|
47
|
+
# Earth model with bump mapping, specular texture and dynamic cloud layer.
|
48
|
+
# Adapted from the THREE.js tutorial to processing by Andres Colubri,
|
49
|
+
# translated to PiCrate by Martin Prout:
|
50
|
+
# http://learningthreejs.com/blog/2013/09/16/how-to-make-the-earth-in-webgl/
|
51
|
+
class BlueMarble < Processing::App
|
52
|
+
attr_reader :earth, :clouds, :earth_shader, :cloud_shader, :earth_rotation
|
53
|
+
attr_reader :clouds_rotation, :target_angle
|
54
|
+
|
55
|
+
SHADERS = %w(EarthFrag.glsl EarthVert.glsl CloudFrag.glsl CloudVert.glsl).freeze
|
56
|
+
SHADER_NAME = %i(earth_frag earth_vert cloud_frag cloud_vert).freeze
|
57
|
+
IMAGES = %w(earthmap1k earthcloudmap earthcloudmaptrans earthbump1k earthspec1k).freeze
|
58
|
+
IMAGE_NAME = %i(earth_tex cloud_tex alpha_tex bump_map spec_map).freeze
|
59
|
+
|
60
|
+
def setup
|
61
|
+
sketch_title 'Blue Marble'
|
62
|
+
@earth_rotation = 0
|
63
|
+
@clouds_rotation = 0
|
64
|
+
glsl_files = SHADERS.map { |shade| data_path(shade) }
|
65
|
+
shaders = SHADER_NAME.zip(glsl_files.to_java(:string)).to_h
|
66
|
+
images = IMAGES.map { |img| load_image(data_path("#{img}.jpg")) }
|
67
|
+
textures = IMAGE_NAME.zip(images).to_h
|
68
|
+
@earth_shader = load_shader(shaders[:earth_frag], shaders[:earth_vert])
|
69
|
+
earth_shader.set('texMap', textures[:earth_tex])
|
70
|
+
earth_shader.set('bumpMap', textures[:bump_map])
|
71
|
+
earth_shader.set('specularMap', textures[:spec_map])
|
72
|
+
earth_shader.set('bumpScale', 0.05)
|
73
|
+
@cloud_shader = load_shader(shaders[:cloud_frag], shaders[:cloud_vert])
|
74
|
+
cloud_shader.set('texMap', textures[:cloud_tex])
|
75
|
+
cloud_shader.set('alphaMap', textures[:alpha_tex])
|
76
|
+
@earth = create_shape(SPHERE, 200)
|
77
|
+
earth.setStroke(false)
|
78
|
+
earth.setSpecular(color(125))
|
79
|
+
earth.setShininess(10)
|
80
|
+
@clouds = create_shape(SPHERE, 201)
|
81
|
+
clouds.setStroke(false)
|
82
|
+
end
|
83
|
+
|
84
|
+
def draw
|
85
|
+
background(0)
|
86
|
+
translate(width / 2, height / 2)
|
87
|
+
point_light(255, 255, 255, 300, 0, 500)
|
88
|
+
target_angle = map1d(mouse_x, (0..width), (0..TWO_PI))
|
89
|
+
@earth_rotation += 0.05 * (target_angle - earth_rotation)
|
90
|
+
shader(earth_shader)
|
91
|
+
push_matrix
|
92
|
+
rotate_y(earth_rotation)
|
93
|
+
shape(earth)
|
94
|
+
pop_matrix
|
95
|
+
shader(cloud_shader)
|
96
|
+
push_matrix
|
97
|
+
rotate_y(earth_rotation + clouds_rotation)
|
98
|
+
shape(clouds)
|
99
|
+
pop_matrix
|
100
|
+
@clouds_rotation += 0.001
|
101
|
+
end
|
102
|
+
|
103
|
+
def settings
|
104
|
+
size(600, 600, P3D)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
BlueMarble.new
|
109
|
+
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "draw"
|
4
|
+
permalink: methods/draw.html
|
5
|
+
---
|
6
|
+
Called directly after setup, the draw function continuously executes the lines of code contained inside its block until the program is stopped or no_loop is called. The number of times draw executes in each second may be controlled with the frame_rate(xxx).
|
7
|
+
|
8
|
+
It is common to call background near the beginning of the [draw loop][draw] to clear the contents of the window. Since pixels drawn to the window are cumulative, omitting background may result in unintended results, especially when drawing anti-aliased shapes or text.
|
9
|
+
|
10
|
+
There can only be one [draw][draw] function for each sketch, and [draw][draw] must exist if you want the code to run continuously, or to process events such as [mouse_pressed][mouse_pressed].
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
def draw
|
14
|
+
background 0
|
15
|
+
# dynamic code
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
[draw]:https://processing.org/reference/draw_.html
|
20
|
+
[mouse_pressed]:https://processing.org/reference/mousePressed_.html
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "key_pressed"
|
4
|
+
permalink: methods/key_pressed.html
|
5
|
+
---
|
6
|
+
In vanilla processing [keyPressed][keyPressed] is both a variable and a method, for PiCrate the boolean variable is available as `key_pressed?`, whereas you can create events/operations that occur on key pressed by adding a `key_pressed` method as below:-
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
def key_pressed
|
10
|
+
# code gets executed on key pressed you can access the `key` variable in this loop
|
11
|
+
case key
|
12
|
+
when 'c', 'C'
|
13
|
+
# do stuff when c is pressed
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
For sketch with `key_pressed` method see [raining][raining], follow link for a sketch using [key_pressed?][key_pressed?] or this [alternative][alternative].
|
18
|
+
|
19
|
+
See also:-
|
20
|
+
|
21
|
+
[key_released][keyReleased]
|
22
|
+
|
23
|
+
[key_pressed?]:https://github.com/ruby-processing/picrate-examples/blob/master/basics/typography/letters.rb
|
24
|
+
[keyPressed]:https://processing.org/reference/keyPressed_.html
|
25
|
+
[keyReleased]:https://processing.org/reference/keyReleased_.html
|
26
|
+
[raining]:https://github.com/ruby-processing/picrate-examples/blob/master/demos/raining.rb
|
27
|
+
[alternative]:https://github.com/ruby-processing/picrate-examples/blob/master/demos/25_squares.rb
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "load_library"
|
4
|
+
keywords: ruby, java, jruby, library, load_library, native
|
5
|
+
permalink: methods/load_library.html
|
6
|
+
---
|
7
|
+
The purpose of the `load_library` (synonym `load_libraries`) method is to provide a convenient way to load the different kinds of ruby [libraries][libraries], and in the case of java libraries that use a native library, load the relevant classpath. It does this by a mixture of pattern matching and honest magic so that you don't need to worry about adding the native libraries to classpath to the java runtime, and lots of other incomprehensible stuff. When it works it is fabulous (which is most of the time on Linux64 bit and MacOS). See examples under [libraries][libraries].
|
8
|
+
|
9
|
+
### Cautionary Notes ###
|
10
|
+
|
11
|
+
Simply loading in the code for a library via `load_library` may not be enough to actually import the library's classes into your namespace. For some libraries, such as __Minim__, you'll want to import the package as well (as you would in Java):
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
load_library 'minim'
|
15
|
+
java_import 'ddf.minim'
|
16
|
+
java_import 'ddf.minim.analysis'
|
17
|
+
include_package 'ddf' # can also be use to "import the ddf package"
|
18
|
+
```
|
19
|
+
|
20
|
+
Some libraries use Java's reflective capacities to try and invoke methods on your sketch. If the methods that they're looking for happen to be defined in Ruby alone, Java won't be able to find them. Better support for this sort of thing may be forthcoming in a future JRuby releases, but for now you'll either need to patch the library to stop using [reflection][reflection] on the sketch, or insert a thin Java interface. For example, the [Carnivore][carnivore] library uses reflection and tries to find a `packetEvent()` method on the sketch. An appropriate fix is to create, compile and jar-up a java interface, and then include it into your sketch. See also how we implement a native [FileChooser][magic] (_reflection can be a pain, and unfortunately those processing guys seem to be dead keen on it_).
|
21
|
+
|
22
|
+
```java
|
23
|
+
public interface PacketListener {
|
24
|
+
public void packetEvent(org.rsg.carnivore.CarnivorePacket packet);
|
25
|
+
}
|
26
|
+
```
|
27
|
+
|
28
|
+
Compile it, jar it up.
|
29
|
+
|
30
|
+
<pre>
|
31
|
+
javac -cp path/to/carnivore.jar PacketListener.java
|
32
|
+
jar cvf packet_listener.jar PacketListener.java
|
33
|
+
</pre>
|
34
|
+
|
35
|
+
And then include it in your sketch...
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'packet_listener'
|
39
|
+
include Java::PacketListener
|
40
|
+
|
41
|
+
def packetEvent(packet)
|
42
|
+
# code goes here...
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
[libraries]:{{ site.github.url }}/libraries.html
|
47
|
+
[carnivore]:http://r-s-g.org/carnivore/installation.html
|
48
|
+
[magic]:{{ site.github.url }}/magic/processing
|
49
|
+
[reflection]:https://docs.oracle.com/javase/tutorial/reflect/
|
@@ -0,0 +1,77 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "map1d in detail"
|
4
|
+
permalink: methods/map1d.html
|
5
|
+
---
|
6
|
+
|
7
|
+
### Name ###
|
8
|
+
|
9
|
+
`map1d` _NB: a different was used than vanilla processing because `map` has another meaning in ruby and we anticipate a possible `map2d` or even `map3d`_.
|
10
|
+
|
11
|
+
### Examples ###
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
#!/usr/bin/env jruby -w
|
15
|
+
require 'picrate'
|
16
|
+
class UsingMap1D < Processing::App
|
17
|
+
def settings
|
18
|
+
size(200, 200)
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
sketch_title 'Using map1d'
|
23
|
+
no_stroke
|
24
|
+
end
|
25
|
+
|
26
|
+
def draw
|
27
|
+
background(204)
|
28
|
+
x1 = map1d(mouse_x, (0..width), (50..150))
|
29
|
+
ellipse(x1, 75, 50, 50)
|
30
|
+
x2 = map1d(mouse_x, (0..width), (0..200))
|
31
|
+
ellipse(x2, 125, 50, 50)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
UsingMap1D.new
|
36
|
+
```
|
37
|
+
|
38
|
+
### Description ###
|
39
|
+
|
40
|
+
Re-maps a number from one range to another.
|
41
|
+
|
42
|
+
As shown in the example, numbers outside of the range are not clamped to the minimum and maximum parameters values, because out-of-range values are often intentional and useful.
|
43
|
+
|
44
|
+
### Syntax ###
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
map1d(value, (start1..stop1), (start2..stop2))
|
48
|
+
```
|
49
|
+
|
50
|
+
### Parameters ###
|
51
|
+
|
52
|
+
value the incoming value to be converted
|
53
|
+
|
54
|
+
start1 lower bound of the value's current range
|
55
|
+
|
56
|
+
stop1 upper bound of the value's current range
|
57
|
+
|
58
|
+
start2 lower bound of the value's target range
|
59
|
+
|
60
|
+
stop2 upper bound of the value's target range
|
61
|
+
|
62
|
+
Returns float
|
63
|
+
|
64
|
+
### Related ###
|
65
|
+
|
66
|
+
`constrained_map` (numbers are clamped to range)
|
67
|
+
|
68
|
+
`p5map` (same signature as [processing map][map])
|
69
|
+
|
70
|
+
`norm` (same as [processing norm][norm])
|
71
|
+
|
72
|
+
`norm_strict` (output is clamped to 0..1.0)
|
73
|
+
|
74
|
+
`lerp`
|
75
|
+
|
76
|
+
[norm]:https://processing.org/reference/norm_.html
|
77
|
+
[map]:https://processing.org/reference/map_.html
|
@@ -0,0 +1,103 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "summary"
|
4
|
+
permalink: methods/summary.html
|
5
|
+
---
|
6
|
+
|
7
|
+
The MathTool and HelperMethods modules implement some of the processing convenience methods
|
8
|
+
|
9
|
+
### color method
|
10
|
+
A convenience method that returns a 'color' int for processing
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
color(*args) # where args can be a hex string, a hexadecimal number, etc. see examples
|
14
|
+
color('#CC6600') # hexadecimal string, can be lower-case
|
15
|
+
color(0xFFCC6600) # hexadecimal
|
16
|
+
color(255) # white
|
17
|
+
color(0) # black
|
18
|
+
color(255, 0, 0) # red
|
19
|
+
color(0, 0, 255) # blue
|
20
|
+
color(0, 0, 255, 100) # blue with alpha value 100
|
21
|
+
```
|
22
|
+
Example Usages: [Creating][color], [Blend Color][blend_color]
|
23
|
+
|
24
|
+
### hsb_color method
|
25
|
+
A convenience method that returns a 'color' int for processing for `hsb` input, where hue, saturation and brightness are in range `0..1.0`
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
hsb_color(hue, sat, bright) # where args are ruby float
|
29
|
+
```
|
30
|
+
|
31
|
+
### web_to_color_array method
|
32
|
+
A convenience method that converts an array of web color strings to an array of 'color' int. Particularly useful when working with the Joshua Davis Processing-HYPE library.
|
33
|
+
```ruby
|
34
|
+
WEB = %w(#CC6600 #CC9900 #FFFFFF).freeze
|
35
|
+
web_to_color_array(WEB)
|
36
|
+
# output = [-3381760, -3368704, -1]
|
37
|
+
```
|
38
|
+
see usage in a [Wordcram sketch][wordcram]
|
39
|
+
|
40
|
+
### p52ruby
|
41
|
+
|
42
|
+
A convenience method that converts an array of 'color' int to a ruby string that you can use in your Wordcram or Hype sketches (say from a ColorHarmony sketch)
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
p52ruby([-3381760, -3368704, -1])
|
46
|
+
# output = "%w(#CC6600 #CC9900 #FFFFFF)\n"
|
47
|
+
```
|
48
|
+
For toxiclibs we have created a new method `to_ruby_string` for the `ColorList` class that does the same thing for a collection of `TColor`
|
49
|
+
See this [toxiclibs sketch][palette] where we use color theory to generate a sketch palette.
|
50
|
+
|
51
|
+
### map1d method
|
52
|
+
A replacement for processings map function, maps val (range1) to range2 using a linear transform.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
map1d(val, range1, range2) # where val is an input float range1 is source and range2 is target
|
56
|
+
# simple example
|
57
|
+
map1d(10, (0..20), (0..1.0)) # returns 0.5
|
58
|
+
```
|
59
|
+
|
60
|
+
Example Usages: [Mandelbrot][mandelbrot], [Game of Life][conway]
|
61
|
+
|
62
|
+
### radians and degrees methods
|
63
|
+
A replacement for processings radians(x) and degree(x) methods _in ruby everything is an object!!_
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
x.radians # we did this by monkey patching ruby numeric
|
67
|
+
x.degrees
|
68
|
+
```
|
69
|
+
|
70
|
+
Note: ruby already provides x.abs, x.to_s, and x.to_f replacing abs(x), str(x), and float(x) etc
|
71
|
+
|
72
|
+
Example Usages:
|
73
|
+
[bezier ellipse][bezier], [brick tower][brick_tower]
|
74
|
+
|
75
|
+
### Processing max and min convenience methods
|
76
|
+
|
77
|
+
We make these methods available in propane, by mocking them using ruby `Enumerable` `max` and `min` methods, you may prefer to use the `Enumerable` methods directly since they are more flexible (you can even provide a [comparator block][enumerable] to change basis of ordering).
|
78
|
+
|
79
|
+
|
80
|
+
### find_method method
|
81
|
+
A convenient way of finding a method
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
find_method(method) # where method is a method name or fragment
|
85
|
+
# simple example
|
86
|
+
puts find_method('map') # see output below
|
87
|
+
```
|
88
|
+
|
89
|
+
```bash
|
90
|
+
constrained_map
|
91
|
+
map1d
|
92
|
+
p5map
|
93
|
+
```
|
94
|
+
|
95
|
+
[palette]:https://github.com/ruby-processing/picrate-examples/blob/master/gems/toxiclibs/color_utils/palette_generator.rb
|
96
|
+
[wordcram]:https://github.com/ruby-processing/picrate-examples/blob/master/gems/ruby_wordcram/fruits.rb
|
97
|
+
[bezier]:https://github.com/ruby-processing/picrate-examples/blob/master//basics/form/bezier_ellipse.rb
|
98
|
+
[brick_tower]:https://github.com/ruby-processing/picrate-examples/blob/master//basics/form/brick_tower.rb
|
99
|
+
[mandelbrot]:https://github.com/ruby-processing/JRubyArt-examples/blob/master/contributed/mandelbrot.rb
|
100
|
+
[conway]:https://github.com/ruby-processing/picrate-examples/blob/master//topics/shaders/conway.rb
|
101
|
+
[color]:https://github.com/ruby-processing/picrate-examples/blob/master//basics/color/creating.rb
|
102
|
+
[blend_color]:https://github.com/ruby-processing/picrate-examples/blob/master//basics/color/blend_color.rb
|
103
|
+
[enumerable]:http://apidock.com/ruby/Enumerable/max
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "mouse_pressed"
|
4
|
+
permalink: methods/mouse_pressed.html
|
5
|
+
---
|
6
|
+
In vanilla processing [mousePressed][mousePressed] is both a variable and a method, for PiCrate the boolean variable is available as `mouse_pressed?`, whereas you can create events/operations that occur on mouse pressed by adding a [mouse_pressed][mouse_pressed] method as below:-
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
def mouse_pressed
|
10
|
+
# code gets executed on mouse pressed
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
14
|
+
For sketch with mouse_pressed method see [drawolver][drawolver], follow link for a sketch using [mouse_pressed?][mouse_pressed?].
|
15
|
+
|
16
|
+
See also:-
|
17
|
+
|
18
|
+
[mouse_released][mouse_released], [mouse_dragged][mouse_dragged], [mouse_clicked][mouse_clicked]
|
19
|
+
|
20
|
+
[mouse_pressed?]:https://github.com/ruby-processing/JRubyArt-examples/blob/master/basics/input/mouse_press.rb
|
21
|
+
[mousePressed]:https://processing.org/reference/mousePressed_.html
|
22
|
+
[drawolver]:https://github.com/ruby-processing/picrate-examples/blob/master/demos/drawolver.rb
|
23
|
+
[mouse_released]:https://github.com/ruby-processing/picrate-examples/blob/master/demos/bezier_playground.rb
|
24
|
+
[mouse_dragged]:https://github.com/ruby-processing/picrate-examples/blob/master/demos/bezier_playground.rb
|
25
|
+
[mouse_clicked]:https://github.com/ruby-processing/picrate-examples/blob/master/demos/fibonacci_sphere.rb
|
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "post_initialize"
|
4
|
+
permalink: methods/post_initialize.html
|
5
|
+
---
|
6
|
+
We have provided a `post_initialize` for a propane sketch, which allows you to send parameter options to your sketch via initialize, and really only makes sense when you explicitly create an instance of your sketch. The `post_initialize` method is a hook that avoids you needing to call super on initialize. At present we haven't got an examples to show you, but see this is an alternative
|
7
|
+
[hook example][hook].
|
8
|
+
|
9
|
+
[hook]:https://github.com/ruby-processing/picrate-examples/tree/master/processing_app/topics/ruby_hook
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "processing API"
|
4
|
+
permalink: methods/processingapi.html
|
5
|
+
---
|
6
|
+
Most of the processing methods, as explained in the [Processing Language API][api], are available as instance methods to the Processing::App. (frame_rate, ellipse, many others). But there are [exceptions][alternatives] see below and [here][alternatives], where good or better alternatives already exist in ruby. Also make sure you take a look at the many [included example sketches][sketches], where ruby [core][core] and [Math][Math] methods are preferred over the processing/java alternative eg `rand(0.0..4)` is preferred over `random(0, 4.0)`.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
#!/usr/bin/env jruby -w
|
10
|
+
require 'picrate'
|
11
|
+
class TrianglesGoneWild < Processing::App
|
12
|
+
def settings
|
13
|
+
size 600, 600
|
14
|
+
smooth 8
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
sketch_title 'Triangles Gone Wild'
|
19
|
+
color_mode RGB, 1.0
|
20
|
+
frame_rate 30
|
21
|
+
fill 0.8, 0.6
|
22
|
+
end
|
23
|
+
|
24
|
+
def draw
|
25
|
+
triangle(rand(width), rand(height), rand(width), rand(height), rand(width), rand(height))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
TrianglesGoneWild.new
|
30
|
+
```
|
31
|
+
|
32
|
+
Some variables that you might expect to find under their Processing names are available by more rubyish names, `keyPressed` becomes `key_pressed?` and `mousePressed` becomes `mouse_pressed?`. The functions `keyPressed`, `mousePressed` become `key_pressed` and `mouse_pressed` ie without `?`. And some things are better done with regular Ruby than with Processing; instead of using `load_strings('file.txt')` to read in a file, consider `File.readlines('file.txt')`. For math use `x.to_f`, `x.radians` and `x**3` for `float(x)`, `radians(x)` and `pow(x, 3)`.
|
33
|
+
|
34
|
+
Because of this method madness, `Processing::App` has a convenience method for searching through them. `find_method('ellipse')` will return a list of the method names that may match what you're looking for: 'ellipse', 'ellipseMode', and 'ellipse_mode'. Please note this is an instance method, so from irb or pry use `Propane.app.find_method 'ellipse'` on a loaded sketch. Alternatively add `puts find_method 'ellipse'` at the end of your `setup` method (or `draw` but only with `no_loop`).
|
35
|
+
|
36
|
+
Also prefer [`Vec2D`][vec2] and [`Vec3D`][vec3] to [`PVector`][pvector] follow links for reference. Also you can/should use `data_path` to wrap filenames (propane uses ruby to access the absolute_path of files in the sketch data folder, this avoids the file permission issues of the vanilla-processing method).
|
37
|
+
|
38
|
+
[api]:https://processing.org/reference/index.html
|
39
|
+
[vec2]:{{site.github.url}}/classes/vec2d/
|
40
|
+
[vec3]:{{site.github.url}}/classes/vec3d/
|
41
|
+
[alternatives]:{{site.github.url}}/methods/alternative_methods/
|
42
|
+
[pvector]:https://processing.org/reference/PVector.html
|
43
|
+
[Math]:https://ruby-doc.org/core-2.2.3/Math.html
|
44
|
+
[core]:https://ruby-doc.org/core-2.2.3/
|
45
|
+
[sketches]:https://github.com/ruby-processing/JRubyArt-examples/
|
46
|
+
[settings]:https://processing.org/reference/settings_.html
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "settings"
|
4
|
+
permalink: methods/settings.html
|
5
|
+
---
|
6
|
+
All sketches require a user defined [settings][settings] method. This is where you define the sketch size (can be fullscreen) and render mode. Regular processing sketches hide this in a pre-process step that converts `pde` code to valid java code (on linux you can find the java code in the `/tmp` folder, and in some other temporary location on MacOS and Windows).
|
7
|
+
|
8
|
+
Minimal code default renderer:-
|
9
|
+
```ruby
|
10
|
+
def settings
|
11
|
+
size 200, 200
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
Minimal code fullscreen default renderer:-
|
16
|
+
```ruby
|
17
|
+
def settings
|
18
|
+
fullscreen
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
Minimal code fullscreen opengl 3D renderer:-
|
23
|
+
```ruby
|
24
|
+
def settings
|
25
|
+
size 200, 200, P3D
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Minimal code fullscreen opengl 3D renderer:-
|
30
|
+
```ruby
|
31
|
+
def settings
|
32
|
+
fullscreen P3D
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
For hi-dpi screens:-
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
def settings
|
40
|
+
size 200, 200
|
41
|
+
pixel_density(2)
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
You should also put `smooth` inside [settings][settings]
|
46
|
+
|
47
|
+
NB: as with vanilla-processing you can access the `width` and `height` variables within the sketch, eg in draw loop or mouse_pressed.
|
48
|
+
[settings]:https://processing.org/reference/settings_.html
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
layout: post
|
3
|
+
title: "setup"
|
4
|
+
permalink: methods/setup.html
|
5
|
+
---
|
6
|
+
All sketches will propably have a user defined [setup][setup] method. This is where you define the sketch title and where static code belongs.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
def setup
|
10
|
+
sketch_title 'My sketch'
|
11
|
+
# ... static code
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
Note to make variables declared in setup in the rest of sketch, you can make use of ruby `attr_reader` as for the `pts` array below.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
attr_reader :pts
|
19
|
+
|
20
|
+
def setup
|
21
|
+
sketch_title 'My sketch'
|
22
|
+
@pts = []
|
23
|
+
# ... static code
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
When the you can access `pts` in say the draw loop
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
def draw
|
31
|
+
p pts.length
|
32
|
+
# ... static code
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
[settings]:https://processing.org/reference/setup_.html
|