ruby-processing 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/CHANGELOG +6 -0
  2. data/lib/core/core.jar +0 -0
  3. data/lib/core/jruby-complete.jar +0 -0
  4. data/lib/ruby-processing.rb +5 -10
  5. data/lib/ruby-processing/app.rb +139 -98
  6. data/lib/ruby-processing/exporters/applet_exporter.rb +4 -1
  7. data/lib/ruby-processing/exporters/application_exporter.rb +5 -1
  8. data/lib/ruby-processing/exporters/base_exporter.rb +3 -2
  9. data/lib/ruby-processing/runner.rb +54 -46
  10. data/lib/ruby-processing/runners/base.rb +6 -7
  11. data/lib/ruby-processing/runners/live.rb +4 -3
  12. data/lib/ruby-processing/runners/watch.rb +33 -27
  13. data/library/control_panel/control_panel.rb +24 -23
  14. data/samples/anar/data/java_args.txt +1 -0
  15. data/samples/anar/extrusion.rb +49 -0
  16. data/samples/anar/l_system.rb +86 -0
  17. data/samples/anar/library/anar/anar.jar +0 -0
  18. data/samples/anar/many_shapes.rb +98 -0
  19. data/samples/empathy.rb +73 -0
  20. data/samples/gravity.rb +113 -0
  21. data/samples/peasy_cam/data/java_args.txt +1 -0
  22. data/samples/peasy_cam/hello_peasy.rb +29 -0
  23. data/samples/peasy_cam/hilbert_fractal.rb +40 -0
  24. data/samples/peasy_cam/library/PeasyCam/PeasyCam.jar +0 -0
  25. data/samples/peasy_cam/library/hilbert/hilbert.rb +99 -0
  26. data/samples/processing_app/3D/form/brick_tower.rb +3 -3
  27. data/samples/processing_app/basics/data/characters_strings/characters_strings.rb +5 -7
  28. data/samples/processing_app/basics/form/triangle_strip.rb +11 -11
  29. data/samples/processing_app/basics/input/keyboard.rb +2 -8
  30. data/samples/processing_app/basics/input/keyboard_2.rb +4 -4
  31. data/samples/processing_app/basics/input/keyboard_functions.rb +12 -21
  32. metadata +41 -64
@@ -9,7 +9,8 @@ module ControlPanel
9
9
 
10
10
  class Slider < javax.swing.JSlider
11
11
  def initialize(control_panel, name, range, initial_value, proc=nil)
12
- min, max = range.begin * 100, range.end * 100
12
+ min = range.begin * 100
13
+ max = ((range.exclude_end? && range.begin.respond_to?(:succ)) ? range.max : range.end) * 100
13
14
  super(min, max)
14
15
  set_minor_tick_spacing((max - min).abs / 10)
15
16
  set_paint_ticks true
@@ -24,20 +25,20 @@ module ControlPanel
24
25
  set_value(initial_value ? initial_value*100 : min)
25
26
  fire_state_changed
26
27
  end
27
-
28
+
28
29
  def value
29
30
  get_value / 100.0
30
31
  end
31
-
32
+
32
33
  def update_label(label, name, value)
33
34
  value = value.to_s
34
35
  value << "0" if value.length < 4
35
36
  label.set_text "<html><br>#{name.to_s}: #{value}</html>"
36
37
  end
37
38
  end
38
-
39
-
40
- class Menu < javax.swing.JComboBox
39
+
40
+
41
+ class Menu < javax.swing.JComboBox
41
42
  def initialize(control_panel, name, elements, initial_value, proc=nil)
42
43
  super(elements.to_java(:String))
43
44
  set_preferred_size(java.awt.Dimension.new(190, 30))
@@ -48,13 +49,13 @@ module ControlPanel
48
49
  end
49
50
  set_selected_index(initial_value ? elements.index(initial_value) : 0)
50
51
  end
51
-
52
+
52
53
  def value
53
54
  get_selected_item
54
55
  end
55
56
  end
56
-
57
-
57
+
58
+
58
59
  class Checkbox < javax.swing.JCheckBox
59
60
  def initialize(control_panel, name, proc=nil)
60
61
  @control_panel = control_panel
@@ -62,18 +63,18 @@ module ControlPanel
62
63
  set_preferred_size(java.awt.Dimension.new(190, 64))
63
64
  set_horizontal_alignment javax.swing.SwingConstants::CENTER
64
65
  control_panel.add_element(self, name, false)
65
- add_action_listener do
66
+ add_action_listener do
66
67
  $app.instance_variable_set("@#{name}", value) unless value.nil?
67
68
  proc.call(value) if proc
68
69
  end
69
70
  end
70
-
71
+
71
72
  def value
72
73
  is_selected
73
74
  end
74
75
  end
75
-
76
-
76
+
77
+
77
78
  class Button < javax.swing.JButton
78
79
  def initialize(control_panel, name, proc=nil)
79
80
  super(name.to_s)
@@ -85,17 +86,17 @@ module ControlPanel
85
86
  end
86
87
  end
87
88
  end
88
-
89
-
89
+
90
+
90
91
  class Panel < javax.swing.JFrame
91
92
  attr_accessor :elements
92
-
93
+
93
94
  def initialize
94
95
  super()
95
96
  @elements = []
96
97
  @panel = javax.swing.JPanel.new(java.awt.FlowLayout.new(1, 0, 0))
97
98
  end
98
-
99
+
99
100
  def display
100
101
  add @panel
101
102
  set_size 200, 30 + (64 * @elements.size)
@@ -108,7 +109,7 @@ module ControlPanel
108
109
  show
109
110
  end
110
111
  end
111
-
112
+
112
113
  def add_element(element, name, has_label=true, button=false)
113
114
  if has_label
114
115
  label = javax.swing.JLabel.new("<html><br>#{name}</html>")
@@ -118,12 +119,12 @@ module ControlPanel
118
119
  @panel.add element
119
120
  return has_label ? label : nil
120
121
  end
121
-
122
+
122
123
  def remove
123
124
  remove_all
124
125
  dispose
125
126
  end
126
-
127
+
127
128
  def slider(name, range=0..100, initial_value = nil, &block)
128
129
  slider = Slider.new(self, name, range, initial_value, block || nil)
129
130
  end
@@ -131,17 +132,17 @@ module ControlPanel
131
132
  def menu(name, elements, initial_value = nil, &block)
132
133
  menu = Menu.new(self, name, elements, initial_value, block || nil)
133
134
  end
134
-
135
+
135
136
  def checkbox(name, initial_value = nil, &block)
136
137
  checkbox = Checkbox.new(self, name, block || nil)
137
138
  checkbox.do_click if initial_value == true
138
139
  end
139
-
140
+
140
141
  def button(name, &block)
141
142
  button = Button.new(self, name, block || nil)
142
143
  end
143
144
  end
144
-
145
+
145
146
 
146
147
  module InstanceMethods
147
148
  def control_panel
@@ -0,0 +1 @@
1
+ -Xms256m -Xmx256m
@@ -0,0 +1,49 @@
1
+ # extrude.rb is a processing sketch that shows
2
+ # how you can use the Anar library in Ruby-Processing.
3
+
4
+ load_libraries 'anar', 'opengl'
5
+ import "anar"
6
+ import "processing.opengl"
7
+ full_screen
8
+
9
+ def setup
10
+ configure_opengl
11
+ configure_anar
12
+ @points = [
13
+ [100, 110, 20],
14
+ [110, 100, 40],
15
+ [110, 90, 60],
16
+ [90, 90, 90]
17
+ ]
18
+ create_extrusion
19
+ end
20
+
21
+ def configure_opengl
22
+ render_mode OPENGL
23
+ hint ENABLE_OPENGL_4X_SMOOTH # optional
24
+ hint DISABLE_OPENGL_ERROR_REPORT # optional
25
+ end
26
+
27
+ def configure_anar
28
+ Anar.init self
29
+ Anar.draw_axis true
30
+ end
31
+
32
+ def create_extrusion
33
+ pts = Pts.new
34
+ @points.each {|xyz| pts.add(Anar.Pt(*xyz)) } # make a line out of points
35
+ face = Star.new(50,100,5) # make a face
36
+ @extrusion = Extrude.new(face, pts) # extrude the face along the line
37
+ Anar.cam_target(@extrusion)
38
+ Anar.sliders(@extrusion)
39
+ end
40
+
41
+ def draw
42
+ background 155
43
+ @extrusion.draw
44
+ end
45
+
46
+ # show or hide the sliders
47
+ def key_pressed
48
+ Anar.sliders_toggle
49
+ end
@@ -0,0 +1,86 @@
1
+ # Demonstrates how you can use the Lindenmeyer System (lsys)
2
+ # features of the Anar library in Ruby-Processing.
3
+ # Press space to draw further iterations of the system.
4
+
5
+ load_libraries 'anar', 'opengl'
6
+ import "anar"
7
+ import "lsys.Grammar"
8
+ import "processing.opengl"
9
+ full_screen
10
+
11
+ def setup
12
+ setup_opengl
13
+ Anar.init self
14
+ Anar.draw_axis true
15
+ create_grammar
16
+ create_scene
17
+ end
18
+
19
+ def create_grammar
20
+ @grammar = Grammar.new("bt")
21
+ # Here we define the rules.
22
+ # "*" means any kind of symbol.
23
+ # The example rules below are non-contextual.
24
+ @grammar.add_rule("*b*", "brb")
25
+ @grammar.add_rule("*t*", "rssb")
26
+ @grammar.add_rule("*r*", "rs")
27
+ @grammar.add_rule("*s*", "s")
28
+ # The following rule makes it context-sensitive.
29
+ # grammar.add_rule("sss", "ss")
30
+ puts @grammar
31
+ end
32
+
33
+ def create_scene
34
+ @box = Box.new(10, 10, 50) # the base element
35
+ @pos = Translate.new(0, 50, 0) # with position
36
+ @trans = Translate.new(Anar.Pt(0, 10, -0.001)) # and transformations...
37
+ @rot = RotateZ.new(0.5)
38
+ @scale = Scale.new(Anar.Pt(0.99, 0.99, 0.99))
39
+ interpret_grammar
40
+ end
41
+
42
+ def interpret_grammar
43
+ @scene = Obj.new
44
+ @root = Transform.new(@pos)
45
+ @grammar.num_of_symbols.times do |i|
46
+ rule = @grammar.symbol(i)[0].chr
47
+ case rule # todo this is bit of hack, I need understand grammar better
48
+ when 'b'
49
+ @scene.add(Obj.new(@box, @root))
50
+ @root = Transform.new(@root)
51
+ when 't' then @root.apply(@trans)
52
+ when 'r' then @root.apply(@rot)
53
+ when 's' then @root.apply(@scale)
54
+ else
55
+ puts "rule: '#{rule}' is not in grammar"
56
+ end
57
+ end
58
+ Anar.cam_target @scene
59
+ end
60
+
61
+ def draw
62
+ background 153
63
+ @scene.draw
64
+ end
65
+
66
+ def key_pressed
67
+ case key
68
+ when ' '
69
+ @grammar.step
70
+ interpret_grammar
71
+ puts @grammar
72
+ when 'r'
73
+ @grammar.reset
74
+ create_grammar
75
+ interpret_grammar
76
+ puts @grammar
77
+ when 'p'
78
+ save_frame "block.png"
79
+ end
80
+ end
81
+
82
+ def setup_opengl
83
+ render_mode OPENGL
84
+ hint ENABLE_OPENGL_4X_SMOOTH # optional
85
+ hint DISABLE_OPENGL_ERROR_REPORT # optional
86
+ end
@@ -0,0 +1,98 @@
1
+ # Demonstrates custom shapes with the Anar library.
2
+ # Hold down middle button to control orientation
3
+ # of the working surface (prepare to be amazed)!
4
+
5
+ load_libraries 'anar', 'opengl'
6
+ import "anar"
7
+ import "processing.opengl"
8
+ full_screen
9
+
10
+ def setup
11
+ setup_opengl
12
+ Anar.init self
13
+ Anar.draw_axis
14
+ Face.globalRender = RenderFaceNormal.new(OogColor.new(255, 100), OogColor.new(100))
15
+ create_shapes
16
+ end
17
+
18
+ def create_shapes
19
+ @scene = Obj.new
20
+ @group = Group.new
21
+ shapes = []
22
+
23
+ # A Cone.
24
+ cone = Cone.new(50,100,20)
25
+ cone.set("cone")
26
+ cone.translate(100,100,0)
27
+ @group.add(cone)
28
+ shapes << cone
29
+ # puts(cone.to_obj_exporter)
30
+
31
+ # A Box.
32
+ box = Box.new(10,20,30)
33
+ box.set("box")
34
+ box.rotate_z(0)
35
+ box.rotate_x(0)
36
+ box.translate(100, 0, 0)
37
+ @group.add(box)
38
+ shapes << box
39
+ # puts(box.to_obj_exporter("box"))
40
+ # puts(box.parent_list(-1))
41
+
42
+ # A Cylinder
43
+ cylinder = Cylinder.new(50, 24, 50)
44
+ cylinder.set("cylinder")
45
+ cylinder.translate(-100, 0, 0)
46
+ @group.add(cylinder)
47
+ shapes << cylinder
48
+ # puts(cylinder.to_obj_exporter("cylinder"))
49
+
50
+ # An ellipse.
51
+ ellipse = Ellipse.new(40, 20)
52
+ ellipse.set("ellipse")
53
+ @group.add(ellipse)
54
+ shapes << ellipse
55
+ # puts(ellipse.to_obj_exporter("ellipse"))
56
+
57
+ # A 3D Swiss Cross.
58
+ swiss_cross = SwissCross3D.new(10, 10)
59
+ swiss_cross.set("swiss_cross")
60
+ #swiss_cross.fill(255,0,0,200)
61
+ #swiss_cross.translate(-100,0,0)
62
+ @group.add(swiss_cross)
63
+ shapes << swiss_cross
64
+ # puts(swiss_cross.to_obj_exporter("swiss_cross"))
65
+
66
+ # A Revolver
67
+ control_line = Pts.new()
68
+ control_line.add(Anar.Pt(30,0,30))
69
+ control_line.add(Anar.Pt(10,0,40))
70
+ control_line.add(Anar.Pt(20,0,60))
71
+ control_line.add(Anar.Pt(20,0,70))
72
+ revolver = Revolve.new(control_line, Anar.Pt(0,0,20), 12)
73
+ revolver.set("revolver")
74
+ @group.add(revolver)
75
+ shapes << revolver
76
+ # puts(revolver.to_obj_exporter("revolver"))
77
+
78
+ # Add all the shapes to the scene.
79
+ shapes.each {|shape| @scene.add(shape) }
80
+ Anar.sliders(swiss_cross)
81
+ Anar.sliders(revolver)
82
+ Anar.cam_target(revolver)
83
+ end
84
+
85
+ def setup_opengl
86
+ render_mode OPENGL
87
+ hint ENABLE_OPENGL_4X_SMOOTH # optional
88
+ hint DISABLE_OPENGL_ERROR_REPORT # optional
89
+ end
90
+
91
+ def draw
92
+ background 155
93
+ @group.draw
94
+ end
95
+
96
+ def key_pressed
97
+ create_shapes if key == ' '
98
+ end
@@ -0,0 +1,73 @@
1
+ # Empathy
2
+ # original by Kyle McDonald
3
+ # http://www.openprocessing.org/visuals/?visualID=1182
4
+
5
+ # This sketch takes advantage of multiple processors by running calculations
6
+ # in a separate thread.
7
+
8
+ CELL_COUNT = 5000
9
+ SLOW_DOWN = 0.97
10
+ ROTATION = 0.004
11
+ LINE_LENGTH = 37
12
+ MULTI_THREADED = true
13
+
14
+ def setup
15
+ size(500, 500, P3D)
16
+ stroke(0, 0, 0, 25)
17
+ initialize_cells
18
+ start_cell_updates if MULTI_THREADED
19
+ end
20
+
21
+ def initialize_cells
22
+ @cells = []
23
+ n = CELL_COUNT
24
+ n.times do |i|
25
+ a = i + rand * (Math::PI / 9.0)
26
+ r = ((i / n.to_f) * (width / 2) * (((n - i) / n.to_f) * 3.3)) + (rand * 6)
27
+ @cells[i] = Cell.new((r * Math.cos(a) + width/2).to_i, (r * Math.sin(a) + height/2).to_i)
28
+ end
29
+ end
30
+
31
+ def start_cell_updates
32
+ Thread.new { Kernel.loop { @cells.each {|cell| cell.update } } }
33
+ end
34
+
35
+ def draw
36
+ background 255
37
+ @cells.each {|cell| cell.sense } if started?
38
+ end
39
+
40
+ def started?
41
+ pmouse_x != 0 || pmouse_y != 0
42
+ end
43
+
44
+ def mouse_pressed
45
+ @cells.each {|cell| cell.reset }
46
+ end
47
+
48
+ class Cell
49
+
50
+ def initialize(x, y)
51
+ @x, @y = x, y
52
+ @spin = 0
53
+ @angle = 0
54
+ end
55
+
56
+ def reset
57
+ @spin, @angle = 0, 0
58
+ end
59
+
60
+ def update
61
+ det = ((pmouse_x-@x) * (mouse_y-@y) - (mouse_x-@x) * (pmouse_y-@y)).to_f
62
+ @spin += ROTATION * det / dist(@x, @y, mouse_x, mouse_y).to_f
63
+ @spin *= SLOW_DOWN
64
+ @angle += @spin
65
+ end
66
+
67
+ def sense
68
+ update unless MULTI_THREADED
69
+ d = LINE_LENGTH * @spin + 0.001
70
+ line(@x, @y, @x + d * Math.cos(@angle), @y + d * Math.sin(@angle))
71
+ end
72
+
73
+ end