11月8日イケテルjruby勉強会@東京
Upcoming SlideShare
Loading in...5
×
 

11月8日イケテルjruby勉強会@東京

on

  • 3,394 views

RubyProcessingの説明

RubyProcessingの説明

Statistics

Views

Total Views
3,394
Views on SlideShare
3,345
Embed Views
49

Actions

Likes
2
Downloads
19
Comments
1

3 Embeds 49

http://mochikoastech.blog113.fc2.com 42
http://blog.livedoor.jp 6
http://web.archive.org 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • 参考コードはこちら
    http://code.google.com/p/rbc-incubator/source/browse/takeMe2theStarlet/studySettionData/trunk/rubyProcessing/
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

11月8日イケテルjruby勉強会@東京 11月8日イケテルjruby勉強会@東京 Presentation Transcript

  •           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