ruby-processing 2.5.0 → 2.5.1

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rpextras.jar +0 -0
  3. data/lib/ruby-processing/app.rb +26 -26
  4. data/lib/ruby-processing/exporters/base_exporter.rb +7 -5
  5. data/lib/ruby-processing/helper_methods.rb +78 -3
  6. data/lib/ruby-processing/version.rb +1 -1
  7. data/lib/templates/application/run.erb +4 -4
  8. data/samples/contributed/elegant_ball.rb +47 -37
  9. data/samples/contributed/tree.rb +1 -5
  10. data/samples/external_library/java_processing/custom/README.md +6 -5
  11. data/samples/external_library/java_processing/custom/Rakefile +17 -23
  12. data/samples/external_library/java_processing/custom/{src → ext}/nn/Connection.java +0 -0
  13. data/samples/external_library/java_processing/custom/{src → ext}/nn/HiddenNeuron.java +0 -0
  14. data/samples/external_library/java_processing/custom/{src → ext}/nn/InputNeuron.java +0 -0
  15. data/samples/external_library/java_processing/custom/{src → ext}/nn/Network.java +0 -0
  16. data/samples/external_library/java_processing/custom/{src → ext}/nn/Neuron.java +0 -0
  17. data/samples/external_library/java_processing/custom/{src → ext}/nn/OutputNeuron.java +0 -0
  18. data/samples/external_library/java_processing/custom/xor.rb +1 -1
  19. data/samples/external_library/ruby_gem/draw_test.rb +1 -1
  20. data/samples/processing_app/basics/arrays/array.rb +11 -11
  21. data/samples/processing_app/basics/color/blend_color.rb +17 -0
  22. data/samples/processing_app/basics/color/reading/reading.rb +20 -29
  23. data/samples/processing_app/basics/form/brick_tower.rb +11 -10
  24. data/samples/processing_app/basics/form/pie_chart.rb +4 -4
  25. data/samples/processing_app/basics/form/shape_transform.rb +17 -22
  26. data/samples/processing_app/basics/form/toroid.rb +16 -21
  27. data/samples/processing_app/basics/input/clock.rb +11 -10
  28. data/samples/processing_app/basics/math/sine_cosine.rb +6 -6
  29. data/samples/processing_app/basics/transform/bird.rb +9 -9
  30. data/samples/processing_app/basics/transform/birds.rb +1 -1
  31. data/samples/processing_app/basics/transform/library/bird/bird.rb +12 -12
  32. data/samples/processing_app/basics/transform/rotate.rb +10 -5
  33. data/samples/processing_app/basics/transform/triangle_flower.rb +3 -3
  34. data/samples/processing_app/library/fastmath/clock.rb +9 -7
  35. data/samples/processing_app/library/net/HTTPClient.rb +4 -2
  36. data/samples/processing_app/library/vecmath/arcball/arcball_box.rb +1 -1
  37. data/samples/processing_app/library/vecmath/arcball/arcball_radius.rb +1 -1
  38. data/samples/processing_app/library/vecmath/arcball/arcball_shape.rb +1 -1
  39. data/samples/processing_app/library/vecmath/vec2d/multiple_particle_systems.rb +1 -1
  40. data/samples/processing_app/library/vecmath/vec3d/retained_menger.rb +2 -2
  41. data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +1 -1
  42. data/samples/processing_app/topics/drawing/pulses.rb +3 -3
  43. data/samples/processing_app/topics/image_processing/linear_image.rb +1 -1
  44. data/samples/processing_app/topics/lsystems/csplant.rb +3 -3
  45. data/samples/processing_app/topics/motion/puff.rb +4 -4
  46. data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +1 -1
  47. data/samples/processing_app/topics/shaders/landscape.rb +1 -1
  48. metadata +10 -9
@@ -1,28 +1,22 @@
1
- require 'ant'
2
-
3
- PROJECT_NAME ='nn'
4
- MAIN_SRC_DIR = 'src'
5
- BUILD_DIR = 'build'
6
- DIST_DIR = 'library/nn'
7
-
8
- task :default => [:clean, :make_jars]
9
-
10
- task :clean do
11
- ant.delete :dir => BUILD_DIR
12
- puts
1
+ if RUBY_PLATFORM =~ /java/
2
+ # -*- ruby -*-
3
+ require 'rake/javaextensiontask'
4
+
5
+ Rake::JavaExtensionTask.new('nn') do |ext|
6
+ ext.name = 'nn'
7
+ ext.debug = true
8
+ ext.lib_dir = 'library/nn'
9
+ ext.source_version='1.7'
10
+ ext.target_version='1.7'
11
+ end
13
12
  end
14
13
 
15
- task :make_jars => :clean do
16
- make_jar MAIN_SRC_DIR, "#{PROJECT_NAME}.jar"
14
+ desc 'clean'
15
+ task :clean do
16
+ FileUtils.rm_rf(FileList['tmp', 'library'])
17
17
  end
18
18
 
19
- def make_jar(source_folder, jar_file_name)
20
- ant.mkdir :dir => BUILD_DIR
21
- ant.mkdir :dir => DIST_DIR
22
- ant.javac :srcdir => source_folder, :destdir => BUILD_DIR,
23
- :source => "1.7", :target => "1.7", :debug => "yes", :includeantruntime => "no"
24
- ant.jar :jarfile => "#{DIST_DIR}/#{jar_file_name}", :basedir => BUILD_DIR
25
- ant.delete :dir => BUILD_DIR
26
- puts
19
+ desc 'run'
20
+ task :run do
21
+ sh `rp5 run xor.rb`
27
22
  end
28
-
@@ -78,7 +78,7 @@ def network_status
78
78
  text("Total iterations: #{count}", 10, 40)
79
79
  mse += (result - known) * (result - known)
80
80
  rmse = Math::sqrt(mse / 4.0)
81
- out = "Root mean squared error: #{format("%.5f", rmse)}"
81
+ out = "Root mean squared error: #{format('%0.5f', rmse)}"
82
82
  hint DISABLE_DEPTH_SORT
83
83
  text(out, 10, 60)
84
84
  hint ENABLE_DEPTH_SORT
@@ -103,7 +103,7 @@ def train
103
103
  error = net.train(sq_input, [0, 1.0, 0])
104
104
  error = net.train(cr_input, [0, 0, 1.0])
105
105
  error = net.train(ci_input, [0, 1.0, 1.0])
106
- puts "Error after iteration #{i}:\t#{format("%.5f", error)}" if i%20 == 0
106
+ puts "Error after iteration #{i}:\t#{format('%0.5f', error)}" if i%20 == 0
107
107
  end
108
108
  end
109
109
 
@@ -12,24 +12,24 @@ def setup
12
12
  size 640, 360
13
13
  coswave = []
14
14
 
15
- 0.upto( width ) do |i|
15
+ 0.upto(width) do |i|
16
16
  amount = map i, 0, width, 0, PI
17
- coswave[i] = cos( amount ).abs
17
+ coswave[i] = cos(amount).abs
18
18
  end
19
19
 
20
- 0.upto( width ) do |i|
21
- stroke( coswave[i] * 255 )
22
- line i, 0, i, height/3
20
+ 0.upto(width) do |i|
21
+ stroke(coswave[i] * 255)
22
+ line(i, 0, i, height / 3)
23
23
  end
24
24
 
25
- 0.upto( width ) do |i|
26
- stroke( coswave[i] * 255 / 4 )
27
- line i, height/3, i, height/3*2
25
+ 0.upto(width) do |i|
26
+ stroke(coswave[i] * 255 / 4)
27
+ line(i, height / 3, i, height / 3 * 2)
28
28
  end
29
29
 
30
- 0.upto( width ) do |i|
31
- stroke( 255 - coswave[i] * 255 )
32
- line i, height/3*2, i, height
30
+ 0.upto(width) do |i|
31
+ stroke(255 - coswave[i] * 255)
32
+ line(i, height / 3 * 2, i, height)
33
33
  end
34
34
 
35
35
  end
@@ -0,0 +1,17 @@
1
+ # example of processing blend_color (uses PImage blend_color under the hood)
2
+ # blend_color(c1, c2, MODE) returns a color int
3
+
4
+ def setup
5
+ size 100, 100
6
+ orange = color(204, 102, 0)
7
+ blue = color(0, 102, 153)
8
+ orangeblueadd = blend_color(orange, blue, ADD)
9
+ background(51)
10
+ noStroke()
11
+ fill(orange)
12
+ rect(14, 20, 20, 60)
13
+ fill(orangeblueadd)
14
+ rect(40, 20, 20, 60)
15
+ fill(blue)
16
+ rect(66, 20, 20, 60)
17
+ end
@@ -4,35 +4,26 @@
4
4
 
5
5
 
6
6
  def setup
7
- size 200, 200
8
- no_stroke
9
- background 0
10
-
11
- c = load_image "cait.jpg"
12
-
13
- xoff, yoff = 0, 0
14
- p = 2
15
- pix = p * 3
16
-
17
- (c.width * c.height).times do |i|
18
-
19
- pixel = c.pixels[i]
20
-
21
- fill red( pixel ), 0, 0
22
- rect xoff, yoff, p, pix
23
-
24
- fill 0, green( pixel ), 0
25
- rect xoff+p, yoff, p, pix
26
-
27
- fill 0, 0, blue( pixel )
28
- rect xoff+p*2, yoff, p, pix
29
-
30
- xoff += pix
31
- if xoff >= (width-pix)
32
- xoff = 0
33
- yoff += pix
34
- end
7
+ size 200, 200
8
+ no_stroke
9
+ background 0
10
+ c = load_image "cait.jpg"
11
+ xoff, yoff = 0, 0
12
+ p = 2
13
+ pix = p * 3
14
+ (c.width * c.height).times do |i|
15
+ pixel = c.pixels[i]
16
+ fill red( pixel ), 0, 0
17
+ rect xoff, yoff, p, pix
18
+ fill 0, green( pixel ), 0
19
+ rect xoff+p, yoff, p, pix
20
+ fill 0, 0, blue( pixel )
21
+ rect xoff+p*2, yoff, p, pix
22
+ xoff += pix
23
+ if xoff >= (width-pix)
24
+ xoff = 0
25
+ yoff += pix
35
26
  end
36
-
27
+ end
37
28
  end
38
29
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  # 3D castle tower constructed out of individual bricks.
4
4
  # Uses the Vect struct and Cube class.
5
+
5
6
  attr_reader :angle, :brick, :bricks_per_layer, :brick_layers
6
7
  attr_reader :radius, :layer_num, :temp_y
7
8
 
@@ -21,25 +22,25 @@ def draw
21
22
  fill 182, 62, 29
22
23
  no_stroke
23
24
  lights
24
- translate(width/2.0, height * 1.2, -380) # move viewpoint into position
25
- rotate_x(radians(-45)) # tip tower to see inside
25
+ translate(width / 2.0, height * 1.2, -380) # move viewpoint into position
26
+ rotate_x(-45.radians) # tip tower to see inside
26
27
  rotate_y(frame_count * PI/600) # slowly rotate tower
27
- brick_layers.times {|i| draw_layer(i) }
28
+ brick_layers.times { |i| draw_layer(i) }
28
29
  end
29
30
 
30
31
  def draw_layer(layer_num)
31
32
  @layer_num = layer_num
32
33
  @temp_y -= @brick_height # increment rows
33
34
  @angle = 360.0 / bricks_per_layer * layer_num / 2.0 # alternate brick seams
34
- bricks_per_layer.times {|i| draw_bricks(i) }
35
+ bricks_per_layer.times { |i| draw_bricks(i) }
35
36
  end
36
37
 
37
38
  def draw_bricks(brick_num)
38
- temp_z = cos(radians(angle)) * radius
39
- temp_x = sin(radians(angle)) * radius
39
+ temp_z = cos(angle.radians) * radius
40
+ temp_x = sin(angle.radians) * radius
40
41
  push_matrix
41
42
  translate temp_x, temp_y, temp_z
42
- rotate_y(radians(angle))
43
+ rotate_y(angle.radians)
43
44
  top_layer = layer_num == brick_layers - 1
44
45
  even_brick = brick_num % 2 == 0
45
46
  brick.create unless top_layer # main tower
@@ -73,8 +74,8 @@ class Cubeish
73
74
 
74
75
  SIDES.each do |side, signs|
75
76
  vertices[side] = signs.map do |s|
76
- s = s.split('').map {|el| SIGNS[el] }
77
- Vect.new(s[0] * w/2, s[1] * h/2, s[2] * d/2)
77
+ s = s.split('').map { |el| SIGNS[el] }
78
+ Vect.new(s[0] * w / 2, s[1] * h / 2, s[2] * d/2)
78
79
  end
79
80
  end
80
81
  end
@@ -82,7 +83,7 @@ class Cubeish
82
83
  def create
83
84
  vertices.each do |name, vectors|
84
85
  begin_shape QUADS
85
- vectors.each {|v| vertex(v.x, v.y, v.z) }
86
+ vectors.each { |v| vertex(v.x, v.y, v.z) }
86
87
  end_shape
87
88
  end
88
89
  end
@@ -10,7 +10,7 @@
10
10
  def setup
11
11
  size 640, 360
12
12
  background 100
13
- smooth
13
+ smooth(4)
14
14
  no_stroke
15
15
 
16
16
  diameter = min(width, height) * 0.75
@@ -20,8 +20,8 @@ def setup
20
20
  angles.each do |angle|
21
21
  fill angle * 3.0
22
22
  arc width/2, height/2, # center x, y
23
- diameter, diameter, # width, height
24
- last_angle, last_angle + radians(angle) # angles from, to
25
- last_angle += radians(angle)
23
+ diameter, diameter, # width, height
24
+ last_angle, last_angle + angle.radians # angles from, to
25
+ last_angle += angle.radians
26
26
  end
27
27
  end
@@ -10,32 +10,27 @@
10
10
  # Down Arrow - decreases points
11
11
  # 'p' key toggles between cube/pyramid
12
12
 
13
+ load_library :vecmath
14
+ attr_reader :renderer
13
15
 
14
16
 
15
- def setup
16
-
17
+ def setup
17
18
  size 640, 360, P3D
18
-
19
- no_stroke
20
-
21
- @angle_inc = PI/300
22
-
19
+ @renderer = AppRender.new(self)
20
+ no_stroke
21
+ @angle_inc = PI / 300
23
22
  @pts = 4
24
23
  @angle = 0
25
24
  @radius = 99
26
- @cylinder_length = 95
27
-
28
- @is_pyramid = false
29
-
25
+ @cylinder_length = 95
26
+ @is_pyramid = false
30
27
  end
31
28
 
32
- def draw
33
-
29
+ def draw
34
30
  background 170, 95, 95
35
31
  lights
36
- fill 255, 200, 200
37
-
38
- translate width/2, height/2
32
+ fill 255, 200, 200
33
+ translate width / 2, height / 2
39
34
  rotate_x frame_count * @angle_inc
40
35
  rotate_y frame_count * @angle_inc
41
36
  rotate_z frame_count * @angle_inc
@@ -46,10 +41,10 @@ def draw
46
41
  @angle = 0
47
42
  vertices[i] = []
48
43
  0.upto(@pts) { |j|
49
- pvec = PVector.new 0, 0
44
+ pvec = Vec3D.new 0, 0
50
45
  (
51
- pvec.x = cos(radians( @angle )) * @radius
52
- pvec.y = sin(radians( @angle )) * @radius
46
+ pvec.x = cos(@angle.radians) * @radius
47
+ pvec.y = sin(@angle.radians) * @radius
53
48
 
54
49
  ) unless ( @is_pyramid && i == 1 )
55
50
 
@@ -63,15 +58,15 @@ def draw
63
58
 
64
59
  begin_shape QUAD_STRIP
65
60
  0.upto(@pts) { |j|
66
- vertex vertices[0][j].x, vertices[0][j].y, vertices[0][j].z
67
- vertex vertices[1][j].x, vertices[1][j].y, vertices[1][j].z
61
+ vertices[0][j].to_vertex(renderer)
62
+ vertices[1][j].to_vertex(renderer)
68
63
  }
69
64
  end_shape
70
65
 
71
66
  [0,1].each { |i|
72
67
  begin_shape
73
68
  0.upto(@pts) { |j|
74
- vertex vertices[i][j].x, vertices[i][j].y, vertices[i][j].z
69
+ vertices[i][j].to_vertex(renderer)
75
70
  }
76
71
  end_shape CLOSE
77
72
  }
@@ -17,9 +17,11 @@
17
17
  # 'h' key _________ toggle sphere/helix
18
18
 
19
19
  load_library :vecmath
20
+ attr_reader :renderer
20
21
 
21
22
  def setup
22
- size 640, 360, P3D
23
+ size 640, 360, P3D
24
+ @renderer = AppRender.new(self)
23
25
  @pts = 40
24
26
  @angle = 0.0
25
27
  @radius = 60.0
@@ -42,7 +44,7 @@ def draw
42
44
  fill 150, 195, 125
43
45
  end
44
46
 
45
- translate width/2, height/2, -100
47
+ translate width / 2, height / 2, -100
46
48
 
47
49
  rotate_x frame_count * PI / 150
48
50
  rotate_y frame_count * PI / 170
@@ -51,32 +53,25 @@ def draw
51
53
  vertices = []
52
54
  vertices2 = []
53
55
 
54
- 0.upto(@pts) do |i|
55
-
56
+ 0.upto(@pts) do |i|
56
57
  vertices2[i] = Vec3D.new
57
- vertices[i] = Vec3D.new
58
-
59
- vertices[i].x = @lathe_radius + sin( radians( @angle ) ) * @radius
60
-
58
+ vertices[i] = Vec3D.new
59
+ vertices[i].x = @lathe_radius + sin(@angle.radians) * @radius
61
60
  if @is_helix
62
- vertices[i].z = cos( radians( @angle ) ) * @radius - (@helix_offset * @segments) / 2
61
+ vertices[i].z = cos(@angle.radians) * @radius - (@helix_offset * @segments) / 2
63
62
  else
64
- vertices[i].z = cos( radians( @angle ) ) * @radius
65
- end
66
-
63
+ vertices[i].z = cos(@angle.radians) * @radius
64
+ end
67
65
  @angle += 360.0 / @pts
68
- end
69
-
70
- @lathe_angle = 0
71
-
66
+ end
67
+ @lathe_angle = 0
72
68
  0.upto(@segments) do |i|
73
69
  begin_shape QUAD_STRIP
74
70
  (0..@pts).each do |j|
75
71
  vertex_for_vector vertices2[j] if i > 0
76
72
 
77
- vertices2[j].x = cos( radians( @lathe_angle ) ) * vertices[j].x
78
- vertices2[j].y = sin( radians( @lathe_angle )
79
- ) * vertices[j].x
73
+ vertices2[j].x = cos(@lathe_angle.radians) * vertices[j].x
74
+ vertices2[j].y = sin(@lathe_angle.radians) * vertices[j].x
80
75
  vertices2[j].z = vertices[j].z
81
76
 
82
77
  vertices[j].z += @helix_offset if @is_helix
@@ -90,8 +85,8 @@ def draw
90
85
 
91
86
  end
92
87
 
93
- def vertex_for_vector ( pvec )
94
- vertex( pvec.x, pvec.y, pvec.z )
88
+ def vertex_for_vector (pvec)
89
+ pvec.to_vertex(renderer)
95
90
  end
96
91
 
97
92
  def key_pressed
@@ -1,6 +1,8 @@
1
- # The current time can be read with the second(), minute(),
2
- # and hour() functions. In this example, sin() and cos() values
3
- # are used to set the position of the hands.
1
+ # Current time can be read with the t = Time.now. Get hour, minute and second
2
+ # using t.hour, t.min, t.sec functions. The processing hour(), minute() and
3
+ # second are deprecated since ruby-processing-2.5.1. In this example, sine and
4
+ # cosine values are used to set the position of the hands.
5
+
4
6
  load_library :fastmath
5
7
 
6
8
  def setup
@@ -12,17 +14,16 @@ end
12
14
  def draw
13
15
  background 0
14
16
  fill 80
15
- no_stroke
16
-
17
+ no_stroke
17
18
  ellipse 100, 100, 160, 160
18
-
19
+ t = Time.now # access time from ruby
19
20
  stroke 255
20
21
  stroke_weight 1
21
- line( 100, 100, calc_hand_x(second, 0, 72, 100), calc_hand_y(second, 0, 72, 100) )
22
+ line( 100, 100, calc_hand_x(t.sec, 0, 72, 100), calc_hand_y(t.sec, 0, 72, 100) )
22
23
  stroke_weight 2
23
- line( 100, 100, calc_hand_x(minute, second, 60, 100), calc_hand_y(minute, second, 60, 100) )
24
+ line( 100, 100, calc_hand_x(t.min, t.sec, 60, 100), calc_hand_y(t.min, t.sec, 60, 100) )
24
25
  stroke_weight 4
25
- line( 100, 100, calc_hand_x(hour, minute, 50, 100), calc_hand_y(hour, minute, 50, 100) )
26
+ line( 100, 100, calc_hand_x(t.hour, t.min, 50, 100), calc_hand_y(t.hour, t.min, 50, 100) )
26
27
 
27
28
  # Draw the minute ticks
28
29
  stroke_weight 2
@@ -33,7 +34,7 @@ def draw
33
34
  end
34
35
  end
35
36
 
36
- # Angles for sin() and cos() start at 3 o'clock;
37
+ # Angles for sin and cos start at 3 o'clock
37
38
  # subtract 90 degrees to make them start at the top
38
39
 
39
40
  def calc_hand_x(time, time_bit, length, origin)