SlideShare ist ein Scribd-Unternehmen logo
1 von 191
Downloaden Sie, um offline zu lesen
 
                 


                        

  
                                  
                    Ruby Business Commons
2008   11   8                               1
 
                 
                 
                 



                     

                    Ruby Business Commons
2008   11   8                               2
 


                  




                     Ruby Business Commons
2008   11   8                                3
JRuby




                http://java.sun.com/javase/ja/6/download.html

                                                     Ruby Business Commons
2008   11   8                                                                4
Mac
                 dmg




                 http://www.apple.com/jp/ftp-info/reference/
                        javaformacosx105update2.html



                                                     Ruby Business Commons
2008   11   8                                                                5
Windows
                Mac
                        http://dist.codehaus.org/jruby/


                                                          Ruby Business Commons
2008   11   8                                                                     6
 
                 
                 




                    Ruby Business Commons
2008   11   8                               7
 




2008   11   8       8
2




2008   11   8       9
%JAVA_HOME%bin;%JRUBY_HOME%bin;




2008   11   8                          10
JAVA_HOME, JRUBY_HOME, PATH

                   Mac
                export JAVA_HOME=JDK
                export JRUBY_HOME=JRuby
                export PATH=$JRUBY_HOME/bin:$PATH




                                                Ruby Business Commons
2008   11   8                                                           11
 
                 
                 
                 



                     

                        Ruby Business Commons
2008   11   8                                   12
Ruby Business Commons
2008   11   8                           13
RBC




                      Ruby Business Commons
2008   11   8                                 14
 
                         
                ruby-processing

                        



                                      Ruby Business Commons
2008   11   8                                                 15
Ruby Business Commons
2008   11   8                           16
 
                                           
                    “




                        Ruby Business Commons
2008   11   8                                   17
Ruby Business Commons
2008   11   8                           18
Ruby Business Commons
2008   11   8                           19
Ruby Business Commons
2008   11   8                           20
Ruby Business Commons
2008   11   8                           21
 
                 
                 
                             



                    Ruby Business Commons
2008   11   8                               22
 


      




                Ruby Business Commons
2008   11   8                           23
java version quot;1.6.0quot;
                jruby 1.1.4




                             Ruby Business Commons
2008   11   8                                        24
JRuby




                http://java.sun.com/javase/ja/6/download.html

                                                     Ruby Business Commons
2008   11   8                                                                25
Mac
                 dmg




                 http://www.apple.com/jp/ftp-info/reference/
                        javaformacosx105update2.html



                                                     Ruby Business Commons
2008   11   8                                                                26
Windows
                Mac
                        http://dist.codehaus.org/jruby/


                                                          Ruby Business Commons
2008   11   8                                                                     27
 




2008   11   8       28
2




2008   11   8       29
%JAVA_HOME%bin;%JRUBY_HOME%bin;




2008   11   8                          30
JAVA_HOME, JRUBY_HOME, PATH

                   Mac
                export JAVA_HOME=JDK
                export JRUBY_HOME=JRuby
                export PATH=$JRUBY_HOME/bin:$PATH




                                                Ruby Business Commons
2008   11   8                                                           31
 
                 
                 
                 




                    Ruby Business Commons
2008   11   8                               32
 

                 

                               




                    Ruby Business Commons
2008   11   8                               33
 
                 
                 
                     

                        Ruby Business Commons
2008   11   8                                   34
 

                 




                    Ruby Business Commons
2008   11   8                               35
 
                 
                            


                    Ruby Business Commons
2008   11   8                               36
 


                http://www.haque.co.uk/
                             



                                          Ruby Business Commons
2008   11   8                                                     37
 
                 


                 
                           

                    Ruby Business Commons
2008   11   8                               38
rbc

                      Ruby Business Commons
2008   11   8                                 39
 
                         

                 



                    Ruby Business Commons
2008   11   8                               40
 
                     
                     
                     
                     
                     
                     
                     
                 
                                           
                        Ruby Business Commons
2008   11   8                                   41
 
                 

                 




                    Ruby Business Commons
2008   11   8                               42
 
                 




                    Ruby Business Commons
2008   11   8                               43
rbc




                      Ruby Business Commons
2008   11   8                                 44
C:ruby-processing>jruby script/generate rbc/rotate_rectangles.rb 400 400



                                     
                                                               




                                                     Ruby Business Commons
2008   11   8                                                                45
rbc

                      rotate_rectangles.rb
                                 
                                 
                                 
                                 
                                              


                                             Ruby Business Commons
2008   11   8                                                        46
Ruby Business Commons
2008   11   8                           47
1.


require 'ruby-processing'
class RotateRectangles < Processing::App
  def setup
  end
  def draw
  end
end
RotateRectangles.new :title => quot;Rotate Rectanglesquot;, :width =>
400, :height => 400
                                                    Ruby Business Commons
2008   11   8                                                               48
Windows

            generate
             Win




                           Ruby Business Commons
2008   11   8                                      49
C:ruby-processing> jruby script/generate rbc/rotate_rectangles.rb 400 400


                                       
                400x400




                                                      Ruby Business Commons
2008   11   8                                                                 50
generate
                          generate




                rotate_rectangles.rb                



                                       Ruby Business Commons
2008   11   8                                                  51
C:ruby-processing>jruby rbc/rotate_rectangles.rb



                                        
                                        
                                                      


                                                         Ruby Business Commons
2008   11   8                                                                    52
 
                    Ruby Business Commons
2008   11   8                               53
...
                      def setup
                      #
                      #
                      end
            400x400
                      def draw
                       #

                      end
                      ...



                                  Ruby Business Commons
2008   11   8                                             54
 
                 

                 
                 
                 
                     

                        Ruby Business Commons
2008   11   8                                   55
def setup
                 color_mode HSB, 100
                 background 0
                 no_stroke
                end

                def draw
                 5.times do |i|
                  i += 1
                  fill 30, i*20, 99
                  sz = 60 - i*10
                  rect 0, 0, sz, sz
                 end
                end                    Ruby Business Commons
2008   11   8                                                  56
USB




                      Ruby Business Commons
2008   11   8                                 57
Ruby Business Commons
2008   11   8                           58
C:ruby-processing>jruby rbc/rotate_rectangles.rb




                                                         Ruby Business Commons
2008   11   8                                                                    59
Ruby Business Commons
2008   11   8                           60
Ruby Business Commons
2008   11   8                           61
Ruby Business Commons
2008   11   8                           62
C:ruby-processingruby-processing.rb

C:ruby-processing>jirb -r irb/completion
irb(main):001:0> Dir.pwd
=> quot;C:/ruby-processingquot;
                                          Pretty Print!
irb(main):002:0> require 'pp'
=> true
irb(main):003:0> pp $LOAD_PATH
[quot;C:/jruby-1.1.4/lib/ruby/site_ruby/1.8quot;,
 quot;C:/jruby-1.1.4/lib/ruby/site_rubyquot;,
 quot;C:/jruby-1.1.4/lib/ruby/1.8quot;,
 quot;C:/jruby-1.1.4/lib/ruby/1.8/javaquot;,
 quot;lib/ruby/1.8quot;,                          $LOAD_PATH
 quot;.quot;]
=> nil


                                                      Ruby Business Commons
2008   11   8                                                                 63
x.times{|i|....}

        C:ruby-processing>jirb -r irb/completion

        irb(main):001:0> 5.times {|i| p i }
        0
        1
        2
        3
        4
        => 5

        irb(main):002:0>



                                                Ruby Business Commons
2008   11   8                                                           64
 
                                                        

                def draw
                 translate width/2, height/2
                 5.times do |i|
                   i += 1
                   fill 30, i*20, 99
                   sz = 60 - i*10
                   rect 0, 0, sz, sz
                 end
                end
                                               Ruby Business Commons
2008   11   8                                                          65
Ruby Business Commons
2008   11   8                           66
C:ruby-processing>jruby rbc/rotate_rectangles.rb




                                                        Ruby Business Commons
2008   11   8                                                                   67
Ruby Business Commons
2008   11   8                           68
 
                 
                 




                    Ruby Business Commons
2008   11   8                               69
 
                                                        
                def draw
                 translate width/2, height/2
                 rotate radians(45)
                 5.times do |i|
                   i += 1
                   fill 30, i*20, 99
                   sz = 60 - i*10
                   rect 0, 0, sz, sz
                 end
                end
                                               Ruby Business Commons
2008   11   8                                                          70
 
                 
                       
                 


                 
                              

                    Ruby Business Commons
2008   11   8                               71
 
                                                             
                require 'ruby-processing'

                class RotateRectangles < Processing::App
                 include Math

                 def radians(x)
                  return x*(PI/180)
                 end

                                                    Ruby Business Commons
2008   11   8                                                               72
Ruby Business Commons
2008   11   8                           73
C:ruby-processing>jruby rbc/rotate_rectangles.rb




                                                     Ruby Business Commons
2008   11   8                                                                74
Ruby Business Commons
2008   11   8                           75
Ruby Business Commons
2008   11   8                           76
require

 http://qwik.rubybizcommons.jp/518.html




2008   11   8                             77
Q&A




                http://groups.google.com/group/rbc-incubator




2008   11   8                                                  78
 
   def draw                       def draw
    translate width/2, height/2    translate width/2, height/2
                                   ary = (0..11).map{|a| a*30}
                                   ary.each do |r2|
                                    push_matrix
       rotate radians(45)           rotate radians(r2)
                                    translate 50, 0
                                    h = random 100
       5.times do |i|               5.times do |i|
        i += 1                       i += 1
        fill 30, i*20, 99             fill h, i*20, 99, 80
        sz = 60 - i*10                sz = 60 - i*10
        rect 0, 0, sz, sz            rect 0, 0, sz, sz
       end                          end
                                    pop_matrix
                                   end
   end                            end
                                                         Ruby Business Commons
2008   11   8                                                                    79
Ruby Business Commons
2008   11   8                           80
C:ruby-processing>jruby rbc/rotate_rectangles.rb




                                      
                       
                                      



                                                     Ruby Business Commons
2008   11   8                                                                81
Ruby Business Commons
2008   11   8                           82
ary = (0..11).map{|a| a*30}

                 ary.each do |r2|

                       push_martix




                                              Ruby Business Commons
2008   11   8                                                         83
 (0..11).map{|a| a * 30}

 C:>jirb -r irb/completion

 irb(main):001:0> ary = (0..11).map{|a| a * 30}

 => [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]

 irb(main):002:0> ary = (0..11).inject([]){ |a,n| a << n*30 }

 => [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]




                                                  Ruby Business Commons
2008   11   8                                                             84
 
                                                                             

                                          def draw
                                           translate width/2, height/2
       def draw                            ary = (0..11).map{ |a| a *30 }
        translate width/2, height/2        ary.each do |r1|
        ary = (0..11).map{|a| a*30}         push_matrix
                                            rotate radians(r1)
                                            translate 100, 0
                                            h = random 100



                                                       Ruby Business Commons
2008   11   8                                                                   85
 
            ary.each do|r2|            ary.each do |r2|
             push_matrix                push_matrix
             rotate radians(r2)         rotate radians(r2)
             translate 50, 0            translate 50, 0
             h= random 100
             5.times do |i|             5.times do |i|
               i += 1                    i += 1
               fill h, i*20, 99, 80      fill h, i*20, 99, 80
               sz = 60 - i*10            sz = 60 - i*10
               rect 0, 0, sz, sz         rect 0, 0, sz, sz
             end                        end
             pop_matrix                 pop_matrix
                                        end
         end
                                        pop_matrix
                                       end
        end
                                      end
                                                   Ruby Business Commons
2008   11   8                                                              86
Ruby Business Commons
2008   11   8                           87
C:ruby-processing>jruby rbc/rotate_rectangles.rb




                                                        Ruby Business Commons
2008   11   8                                                                   88
Ruby Business Commons
2008   11   8                           89
 

                    Ruby Business Commons
2008   11   8                               90
1.




                             
                     Ruby Business Commons
2008   11   8                                91
Ruby Business Commons
2008   11   8                           92
rbc
                       




                          Ruby Business Commons
2008   11   8                                     93
C:ruby-processing>jruby script/generate rbc/movable_dot.rb 300 300




                                    




                                                    Ruby Business Commons
2008   11   8                                                               94
movable_dot.rb
                       
                        
                        
                        
                                  

                                 Ruby Business Commons
2008   11   8                                            95
300×300
                           
                              Ruby Business Commons
2008   11   8                                         96
require 'ruby-processing'

                class MovableDot < Processing::App

                 def setup
                 end

                 def draw
                 end

                end

                MovableDot.new :title => quot;Movable Dotquot;, :width => 300, :height => 300




                                                                        Ruby Business Commons
2008   11   8                                                                                   97
Ruby Business Commons
2008   11   8                           98
 
                 

                 
                 
                 
                     

                        Ruby Business Commons
2008   11   8                                   99
Position


       require 'ruby-processing'

       class Position
       end
       class Rectangle < Position
       end                                  class MovableDot...

       class Dot
       end
       class MovableDot < Processing::App
                                                       Ruby Business Commons
2008   11   8                                                                  100
Ruby Business Commons
2008   11   8                           101
Ruby Business Commons
2008   11   8                           102
 

                 
                 



                    Ruby Business Commons
2008   11   8                               103
require 'ruby-processing'

                class Position
                                      
                  attr_accessor :x, :y
                end                   
                                      
                class Rectangle < Position
                end                   
                                      
                                      
                                             Ruby Business Commons
2008   11   8                                                        104
class Position
                 attr_accessor :x, :y
                                       
                 def initialize(x = 0, y = 0, &block)
                   move_to(x, y, &block)
                                       
                 end
                                       
                end                    
                                       
                                       

2008   11   8                                           105
class Position
                 attr_accessor :x, :y

                 def initialize(x = 0, y = 0, &block)
                  move_to(x, y, &block)
                 end

                 def move_to(x, y)
                  @x = block_given? ? yield(x) : x
                  @y = block_given? ? yield(y) : y
                 end
                end

2008   11   8                                           106
Ruby Business Commons
2008   11   8                           107
C:ruby-processing>jruby rbc/movable_dot.rb




                                   
                                   
                                   
                                           
                                                 Ruby Business Commons
2008   11   8                                                            108
 


                    Ruby Business Commons
2008   11   8                               109
 
                 
                 




                    Ruby Business Commons
2008   11   8                               110
irb(main):003:0> class Foo
            irb(main):004:1> attr_accessor :name
            irb(main):005:1> end
            => nil
                                                attr_accessor
            irb(main):006:0> foo = Foo.new
            => #<Foo:0x12ddfe4>

            irb(main):007:0> foo.name = quot;Barquot;
            => quot;Barquot;

            irb(main):008:0> puts foo.name
            Bar
            => nil                                       Ruby Business Commons
2008   11   8                                                                    111
:name
       Symbol


       irb(main):001:0> quot;fooquot;.to_s
       => quot;fooquot;
       irb(main):002:0> quot;fooquot;.to_sym
       => :foo
       irb(main):003:0> :foo.to_sym
       => :foo
       irb(main):004:0> :foo.to_s
       => quot;fooquot;


       irb(main):005:0> quot;fooquot;.is_a?(Symbol)
       => false
       irb(main):006:0> :foo.is_a?(String)
       => false                               Ruby Business Commons
2008   11   8                                                         112
Symbol
       Symbol


       irb(main):001:0> quot;fooquot;.object_id
       => 285710
       irb(main):002:0> quot;fooquot;.object_id
       => 278950
       #
       irb(main):003:0> :foo.object_id
       => 145858
       irb(main):004:0> :foo.object_id
       => 145858
       #
       #

                                          Ruby Business Commons
2008   11   8                                                     113
Symbol



       irb(main):026:0> quot;fooquot;.methods.size
       => 153
       irb(main):027:0> :foo.methods.size
       => 46




                                         Ruby Business Commons
2008   11   8                                                    114
Symbol

       irb(main):001:0> hash = {:x => 100, :y => 200}
       => {:x=>100, :y=>200}
       irb(main):002:0> hash[:x]
       => 100
       irb(main):002:0> hash[:y]
       => 200
       irb(main):002:0> hash[:z]
       => nil




                                           Ruby Business Commons
2008   11   8                                                      115
Symbol

       irb(main):013:0> def foo(options = {})
       irb(main):014:1> options[:bar]
       irb(main):015:1> end
       => nil
       irb(main):016:0> foo(:bar => 1)
       => 1
       irb(main):017:0> foo(:hoge => 2)
       => nil




                                           Ruby Business Commons
2008   11   8                                                      116
Symbol
       def foo(t, x)
        case x
        when 1 then t.strftime(quot;%Y/%m/%dquot;)
        when 2 then t.strftime(quot;%H:%M:%Squot;)
        end
       end
       foo(Time.now, 1)
       foo(Time.now, 2)



       def foo(t, x)
        case x
        when :date then t.strftime(quot;%Y/%m/%dquot;)
        when :time then t.strftime(quot;%H:%M:%Squot;)
        end
       end
       foo(Time.now, :time)
       foo(Time.now, :date)


                                                 Ruby Business Commons
2008   11   8                                                            117
 
                def initialize(x = 0, y = 0, &block)
                  move_to(x, y, &block)
                end
                                    



                                                Ruby Business Commons
2008   11   8                                                           118
new --> initialize
                irb(main):001:0> class Foo
                irb(main):002:1> attr_accessor :x, :y
                irb(main):003:1> def initialize(x = 0, y = 0)
                irb(main):004:2> @x, @y = x, y
                irb(main):005:2> end
                irb(main):006:1> end

                irb(main):007:0> foo = Foo.new
                => #<Foo:0x1c8b884 @y=0, @x=0>
                irb(main):008:0> foo.x
                => 0
                irb(main):009:0> foo.y
                => 0

                irb(main):010:0> bar = Foo.new(1, 2)
                => #<Foo:0x1a9883d @y=2, @x=1>
                irb(main):011:0> bar.x
                => 1
                irb(main):012:0> bar.y
                => 2

2008   11   8                                                   119
  def move_to(x, y)
                    @x = block_given? ? yield(x) : x
                    @y = block_given? ? yield(y) : y
                  end
   
                                    

                                                  Ruby Business Commons
2008   11   8                                                             120
irb(main):026:0> num = 1
=> 1
irb(main):027:0> num % 2 == 0 ? quot;evenquot; : quot;oddquot;
=> quot;oddquot;

irb(main):028:0> num = 2
=> 2
irb(main):029:0> num % 2 == 0 ? quot;evenquot; : quot;oddquot;
=> quot;evenquot;




2008   11   8                                    121
yield



 irb(main):050:0> block_1 = Proc.new {|x, y| puts x + y}
 => #<Proc:0x13a8eb1@(irb):51>

 irb(main):051:0> block_2 = proc {|x, y| puts x + y}
 => #<Proc:0x15200be@(irb):52>

 irb(main):052:0> block_3 = lambda {|x, y| puts x + y}
 => #<Proc:0x11b50a1@(irb):53>




2008   11   8                                              122
yield

 irb(main):053:0> block_1.call(1, 2)
 3
 => nil
 irb(main):054:0> block_1[1, 2]
 3
 => nil
 irb(main):055:0> block_2[1, 2]
 3
 => nil
 irb(main):056:0> block_3[1, 2]
 3
 => nil



2008   11   8                          123
yield

 irb(main):062:0> block_1[1, 2, 3]
 3
 => nil

 irb(main):063:0> block_2[1, 2, 3]
 ArgumentError: wrong number of arguments(3 for 2)


 irb(main):064:0> block_3[1, 2, 3]
 ArgumentError: wrong number of arguments(3 for 2)




2008   11   8                                        124
yield

 irb(main):071:0> def multiple(a, b, &block)
 irb(main):072:1> block[a, b]
 irb(main):073:1> end
 => nil
 irb(main):074:0> multiple(1, 2){|x, y| puts x + y}
 3
 => nil
 irb(main):075:0> def multiple(a, b)
 irb(main):076:1> yield a, b
 irb(main):077:1> end
 => nil
 irb(main):078:0> multiple(1, 2){|x, y| puts x + y}
 3
 => nil

2008   11   8                                         125
yield
irb(main):079:0> def multiple(a, b, &block)
irb(main):080:1> block[a, b, 3]
irb(main):081:1> end
=> nil
irb(main):082:0> multiple(1, 2){|x, y| puts x + y}
3
=> nil
irb(main):083:0> def multiple(a, b)
irb(main):084:1> yield a, b, 3
irb(main):085:1> end
=> nil
irb(main):086:0> multiple(1, 2){|x, y| puts x + y}
3
=> nil


2008   11   8                                        126
Rectangle


            class Rectangle < Position
                attr_accessor :width, :height
                def initialize(x, y, width, height)
                 super(x, y)
                 @width, @height = width, height
                end
                                                      Position
                def to_a
                 [@x, @y, @width, @height]
                end
            end
                                                        Ruby Business Commons
2008   11   8                                                                   127
Ruby Business Commons
2008   11   8                           128
 




                    Ruby Business Commons
2008   11   8                               129
 
                 
                         




                    Ruby Business Commons
2008   11   8                               130
class Dot
       include Math
       DEFAULT_SIZE = 10
       DEFAULT_MARGIN = 2
       def initialize(position, w = DEFAULT_SIZE , h = DEFAULT_SIZE)
        @app = Processing::App.current
        @rect = Rectangle.new(position.x, position.y, w, h)
       end
       def display
        c1 = @app.color(255, 255, 255, 255)
        @app.fill c1
        @app.rect(*@rect.to_a)
       end
   end
                                                      Ruby Business Commons
2008   11   8                                                                 131
Ruby Business Commons
2008   11   8                           132
C:ruby-processing>jruby rbc/movable_dot.rb




                                   
                                   
                                   
                                           
                                                 Ruby Business Commons
2008   11   8                                                            133
 
                 

                    Ruby Business Commons
2008   11   8                               134
@app.rect(*@rect.to_a)

                                        )

 irb(main):001:0> def to_a
 irb(main):002:1> [100, 200, 300, 400]
 irb(main):003:1> end

 irb(main):004:0> def foo(a, b=nil, c=nil, d=nil)
 irb(main):005:1> p a
 irb(main):006:1> p b
 irb(main):007:1> p c
 irb(main):008:1> p d
 irb(main):009:1> end

 irb(main):010:0> foo(to_a)
 irb(main):011:0> foo(*to_a)


2008   11   8                                       135
 
                 

                 



                    Ruby Business Commons
2008   11   8                               136
class MovableDot < Processing::App
 THE_NUM_OF_DOT = 20
 def setup
   @dots = []
   dot_size, dot_margin = Dot::DEFAULT_SIZE, Dot::DEFAULT_MARGIN
   THE_NUM_OF_DOT.times do |i|
    initial_position = Position.new(width, height) do |wh_value|
     i * (dot_size + dot_margin) + wh_value/2 - THE_NUM_OF_DOT *
((dot_size + dot_margin)/2)
    end
    @dots << Dot.new(initial_position)
   end
 end                                             Ruby Business Commons
2008   11   8                                                            137
 

            def draw
                background 0               
                @dots.each {|dot| dot.display}
                                           
         end
        end                               
                                          
        MovableDot.new :title => quot;Movable Dotquot;, :width => 300, :height => 300
                                          
                                          
                                          
                                          

                                                              Ruby Business Commons
2008   11   8                                                                         138
Ruby Business Commons
2008   11   8                           139
C:ruby-processing>jruby rbc/movable_dot.rb




                                   
                                   
                                   

                                                 Ruby Business Commons
2008   11   8                                                            140
 
2008   11   8       141
irb>> foo, bar = 1, 2
       => [1, 2]
       irb>> p foo
       1
       irb>> p bar
       2

       irb>> foo, bar = [5,6]
       => [5, 6]
       irb>> p foo
       5
       irb>> p bar
       6


                                Ruby Business Commons
2008   11   8                                           142
 

                                         
                                                            
 def display
  c1 = @app.color(255, 255, 255, 255)
  @app.fill c1
  @app.rect(*@rect.to_a)
 end

                         def display
                           c1 = @app.color(*(0..3).map{rand(255)})
                          @app.fill c1
                          @app.rect(*@rect.to_a)
                         end
                                                   Ruby Business Commons
2008   11   8                                                              143
Ruby Business Commons
2008   11   8                           144
C:ruby-processing>jruby rbc/movable_dot.rb




                                   
                                   
                                   

                                                 Ruby Business Commons
2008   11   8                                                            145
2008   11   8   146
*(0..3).map{rand(255)}

 irb(main):005:0> p (0..3).map{rand(255)}
 [36, 185, 183, 242]
 => nil

 irb(main):006:0> p *(0..3).map{rand(255)}
 98
 3
 227
 88
 => nil




2008   11   8                                147
 
                                                          
            class MovableDot < Processing::App

             THE_NUM_OF_DOT = 20

                def setup
                 frame_rate 1
                 @dots = []

                                                 Ruby Business Commons
2008   11   8                                                            148
Ruby Business Commons
2008   11   8                           149
C:ruby-processing>jruby rbc/movable_dot.rb




                                   
                                   
                                   
                                                 
                                                    Ruby Business Commons
2008   11   8                                                               150
2008   11   8   151
 
                                                               
                def display
                 c1 = @app.color(*(0..3).map{rand(255)})
                 @app.fill c1
                 @app.stroke c1
                 @app.rect(*@rect.to_a)
                end



                                                      Ruby Business Commons
2008   11   8                                                                 152
Ruby Business Commons
2008   11   8                           153
C:ruby-processing>jruby rbc/movable_dot.rb




                                   
                                   
                                   
                                             
                                                 Ruby Business Commons
2008   11   8                                                            154
2008   11   8   155
 
                 
                 
                 
                     
                 



2008   11   8           156
 
            @dots = [] dot_size, dot_margin = Dot::DEFAULT_SIZE,
            Dot::DEFAULT_MARGIN

                THE_NUM_OF_DOT.times do
                THE_NUM_OF_DOT.times do |i|
                 initial_position = Position.new(width, height) do |wh_value|
                  i * (dot_size + dot_margin) + wh_value/2 - THE_NUM_OF_DOT *
            ((dot_size + dot_margin)/2)
                 end
                 @dots << Dot.new(initial_position)
                end
                end                                  THE_NUM_OF_DOT
             end

                                                              Ruby Business Commons
2008   11   8                                                                         157
 
                    Ruby Business Commons
2008   11   8                               158
C:ruby-processing>jruby rbc/movable_dot.rb




                                                    Ruby Business Commons
2008   11   8                                                               159
2008   11   8   160
 
                 
                               
                    Ruby Business Commons
2008   11   8                               161
 
                require 'ruby-processing'
                class LoopQueue
                 def initialize(*items)       LoopQueue
                  @items = items            Dot
                  @index = 0
                 end
                 def next
                  @index += 1
                  @index = 0 if @index == @items.length
                  current
                 end
                 def current
                  @items[@index]
                 end
                end
2008   11   8                                                 162
Ruby Business Commons
2008   11   8                           163
 
                                                       yield
                 def move_to(x, y)
                  @x = block_given? ? yield(x, :x, @x) : x
                  @y = block_given? ? yield(y, :y, @y) : y
                 end


                 def move_by(dx, dy)
                  @x += block_given? ? yield(dx, :x, @x) : dx
                  @y += block_given? ? yield(dy, :y, @y) : dy
                 end
                end

                class Rectangle < Position


2008   11   8                                                       164
 
                                                                         

                def initialize(position, w = DEFAULT_SIZE , h = DEFAULT_SIZE)
                 @app = Processing::App.current
                 @rect = Rectangle.new(position.x, position.y, w, h)
                 @original_position = position.dup
                 @@dot_count ||= 0
                 @dot_num = (@@dot_count += 1)
                 @speed = 0.05                               @next
                 @next = Position.new
                end




2008   11   8                                                                   165
Numeric            
irb(main):001:0> 10 / 3
=> 3
irb(main):002:0> 10 / 3.0
=> 3.3333333333333335
irb(main):003:0> 10.0 / 3
=> 3.3333333333333335
irb(main):004:0> (10/3).class
=> Fixnum
irb(main):005:0> (10/0.3).class
=> Float
irb(main):006:0> (10.0/3).class
=> Float
irb(main):007:0> (10/3).to_f
=> 3.0

                                      Ruby Business Commons
2008   11   8                                                 166
 
 def move
  case @app.patterns.current
  when :line
   @next.move_to(@original_position.x, @original_position.y)
  when :circle
   @next.move_to(@app.width, @app.height) do |wh_value, attr|
     val, sin_or_cos = (attr == :x) ? [10, 'sin'] : [20, 'cos']
     (wh_value/2-val) * self.__send__(sin_or_cos, radians(@dot_num * 360/
@@dot_count)) + wh_value/2
   end
  else
   raise NameError, quot;Unsupported pattern: #{@app.patterns.current.inspect}quot;
  end
  @rect.move_by(@rect.x - @next.x, @rect.y - @next.y) do |value, attr|
   -(value * @speed)
  end
 end

2008   11   8                                                                 167
 
                                         
                 end
                end

                def radians(x)
                 x * (PI/180)
                end
                def display
                 c1 = @app.color(*(0..3).map{rand(255)})




2008   11   8                                              168
Ruby Business Commons
2008   11   8                           169
(wh_value/2-val) * self.__send__(sin_or_cos,
       radians(@dot_num * 360/@@dot_count)) + wh_value/2

                           x      =

                           y      =
                                         


2008   11   8                                              170
case
  irb(main):002:0> def case_test(o)
  irb(main):003:1> case o
  irb(main):004:2> when String : quot;This is String.quot;
  irb(main):005:2> when Fixnum : quot;This is Fixnum.quot;
  irb(main):006:2> when Array : quot;This is Array.quot;
  irb(main):007:2> end
  irb(main):008:1> end
  => nil
  irb(main):009:0> case_test(1)            Attention!!
  => quot;This is Fixnum.quot;                Ruby1.9
  irb(main):010:0> case_test([1,2])
  => quot;This is Array.quot;
  irb(main):011:0> case_test(quot;RBCquot;)
  => quot;This is String.quot;
  irb(main):012:0>

                                             Ruby Business Commons
2008   11   8                                                        171
send
irb(main):001:0> t = Time.now
=> Wed Nov 08 00:07:41 +0900 2008
irb(main):002:0> t.year
=> 2008                         send
irb(main):003:0> t.month
=> 11
irb(main):004:0> t.day
=> 8
irb(main):005:0> t.send(:year)
=> 2008
irb(main):006:0> t.send(:month)
=> 11
irb(main):007:0> t.send(:day)
=> 8

                                       Ruby Business Commons
2008   11   8                                                  172
send

irb(main):001:0> t = Time.now
=> Wed Nov 08 00:07:41 +0900 2008
irb(main):002:0> t.strftime('%Y/%m/%d %H:%M:%S')
=> quot;2008/11/05 00:07:41quot;
irb(main):003:0> t.send(:strfrime, '%Y/%m/%d %H:%M:%S')
=> quot;2008/11/05 00:07:41quot;




                                          Ruby Business Commons
2008   11   8                                                     173
send
irb(main):001:0> class Foo
irb(main):002:1> attr_accessor :bar
irb(main):003:1> end
=> nil
irb(main):004:0> foo = Foo.new
=> #<Foo:0x7e1596>
irb(main):005:0> foo.bar = quot;AAAquot;
=> quot;AAAquot;
irb(main):006:0> foo.send(:bar=, quot;BBBquot;)
=> quot;BBBquot;
irb(main):007:0> foo.bar
=> quot;BBBquot;




                                          Ruby Business Commons
2008   11   8                                                     174
 
                                                                   

                class MovableDot < Processing::App


                 attr_accessor :patterns             frame_rate
                 THE_NUM_OF_DOT = 20

                 def setup
                         5
                  frame_rate
                  @patterns = LoopQueue.new(:line, :circle)
                  @dots = []



2008   11   8                                                         175
 
                                        
                                                               

                def draw
                 background 0
                 @dots.each {|dot| dot.display;   dot.move}
                end

                def mouse_pressed
                 @patterns.next
                end


2008   11   8                                                     176
Ruby Business Commons
2008   11   8                           177
C:ruby-processing>jruby rbc/movable_dot.rb




                                   



                                                 Ruby Business Commons
2008   11   8                                                            178
2008   11   8   179
 
                                                                 

     val, sin_or_cos = (attr == :x) ? [10, 'sin'] : [20, 'cos']
     (wh_value/2-val) * self.__send__(sin_or_cos, radians(@dot_num * 360/
@@dot_count)) + wh_value/2
   end
  when :center
   @next.move_to(@app.width/2, @app.height/2)
  when :random
   @next.move_by(@app.width/8, @app.height/8) do |value, attr|
     @app.random(-value, value)
   end
  else
   raise NameError, quot;Unsupported pattern:
#{@app.patterns.current.inspect}quot;
                                                       Ruby Business Commons
2008   11   8                                                                  180
 

                def setup
                 frame_rate 5
                 @patterns = LoopQueue.new(:line, :circle,   :center, :random)
                 @dots = []




                                                
                                                

                                                                   Ruby Business Commons
2008   11   8                                                                              181
Ruby Business Commons
2008   11   8                           182
C:ruby-processing>jruby rbc/movable_dot.rb




                                   
                                   
                                   


                                                 Ruby Business Commons
2008   11   8                                                            183
400                        




                      Ruby Business Commons
2008   11   8                                 184
Ruby Business Commons
2008   11   8                           185
2008   11   8   186
Ruby Business Commons
2008   11   8                           187
Ruby Business Commons
2008   11   8                           188
Ruby Business Commons
2008   11   8                           189
Ruby




http://qwik.rubybizcommons.jp/members/2.html



                                Ruby Business Commons
2008   11   8                                           190
Ruby Business Commons
2008   11   8                           191

Weitere ähnliche Inhalte

Mehr von mochiko AsTech

About technical docs that connect people and technology
About technical docs that connect people and technologyAbout technical docs that connect people and technology
About technical docs that connect people and technologymochiko AsTech
 
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説mochiko AsTech
 
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編mochiko AsTech
 
20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編mochiko AsTech
 
アウトプットの価値
アウトプットの価値アウトプットの価値
アウトプットの価値mochiko AsTech
 
WiiリモコンでMacBookを操る
WiiリモコンでMacBookを操るWiiリモコンでMacBookを操る
WiiリモコンでMacBookを操るmochiko AsTech
 
写真で振り返るABCクッキング
写真で振り返るABCクッキング写真で振り返るABCクッキング
写真で振り返るABCクッキングmochiko AsTech
 
勉強会へ行こう!
勉強会へ行こう!勉強会へ行こう!
勉強会へ行こう!mochiko AsTech
 
PHP使いから見たRuby(Talking about PHP & Ruby)
PHP使いから見たRuby(Talking about PHP & Ruby)PHP使いから見たRuby(Talking about PHP & Ruby)
PHP使いから見たRuby(Talking about PHP & Ruby)mochiko AsTech
 

Mehr von mochiko AsTech (10)

About technical docs that connect people and technology
About technical docs that connect people and technologyAbout technical docs that connect people and technology
About technical docs that connect people and technology
 
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説
 
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編
 
20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編
 
アウトプットの価値
アウトプットの価値アウトプットの価値
アウトプットの価値
 
WiiリモコンでMacBookを操る
WiiリモコンでMacBookを操るWiiリモコンでMacBookを操る
WiiリモコンでMacBookを操る
 
写真で振り返るABCクッキング
写真で振り返るABCクッキング写真で振り返るABCクッキング
写真で振り返るABCクッキング
 
勉強会へ行こう!
勉強会へ行こう!勉強会へ行こう!
勉強会へ行こう!
 
5分で分かるcron
5分で分かるcron5分で分かるcron
5分で分かるcron
 
PHP使いから見たRuby(Talking about PHP & Ruby)
PHP使いから見たRuby(Talking about PHP & Ruby)PHP使いから見たRuby(Talking about PHP & Ruby)
PHP使いから見たRuby(Talking about PHP & Ruby)
 

Kürzlich hochgeladen

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Kürzlich hochgeladen (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Ruby Business Commons document collection

  • 1.           Ruby Business Commons 2008 11 8 1
  • 2.           Ruby Business Commons 2008 11 8 2
  • 3.          Ruby Business Commons 2008 11 8 3
  • 4. JRuby http://java.sun.com/javase/ja/6/download.html Ruby Business Commons 2008 11 8 4
  • 5. Mac dmg http://www.apple.com/jp/ftp-info/reference/ javaformacosx105update2.html Ruby Business Commons 2008 11 8 5
  • 6. Windows Mac http://dist.codehaus.org/jruby/ Ruby Business Commons 2008 11 8 6
  • 7.       Ruby Business Commons 2008 11 8 7
  • 8.   2008 11 8 8
  • 9. 2 2008 11 8 9
  • 11. JAVA_HOME, JRUBY_HOME, PATH Mac export JAVA_HOME=JDK export JRUBY_HOME=JRuby export PATH=$JRUBY_HOME/bin:$PATH Ruby Business Commons 2008 11 8 11
  • 12.           Ruby Business Commons 2008 11 8 12
  • 14. RBC Ruby Business Commons 2008 11 8 14
  • 15.     ruby-processing   Ruby Business Commons 2008 11 8 15
  • 17.     “ Ruby Business Commons 2008 11 8 17
  • 22.         Ruby Business Commons 2008 11 8 22
  • 23.          Ruby Business Commons 2008 11 8 23
  • 24. java version quot;1.6.0quot; jruby 1.1.4 Ruby Business Commons 2008 11 8 24
  • 25. JRuby http://java.sun.com/javase/ja/6/download.html Ruby Business Commons 2008 11 8 25
  • 26. Mac dmg http://www.apple.com/jp/ftp-info/reference/ javaformacosx105update2.html Ruby Business Commons 2008 11 8 26
  • 27. Windows Mac http://dist.codehaus.org/jruby/ Ruby Business Commons 2008 11 8 27
  • 28.   2008 11 8 28
  • 29. 2 2008 11 8 29
  • 31. JAVA_HOME, JRUBY_HOME, PATH Mac export JAVA_HOME=JDK export JRUBY_HOME=JRuby export PATH=$JRUBY_HOME/bin:$PATH Ruby Business Commons 2008 11 8 31
  • 32.         Ruby Business Commons 2008 11 8 32
  • 33.       Ruby Business Commons 2008 11 8 33
  • 34.         Ruby Business Commons 2008 11 8 34
  • 35.     Ruby Business Commons 2008 11 8 35
  • 36.       Ruby Business Commons 2008 11 8 36
  • 37.   http://www.haque.co.uk/    Ruby Business Commons 2008 11 8 37
  • 38.         Ruby Business Commons 2008 11 8 38
  • 39. rbc Ruby Business Commons 2008 11 8 39
  • 40.       Ruby Business Commons 2008 11 8 40
  • 41.                       Ruby Business Commons 2008 11 8 41
  • 42.       Ruby Business Commons 2008 11 8 42
  • 43.     Ruby Business Commons 2008 11 8 43
  • 44. rbc Ruby Business Commons 2008 11 8 44
  • 45. C:ruby-processing>jruby script/generate rbc/rotate_rectangles.rb 400 400     Ruby Business Commons 2008 11 8 45
  • 46. rbc rotate_rectangles.rb           Ruby Business Commons 2008 11 8 46
  • 48. 1. require 'ruby-processing' class RotateRectangles < Processing::App def setup end def draw end end RotateRectangles.new :title => quot;Rotate Rectanglesquot;, :width => 400, :height => 400 Ruby Business Commons 2008 11 8 48
  • 49. Windows generate Win Ruby Business Commons 2008 11 8 49
  • 50. C:ruby-processing> jruby script/generate rbc/rotate_rectangles.rb 400 400   400x400 Ruby Business Commons 2008 11 8 50
  • 51. generate generate rotate_rectangles.rb   Ruby Business Commons 2008 11 8 51
  • 52. C:ruby-processing>jruby rbc/rotate_rectangles.rb       Ruby Business Commons 2008 11 8 52
  • 53.   Ruby Business Commons 2008 11 8 53
  • 54. ... def setup # # end 400x400 def draw # end ... Ruby Business Commons 2008 11 8 54
  • 55.             Ruby Business Commons 2008 11 8 55
  • 56. def setup color_mode HSB, 100 background 0 no_stroke end def draw 5.times do |i| i += 1 fill 30, i*20, 99 sz = 60 - i*10 rect 0, 0, sz, sz end end Ruby Business Commons 2008 11 8 56
  • 57. USB Ruby Business Commons 2008 11 8 57
  • 59. C:ruby-processing>jruby rbc/rotate_rectangles.rb Ruby Business Commons 2008 11 8 59
  • 63. C:ruby-processingruby-processing.rb C:ruby-processing>jirb -r irb/completion irb(main):001:0> Dir.pwd => quot;C:/ruby-processingquot; Pretty Print! irb(main):002:0> require 'pp' => true irb(main):003:0> pp $LOAD_PATH [quot;C:/jruby-1.1.4/lib/ruby/site_ruby/1.8quot;, quot;C:/jruby-1.1.4/lib/ruby/site_rubyquot;, quot;C:/jruby-1.1.4/lib/ruby/1.8quot;, quot;C:/jruby-1.1.4/lib/ruby/1.8/javaquot;, quot;lib/ruby/1.8quot;, $LOAD_PATH quot;.quot;] => nil Ruby Business Commons 2008 11 8 63
  • 64. x.times{|i|....} C:ruby-processing>jirb -r irb/completion irb(main):001:0> 5.times {|i| p i } 0 1 2 3 4 => 5 irb(main):002:0> Ruby Business Commons 2008 11 8 64
  • 65.     def draw translate width/2, height/2 5.times do |i| i += 1 fill 30, i*20, 99 sz = 60 - i*10 rect 0, 0, sz, sz end end Ruby Business Commons 2008 11 8 65
  • 67. C:ruby-processing>jruby rbc/rotate_rectangles.rb Ruby Business Commons 2008 11 8 67
  • 69.       Ruby Business Commons 2008 11 8 69
  • 70.     def draw translate width/2, height/2 rotate radians(45) 5.times do |i| i += 1 fill 30, i*20, 99 sz = 60 - i*10 rect 0, 0, sz, sz end end Ruby Business Commons 2008 11 8 70
  • 71.             Ruby Business Commons 2008 11 8 71
  • 72.     require 'ruby-processing' class RotateRectangles < Processing::App include Math def radians(x) return x*(PI/180) end Ruby Business Commons 2008 11 8 72
  • 74. C:ruby-processing>jruby rbc/rotate_rectangles.rb Ruby Business Commons 2008 11 8 74
  • 78. Q&A http://groups.google.com/group/rbc-incubator 2008 11 8 78
  • 79.   def draw def draw translate width/2, height/2 translate width/2, height/2 ary = (0..11).map{|a| a*30} ary.each do |r2| push_matrix rotate radians(45) rotate radians(r2) translate 50, 0 h = random 100 5.times do |i| 5.times do |i| i += 1 i += 1 fill 30, i*20, 99 fill h, i*20, 99, 80 sz = 60 - i*10 sz = 60 - i*10 rect 0, 0, sz, sz rect 0, 0, sz, sz end end pop_matrix end end end Ruby Business Commons 2008 11 8 79
  • 81. C:ruby-processing>jruby rbc/rotate_rectangles.rb       Ruby Business Commons 2008 11 8 81
  • 83. ary = (0..11).map{|a| a*30} ary.each do |r2| push_martix Ruby Business Commons 2008 11 8 83
  • 84.  (0..11).map{|a| a * 30} C:>jirb -r irb/completion irb(main):001:0> ary = (0..11).map{|a| a * 30} => [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330] irb(main):002:0> ary = (0..11).inject([]){ |a,n| a << n*30 } => [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330] Ruby Business Commons 2008 11 8 84
  • 85.     def draw translate width/2, height/2 def draw ary = (0..11).map{ |a| a *30 } translate width/2, height/2 ary.each do |r1| ary = (0..11).map{|a| a*30} push_matrix rotate radians(r1) translate 100, 0 h = random 100 Ruby Business Commons 2008 11 8 85
  • 86.   ary.each do|r2| ary.each do |r2| push_matrix push_matrix rotate radians(r2) rotate radians(r2) translate 50, 0 translate 50, 0 h= random 100 5.times do |i| 5.times do |i| i += 1 i += 1 fill h, i*20, 99, 80 fill h, i*20, 99, 80 sz = 60 - i*10 sz = 60 - i*10 rect 0, 0, sz, sz rect 0, 0, sz, sz end end pop_matrix pop_matrix end end pop_matrix end end end Ruby Business Commons 2008 11 8 86
  • 88. C:ruby-processing>jruby rbc/rotate_rectangles.rb Ruby Business Commons 2008 11 8 88
  • 90.   Ruby Business Commons 2008 11 8 90
  • 91. 1.   Ruby Business Commons 2008 11 8 91
  • 93. rbc   Ruby Business Commons 2008 11 8 93
  • 94. C:ruby-processing>jruby script/generate rbc/movable_dot.rb 300 300   Ruby Business Commons 2008 11 8 94
  • 95. movable_dot.rb           Ruby Business Commons 2008 11 8 95
  • 96. 300×300   Ruby Business Commons 2008 11 8 96
  • 97. require 'ruby-processing' class MovableDot < Processing::App def setup end def draw end end MovableDot.new :title => quot;Movable Dotquot;, :width => 300, :height => 300 Ruby Business Commons 2008 11 8 97
  • 99.             Ruby Business Commons 2008 11 8 99
  • 100. Position require 'ruby-processing' class Position end class Rectangle < Position end class MovableDot... class Dot end class MovableDot < Processing::App Ruby Business Commons 2008 11 8 100
  • 103.       Ruby Business Commons 2008 11 8 103
  • 104. require 'ruby-processing' class Position   attr_accessor :x, :y end     class Rectangle < Position end       Ruby Business Commons 2008 11 8 104
  • 105. class Position attr_accessor :x, :y   def initialize(x = 0, y = 0, &block) move_to(x, y, &block)   end   end       2008 11 8 105
  • 106. class Position attr_accessor :x, :y def initialize(x = 0, y = 0, &block) move_to(x, y, &block) end def move_to(x, y) @x = block_given? ? yield(x) : x @y = block_given? ? yield(y) : y end end 2008 11 8 106
  • 108. C:ruby-processing>jruby rbc/movable_dot.rb         Ruby Business Commons 2008 11 8 108
  • 109.   Ruby Business Commons 2008 11 8 109
  • 110.       Ruby Business Commons 2008 11 8 110
  • 111. irb(main):003:0> class Foo irb(main):004:1> attr_accessor :name irb(main):005:1> end => nil attr_accessor irb(main):006:0> foo = Foo.new => #<Foo:0x12ddfe4> irb(main):007:0> foo.name = quot;Barquot; => quot;Barquot; irb(main):008:0> puts foo.name Bar => nil Ruby Business Commons 2008 11 8 111
  • 112. :name Symbol irb(main):001:0> quot;fooquot;.to_s => quot;fooquot; irb(main):002:0> quot;fooquot;.to_sym => :foo irb(main):003:0> :foo.to_sym => :foo irb(main):004:0> :foo.to_s => quot;fooquot; irb(main):005:0> quot;fooquot;.is_a?(Symbol) => false irb(main):006:0> :foo.is_a?(String) => false Ruby Business Commons 2008 11 8 112
  • 113. Symbol Symbol irb(main):001:0> quot;fooquot;.object_id => 285710 irb(main):002:0> quot;fooquot;.object_id => 278950 # irb(main):003:0> :foo.object_id => 145858 irb(main):004:0> :foo.object_id => 145858 # # Ruby Business Commons 2008 11 8 113
  • 114. Symbol irb(main):026:0> quot;fooquot;.methods.size => 153 irb(main):027:0> :foo.methods.size => 46 Ruby Business Commons 2008 11 8 114
  • 115. Symbol irb(main):001:0> hash = {:x => 100, :y => 200} => {:x=>100, :y=>200} irb(main):002:0> hash[:x] => 100 irb(main):002:0> hash[:y] => 200 irb(main):002:0> hash[:z] => nil Ruby Business Commons 2008 11 8 115
  • 116. Symbol irb(main):013:0> def foo(options = {}) irb(main):014:1> options[:bar] irb(main):015:1> end => nil irb(main):016:0> foo(:bar => 1) => 1 irb(main):017:0> foo(:hoge => 2) => nil Ruby Business Commons 2008 11 8 116
  • 117. Symbol def foo(t, x) case x when 1 then t.strftime(quot;%Y/%m/%dquot;) when 2 then t.strftime(quot;%H:%M:%Squot;) end end foo(Time.now, 1) foo(Time.now, 2) def foo(t, x) case x when :date then t.strftime(quot;%Y/%m/%dquot;) when :time then t.strftime(quot;%H:%M:%Squot;) end end foo(Time.now, :time) foo(Time.now, :date) Ruby Business Commons 2008 11 8 117
  • 118.   def initialize(x = 0, y = 0, &block) move_to(x, y, &block) end   Ruby Business Commons 2008 11 8 118
  • 119. new --> initialize irb(main):001:0> class Foo irb(main):002:1> attr_accessor :x, :y irb(main):003:1> def initialize(x = 0, y = 0) irb(main):004:2> @x, @y = x, y irb(main):005:2> end irb(main):006:1> end irb(main):007:0> foo = Foo.new => #<Foo:0x1c8b884 @y=0, @x=0> irb(main):008:0> foo.x => 0 irb(main):009:0> foo.y => 0 irb(main):010:0> bar = Foo.new(1, 2) => #<Foo:0x1a9883d @y=2, @x=1> irb(main):011:0> bar.x => 1 irb(main):012:0> bar.y => 2 2008 11 8 119
  • 120.   def move_to(x, y)     @x = block_given? ? yield(x) : x     @y = block_given? ? yield(y) : y   end     Ruby Business Commons 2008 11 8 120
  • 121. irb(main):026:0> num = 1 => 1 irb(main):027:0> num % 2 == 0 ? quot;evenquot; : quot;oddquot; => quot;oddquot; irb(main):028:0> num = 2 => 2 irb(main):029:0> num % 2 == 0 ? quot;evenquot; : quot;oddquot; => quot;evenquot; 2008 11 8 121
  • 122. yield irb(main):050:0> block_1 = Proc.new {|x, y| puts x + y} => #<Proc:0x13a8eb1@(irb):51> irb(main):051:0> block_2 = proc {|x, y| puts x + y} => #<Proc:0x15200be@(irb):52> irb(main):052:0> block_3 = lambda {|x, y| puts x + y} => #<Proc:0x11b50a1@(irb):53> 2008 11 8 122
  • 123. yield irb(main):053:0> block_1.call(1, 2) 3 => nil irb(main):054:0> block_1[1, 2] 3 => nil irb(main):055:0> block_2[1, 2] 3 => nil irb(main):056:0> block_3[1, 2] 3 => nil 2008 11 8 123
  • 124. yield irb(main):062:0> block_1[1, 2, 3] 3 => nil irb(main):063:0> block_2[1, 2, 3] ArgumentError: wrong number of arguments(3 for 2) irb(main):064:0> block_3[1, 2, 3] ArgumentError: wrong number of arguments(3 for 2) 2008 11 8 124
  • 125. yield irb(main):071:0> def multiple(a, b, &block) irb(main):072:1> block[a, b] irb(main):073:1> end => nil irb(main):074:0> multiple(1, 2){|x, y| puts x + y} 3 => nil irb(main):075:0> def multiple(a, b) irb(main):076:1> yield a, b irb(main):077:1> end => nil irb(main):078:0> multiple(1, 2){|x, y| puts x + y} 3 => nil 2008 11 8 125
  • 126. yield irb(main):079:0> def multiple(a, b, &block) irb(main):080:1> block[a, b, 3] irb(main):081:1> end => nil irb(main):082:0> multiple(1, 2){|x, y| puts x + y} 3 => nil irb(main):083:0> def multiple(a, b) irb(main):084:1> yield a, b, 3 irb(main):085:1> end => nil irb(main):086:0> multiple(1, 2){|x, y| puts x + y} 3 => nil 2008 11 8 126
  • 127. Rectangle class Rectangle < Position attr_accessor :width, :height def initialize(x, y, width, height) super(x, y) @width, @height = width, height end Position def to_a [@x, @y, @width, @height] end end Ruby Business Commons 2008 11 8 127
  • 129.   Ruby Business Commons 2008 11 8 129
  • 130.       Ruby Business Commons 2008 11 8 130
  • 131. class Dot include Math DEFAULT_SIZE = 10 DEFAULT_MARGIN = 2 def initialize(position, w = DEFAULT_SIZE , h = DEFAULT_SIZE) @app = Processing::App.current @rect = Rectangle.new(position.x, position.y, w, h) end def display c1 = @app.color(255, 255, 255, 255) @app.fill c1 @app.rect(*@rect.to_a) end end Ruby Business Commons 2008 11 8 131
  • 133. C:ruby-processing>jruby rbc/movable_dot.rb         Ruby Business Commons 2008 11 8 133
  • 134.     Ruby Business Commons 2008 11 8 134
  • 135. @app.rect(*@rect.to_a) ) irb(main):001:0> def to_a irb(main):002:1> [100, 200, 300, 400] irb(main):003:1> end irb(main):004:0> def foo(a, b=nil, c=nil, d=nil) irb(main):005:1> p a irb(main):006:1> p b irb(main):007:1> p c irb(main):008:1> p d irb(main):009:1> end irb(main):010:0> foo(to_a) irb(main):011:0> foo(*to_a) 2008 11 8 135
  • 136.       Ruby Business Commons 2008 11 8 136
  • 137. class MovableDot < Processing::App THE_NUM_OF_DOT = 20 def setup @dots = [] dot_size, dot_margin = Dot::DEFAULT_SIZE, Dot::DEFAULT_MARGIN THE_NUM_OF_DOT.times do |i| initial_position = Position.new(width, height) do |wh_value| i * (dot_size + dot_margin) + wh_value/2 - THE_NUM_OF_DOT * ((dot_size + dot_margin)/2) end @dots << Dot.new(initial_position) end end Ruby Business Commons 2008 11 8 137
  • 138.   def draw background 0   @dots.each {|dot| dot.display}   end end     MovableDot.new :title => quot;Movable Dotquot;, :width => 300, :height => 300         Ruby Business Commons 2008 11 8 138
  • 140. C:ruby-processing>jruby rbc/movable_dot.rb       Ruby Business Commons 2008 11 8 140
  • 141.   2008 11 8 141
  • 142. irb>> foo, bar = 1, 2 => [1, 2] irb>> p foo 1 irb>> p bar 2 irb>> foo, bar = [5,6] => [5, 6] irb>> p foo 5 irb>> p bar 6 Ruby Business Commons 2008 11 8 142
  • 143.       def display c1 = @app.color(255, 255, 255, 255) @app.fill c1 @app.rect(*@rect.to_a) end def display c1 = @app.color(*(0..3).map{rand(255)}) @app.fill c1 @app.rect(*@rect.to_a) end Ruby Business Commons 2008 11 8 143
  • 145. C:ruby-processing>jruby rbc/movable_dot.rb       Ruby Business Commons 2008 11 8 145
  • 146. 2008 11 8 146
  • 147. *(0..3).map{rand(255)} irb(main):005:0> p (0..3).map{rand(255)} [36, 185, 183, 242] => nil irb(main):006:0> p *(0..3).map{rand(255)} 98 3 227 88 => nil 2008 11 8 147
  • 148.     class MovableDot < Processing::App THE_NUM_OF_DOT = 20 def setup frame_rate 1 @dots = [] Ruby Business Commons 2008 11 8 148
  • 150. C:ruby-processing>jruby rbc/movable_dot.rb         Ruby Business Commons 2008 11 8 150
  • 151. 2008 11 8 151
  • 152.     def display c1 = @app.color(*(0..3).map{rand(255)}) @app.fill c1 @app.stroke c1 @app.rect(*@rect.to_a) end Ruby Business Commons 2008 11 8 152
  • 154. C:ruby-processing>jruby rbc/movable_dot.rb         Ruby Business Commons 2008 11 8 154
  • 155. 2008 11 8 155
  • 156.             2008 11 8 156
  • 157.   @dots = [] dot_size, dot_margin = Dot::DEFAULT_SIZE, Dot::DEFAULT_MARGIN THE_NUM_OF_DOT.times do THE_NUM_OF_DOT.times do |i| initial_position = Position.new(width, height) do |wh_value| i * (dot_size + dot_margin) + wh_value/2 - THE_NUM_OF_DOT * ((dot_size + dot_margin)/2) end @dots << Dot.new(initial_position) end end THE_NUM_OF_DOT end Ruby Business Commons 2008 11 8 157
  • 158.   Ruby Business Commons 2008 11 8 158
  • 159. C:ruby-processing>jruby rbc/movable_dot.rb Ruby Business Commons 2008 11 8 159
  • 160. 2008 11 8 160
  • 161.       Ruby Business Commons 2008 11 8 161
  • 162.   require 'ruby-processing' class LoopQueue def initialize(*items) LoopQueue @items = items Dot @index = 0 end def next @index += 1 @index = 0 if @index == @items.length current end def current @items[@index] end end 2008 11 8 162
  • 164.   yield def move_to(x, y) @x = block_given? ? yield(x, :x, @x) : x @y = block_given? ? yield(y, :y, @y) : y end def move_by(dx, dy) @x += block_given? ? yield(dx, :x, @x) : dx @y += block_given? ? yield(dy, :y, @y) : dy end end class Rectangle < Position 2008 11 8 164
  • 165.     def initialize(position, w = DEFAULT_SIZE , h = DEFAULT_SIZE) @app = Processing::App.current @rect = Rectangle.new(position.x, position.y, w, h) @original_position = position.dup @@dot_count ||= 0 @dot_num = (@@dot_count += 1) @speed = 0.05 @next @next = Position.new end 2008 11 8 165
  • 166. Numeric   irb(main):001:0> 10 / 3 => 3 irb(main):002:0> 10 / 3.0 => 3.3333333333333335 irb(main):003:0> 10.0 / 3 => 3.3333333333333335 irb(main):004:0> (10/3).class => Fixnum irb(main):005:0> (10/0.3).class => Float irb(main):006:0> (10.0/3).class => Float irb(main):007:0> (10/3).to_f => 3.0 Ruby Business Commons 2008 11 8 166
  • 167.   def move case @app.patterns.current when :line @next.move_to(@original_position.x, @original_position.y) when :circle @next.move_to(@app.width, @app.height) do |wh_value, attr| val, sin_or_cos = (attr == :x) ? [10, 'sin'] : [20, 'cos'] (wh_value/2-val) * self.__send__(sin_or_cos, radians(@dot_num * 360/ @@dot_count)) + wh_value/2 end else raise NameError, quot;Unsupported pattern: #{@app.patterns.current.inspect}quot; end @rect.move_by(@rect.x - @next.x, @rect.y - @next.y) do |value, attr| -(value * @speed) end end 2008 11 8 167
  • 168.     end end def radians(x) x * (PI/180) end def display c1 = @app.color(*(0..3).map{rand(255)}) 2008 11 8 168
  • 170. (wh_value/2-val) * self.__send__(sin_or_cos, radians(@dot_num * 360/@@dot_count)) + wh_value/2 x = y =     2008 11 8 170
  • 171. case irb(main):002:0> def case_test(o) irb(main):003:1> case o irb(main):004:2> when String : quot;This is String.quot; irb(main):005:2> when Fixnum : quot;This is Fixnum.quot; irb(main):006:2> when Array : quot;This is Array.quot; irb(main):007:2> end irb(main):008:1> end => nil irb(main):009:0> case_test(1) Attention!! => quot;This is Fixnum.quot; Ruby1.9 irb(main):010:0> case_test([1,2]) => quot;This is Array.quot; irb(main):011:0> case_test(quot;RBCquot;) => quot;This is String.quot; irb(main):012:0> Ruby Business Commons 2008 11 8 171
  • 172. send irb(main):001:0> t = Time.now => Wed Nov 08 00:07:41 +0900 2008 irb(main):002:0> t.year => 2008 send irb(main):003:0> t.month => 11 irb(main):004:0> t.day => 8 irb(main):005:0> t.send(:year) => 2008 irb(main):006:0> t.send(:month) => 11 irb(main):007:0> t.send(:day) => 8 Ruby Business Commons 2008 11 8 172
  • 173. send irb(main):001:0> t = Time.now => Wed Nov 08 00:07:41 +0900 2008 irb(main):002:0> t.strftime('%Y/%m/%d %H:%M:%S') => quot;2008/11/05 00:07:41quot; irb(main):003:0> t.send(:strfrime, '%Y/%m/%d %H:%M:%S') => quot;2008/11/05 00:07:41quot; Ruby Business Commons 2008 11 8 173
  • 174. send irb(main):001:0> class Foo irb(main):002:1> attr_accessor :bar irb(main):003:1> end => nil irb(main):004:0> foo = Foo.new => #<Foo:0x7e1596> irb(main):005:0> foo.bar = quot;AAAquot; => quot;AAAquot; irb(main):006:0> foo.send(:bar=, quot;BBBquot;) => quot;BBBquot; irb(main):007:0> foo.bar => quot;BBBquot; Ruby Business Commons 2008 11 8 174
  • 175.     class MovableDot < Processing::App attr_accessor :patterns frame_rate THE_NUM_OF_DOT = 20 def setup 5 frame_rate @patterns = LoopQueue.new(:line, :circle) @dots = [] 2008 11 8 175
  • 176.       def draw background 0 @dots.each {|dot| dot.display; dot.move} end def mouse_pressed @patterns.next end 2008 11 8 176
  • 178. C:ruby-processing>jruby rbc/movable_dot.rb   Ruby Business Commons 2008 11 8 178
  • 179. 2008 11 8 179
  • 180.       val, sin_or_cos = (attr == :x) ? [10, 'sin'] : [20, 'cos'] (wh_value/2-val) * self.__send__(sin_or_cos, radians(@dot_num * 360/ @@dot_count)) + wh_value/2 end when :center @next.move_to(@app.width/2, @app.height/2) when :random @next.move_by(@app.width/8, @app.height/8) do |value, attr| @app.random(-value, value) end else raise NameError, quot;Unsupported pattern: #{@app.patterns.current.inspect}quot; Ruby Business Commons 2008 11 8 180
  • 181.   def setup frame_rate 5 @patterns = LoopQueue.new(:line, :circle, :center, :random) @dots = []     Ruby Business Commons 2008 11 8 181
  • 183. C:ruby-processing>jruby rbc/movable_dot.rb       Ruby Business Commons 2008 11 8 183
  • 184. 400   Ruby Business Commons 2008 11 8 184
  • 186. 2008 11 8 186
  • 190. Ruby http://qwik.rubybizcommons.jp/members/2.html Ruby Business Commons 2008 11 8 190