ruby-processing 1.0.5 → 1.0.6
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.
- data/CHANGELOG +8 -0
 - data/lib/ruby-processing.rb +1 -1
 - data/lib/ruby-processing/app.rb +85 -20
 - data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
 - data/lib/ruby-processing/runners/base.rb +1 -1
 - data/lib/ruby-processing/runners/watch.rb +1 -1
 - data/lib/templates/applet/images/built_with.jpg +0 -0
 - data/lib/templates/applet/images/ruby.jpg +0 -0
 - data/lib/templates/applet/index.html.erb +7 -3
 - data/lib/templates/application/Contents/Resources/sketch.icns +0 -0
 - data/library/control_panel/control_panel.rb +18 -13
 - data/samples/circle_collision.rb +72 -85
 - data/samples/getting_started.rb +1 -0
 - data/samples/jwishy.rb +8 -7
 - data/samples/orbit.rb +27 -32
 - data/samples/processing_app/3D/camera/ortho_vs_perspective.rb +22 -30
 - data/samples/processing_app/3D/camera/perspective.rb +21 -29
 - data/samples/processing_app/3D/form/brick_tower.rb +46 -54
 - data/samples/processing_app/3D/typography/kinetic_type.rb +36 -35
 - data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +74 -73
 - data/samples/reflection.rb +13 -22
 - metadata +2 -2
 
| 
         @@ -5,10 +5,51 @@ 
     | 
|
| 
       5 
5 
     | 
    
         
             
            # Each burst is one instance of a particle system with Particles and
         
     | 
| 
       6 
6 
     | 
    
         
             
            # CrazyParticles (a subclass of Particle).
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
      
 8 
     | 
    
         
            +
            module Runnable
         
     | 
| 
      
 9 
     | 
    
         
            +
              def run
         
     | 
| 
      
 10 
     | 
    
         
            +
                self.reject! { |item| item.dead? }
         
     | 
| 
      
 11 
     | 
    
         
            +
                self.each    { |item| item.run   }
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            class Vector
         
     | 
| 
      
 17 
     | 
    
         
            +
              attr_accessor :x, :y
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              def initialize(x, y)
         
     | 
| 
      
 20 
     | 
    
         
            +
                @x, @y = x, y
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
       8 
22 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
              def +(other)
         
     | 
| 
      
 24 
     | 
    
         
            +
                return Vector.new(@x + other, @y + other)     if other.is_a?(Numeric)
         
     | 
| 
      
 25 
     | 
    
         
            +
                return Vector.new(@x + other.x, @y + other.y) if other.is_a?(Vector)
         
     | 
| 
      
 26 
     | 
    
         
            +
                self
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              def heading
         
     | 
| 
      
 30 
     | 
    
         
            +
                -1 * Math::atan2(-@y, @x)
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def magnitude
         
     | 
| 
      
 34 
     | 
    
         
            +
                @x * @x + @y * @y
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
       10 
37 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            class ParticleSystem < Array
         
     | 
| 
      
 40 
     | 
    
         
            +
              include Runnable
         
     | 
| 
      
 41 
     | 
    
         
            +
              alias_method :dead?, :empty?
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              def initialize(number, origin)
         
     | 
| 
      
 44 
     | 
    
         
            +
                super()
         
     | 
| 
      
 45 
     | 
    
         
            +
                @origin = origin
         
     | 
| 
      
 46 
     | 
    
         
            +
                kind = rand < 0.5 ? Sketch::Particle : Sketch::CrazyParticle
         
     | 
| 
      
 47 
     | 
    
         
            +
                number.times { self << kind.new(origin) }
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            class Sketch < Processing::App
         
     | 
| 
       12 
53 
     | 
    
         
             
              def setup
         
     | 
| 
       13 
54 
     | 
    
         
             
                smooth
         
     | 
| 
       14 
55 
     | 
    
         
             
                color_mode(RGB, 255, 255, 255, 100)
         
     | 
| 
         @@ -24,28 +65,12 @@ class MultipleParticleSystems < Processing::App 
     | 
|
| 
       24 
65 
     | 
    
         
             
              end
         
     | 
| 
       25 
66 
     | 
    
         | 
| 
       26 
67 
     | 
    
         
             
              def mouse_pressed
         
     | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
      
 68 
     | 
    
         
            +
                origin = rand(21) + 5
         
     | 
| 
      
 69 
     | 
    
         
            +
                vector = Vector.new(mouse_x, mouse_y)
         
     | 
| 
      
 70 
     | 
    
         
            +
                @particle_systems << ParticleSystem.new(origin, vector)
         
     | 
| 
       28 
71 
     | 
    
         
             
              end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
               
     | 
| 
       31 
     | 
    
         
            -
                def run
         
     | 
| 
       32 
     | 
    
         
            -
                  self.reject! { |item| item.dead? }
         
     | 
| 
       33 
     | 
    
         
            -
                  self.each    { |item| item.run   }
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
              class ParticleSystem < Array
         
     | 
| 
       38 
     | 
    
         
            -
                include Runnable
         
     | 
| 
       39 
     | 
    
         
            -
                alias_method :dead?, :empty?
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                def initialize(number, origin)
         
     | 
| 
       42 
     | 
    
         
            -
                  super()
         
     | 
| 
       43 
     | 
    
         
            -
                  @origin = origin
         
     | 
| 
       44 
     | 
    
         
            -
                  kind = rand < 0.5 ? Particle : CrazyParticle
         
     | 
| 
       45 
     | 
    
         
            -
                  number.times { self << kind.new(origin) }
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
              end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
              
         
     | 
| 
      
 73 
     | 
    
         
            +
              
         
     | 
| 
       49 
74 
     | 
    
         
             
              class Particle
         
     | 
| 
       50 
75 
     | 
    
         
             
                def initialize(origin)
         
     | 
| 
       51 
76 
     | 
    
         
             
                  @origin = origin
         
     | 
| 
         @@ -76,30 +101,31 @@ class MultipleParticleSystems < Processing::App 
     | 
|
| 
       76 
101 
     | 
    
         
             
                end
         
     | 
| 
       77 
102 
     | 
    
         | 
| 
       78 
103 
     | 
    
         
             
                def render
         
     | 
| 
       79 
     | 
    
         
            -
                   
     | 
| 
       80 
     | 
    
         
            -
                   
     | 
| 
       81 
     | 
    
         
            -
                   
     | 
| 
      
 104 
     | 
    
         
            +
                  stroke(255, @lifespan)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  fill(100, @lifespan)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  ellipse(@origin.x, @origin.y, @radius, @radius)
         
     | 
| 
       82 
107 
     | 
    
         
             
                end
         
     | 
| 
       83 
108 
     | 
    
         | 
| 
       84 
109 
     | 
    
         
             
                def render_velocity_vector
         
     | 
| 
       85 
110 
     | 
    
         
             
                  scale = 10
         
     | 
| 
       86 
111 
     | 
    
         
             
                  arrow_size = 4
         
     | 
| 
       87 
112 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                   
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                   
     | 
| 
       91 
     | 
    
         
            -
                   
     | 
| 
      
 113 
     | 
    
         
            +
                  push_matrix
         
     | 
| 
      
 114 
     | 
    
         
            +
                  
         
     | 
| 
      
 115 
     | 
    
         
            +
                  translate(@origin.x, @origin.y)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  rotate(@velocity.heading)
         
     | 
| 
       92 
117 
     | 
    
         | 
| 
       93 
118 
     | 
    
         
             
                  length = @velocity.magnitude * scale
         
     | 
| 
       94 
119 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
                   
     | 
| 
       96 
     | 
    
         
            -
                   
     | 
| 
       97 
     | 
    
         
            -
                   
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
                   
     | 
| 
      
 120 
     | 
    
         
            +
                  line 0, 0, length, 0
         
     | 
| 
      
 121 
     | 
    
         
            +
                  line length, 0, length - arrow_size, arrow_size / 2
         
     | 
| 
      
 122 
     | 
    
         
            +
                  line length, 0, length - arrow_size, -arrow_size / 2
         
     | 
| 
      
 123 
     | 
    
         
            +
                  
         
     | 
| 
      
 124 
     | 
    
         
            +
                  pop_matrix
         
     | 
| 
       100 
125 
     | 
    
         
             
                end
         
     | 
| 
       101 
126 
     | 
    
         
             
              end
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 127 
     | 
    
         
            +
              
         
     | 
| 
      
 128 
     | 
    
         
            +
              
         
     | 
| 
       103 
129 
     | 
    
         
             
              class CrazyParticle < Particle
         
     | 
| 
       104 
130 
     | 
    
         
             
                def initialize(origin)
         
     | 
| 
       105 
131 
     | 
    
         
             
                  super
         
     | 
| 
         @@ -123,44 +149,19 @@ class MultipleParticleSystems < Processing::App 
     | 
|
| 
       123 
149 
     | 
    
         
             
                end
         
     | 
| 
       124 
150 
     | 
    
         | 
| 
       125 
151 
     | 
    
         
             
                def render_rotation_line
         
     | 
| 
       126 
     | 
    
         
            -
                   
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
                   
     | 
| 
       129 
     | 
    
         
            -
                   
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                   
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                   
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
                   
     | 
| 
       136 
     | 
    
         
            -
                end
         
     | 
| 
       137 
     | 
    
         
            -
              end
         
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
              class Vector
         
     | 
| 
       140 
     | 
    
         
            -
                attr_accessor :x, :y
         
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
                def initialize(x, y)
         
     | 
| 
       143 
     | 
    
         
            -
                  @x, @y = x, y
         
     | 
| 
       144 
     | 
    
         
            -
                end
         
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
                def +(other)
         
     | 
| 
       147 
     | 
    
         
            -
                  if other.is_a?(Numeric)
         
     | 
| 
       148 
     | 
    
         
            -
                    Vector.new(@x + other, @y + other)
         
     | 
| 
       149 
     | 
    
         
            -
                  elsif other.is_a?(Vector)
         
     | 
| 
       150 
     | 
    
         
            -
                    Vector.new(@x + other.x, @y + other.y)
         
     | 
| 
       151 
     | 
    
         
            -
                  else
         
     | 
| 
       152 
     | 
    
         
            -
                    self
         
     | 
| 
       153 
     | 
    
         
            -
                  end
         
     | 
| 
       154 
     | 
    
         
            -
                end
         
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
                def heading
         
     | 
| 
       157 
     | 
    
         
            -
                  -1 * Math::atan2(-@y, @x)
         
     | 
| 
       158 
     | 
    
         
            -
                end
         
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
                def magnitude
         
     | 
| 
       161 
     | 
    
         
            -
                  @x * @x + @y * @y
         
     | 
| 
      
 152 
     | 
    
         
            +
                  push_matrix
         
     | 
| 
      
 153 
     | 
    
         
            +
                  
         
     | 
| 
      
 154 
     | 
    
         
            +
                  translate(@origin.x, @origin.y)
         
     | 
| 
      
 155 
     | 
    
         
            +
                  rotate(@theta)
         
     | 
| 
      
 156 
     | 
    
         
            +
                  
         
     | 
| 
      
 157 
     | 
    
         
            +
                  stroke(255, @lifespan)
         
     | 
| 
      
 158 
     | 
    
         
            +
                  
         
     | 
| 
      
 159 
     | 
    
         
            +
                  line(0, 0, 25, 0)
         
     | 
| 
      
 160 
     | 
    
         
            +
                  
         
     | 
| 
      
 161 
     | 
    
         
            +
                  pop_matrix
         
     | 
| 
       162 
162 
     | 
    
         
             
                end
         
     | 
| 
       163 
163 
     | 
    
         
             
              end
         
     | 
| 
      
 164 
     | 
    
         
            +
              
         
     | 
| 
       164 
165 
     | 
    
         
             
            end
         
     | 
| 
       165 
166 
     | 
    
         | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
      
 167 
     | 
    
         
            +
            Sketch.new :width => 640, :height => 340
         
     | 
    
        data/samples/reflection.rb
    CHANGED
    
    | 
         @@ -1,26 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Taken from the Processing Examples.
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'ruby-processing'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            class Reflection < Processing::App
         
     | 
| 
       6 
     | 
    
         
            -
              
         
     | 
| 
       7 
     | 
    
         
            -
              def setup
         
     | 
| 
       8 
     | 
    
         
            -
                render_mode(P3D)
         
     | 
| 
       9 
     | 
    
         
            -
                no_stroke
         
     | 
| 
       10 
     | 
    
         
            -
                color_mode(RGB, 1)
         
     | 
| 
       11 
     | 
    
         
            -
                fill 0.4
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
              
         
     | 
| 
       14 
     | 
    
         
            -
              def draw
         
     | 
| 
       15 
     | 
    
         
            -
                background 0
         
     | 
| 
       16 
     | 
    
         
            -
                translate( width/2, height/2 )
         
     | 
| 
       17 
     | 
    
         
            -
                light_specular(1, 1, 1)
         
     | 
| 
       18 
     | 
    
         
            -
                directional_light(0.8, 0.8, 0.8, 0, 0, -1)
         
     | 
| 
       19 
     | 
    
         
            -
                s = mouse_x.to_f / width.to_f
         
     | 
| 
       20 
     | 
    
         
            -
                specular s, s, s
         
     | 
| 
       21 
     | 
    
         
            -
                sphere 50
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            def setup
         
     | 
| 
      
 4 
     | 
    
         
            +
              size 200, 200, P3D
         
     | 
| 
      
 5 
     | 
    
         
            +
              no_stroke
         
     | 
| 
      
 6 
     | 
    
         
            +
              color_mode RGB, 1
         
     | 
| 
      
 7 
     | 
    
         
            +
              fill 0.4
         
     | 
| 
       24 
8 
     | 
    
         
             
            end
         
     | 
| 
       25 
9 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
            def draw
         
     | 
| 
      
 11 
     | 
    
         
            +
              background          0
         
     | 
| 
      
 12 
     | 
    
         
            +
              translate           width/2, height/2 
         
     | 
| 
      
 13 
     | 
    
         
            +
              light_specular      1, 1, 1
         
     | 
| 
      
 14 
     | 
    
         
            +
              directional_light   0.8, 0.8, 0.8, 0, 0, -1
         
     | 
| 
      
 15 
     | 
    
         
            +
              specular            mouse_x.to_f / width.to_f
         
     | 
| 
      
 16 
     | 
    
         
            +
              sphere              50
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: ruby-processing
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jeremy Ashkenas
         
     | 
| 
         @@ -17,7 +17,7 @@ autorequire: 
     | 
|
| 
       17 
17 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       18 
18 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
            date: 2009- 
     | 
| 
      
 20 
     | 
    
         
            +
            date: 2009-04-05 00:00:00 -04:00
         
     | 
| 
       21 
21 
     | 
    
         
             
            default_executable: rp5
         
     | 
| 
       22 
22 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       23 
23 
     | 
    
         |