ruby-processingでProcessing->Examples->Basic->Controlの写経
写経してみたw;
case :LogicalOperators when :LogicalOperators def setup size 200,200 background 126 op = false 5.step(195,5){|i| stroke 0 if 35<i and i<100 line 5,i,95,i op = false end stroke 76 if i<=35 or 100<=i line 105,i,195,i op = true end if op stroke 0 point width/2,i end unless op stroke 255 point width/4,i end } end def draw end when :none def setup size 200,200 background 102 end def draw end when :Iteratin def setup xpos1 = 100 xpos2 = 118 count = 0 timey = 0 num = 12 size 200,200 background 102 no_stroke fill 255 k=60 0.step(num/3-1){|i| rect 25,k,255,5 k+=10 } fill 51 k = 40 0.step(num-1){|i| rect 105,k,30,5 k+=10 } k = 15 0.step(num-1){|i| rect 125,k,30,5 k+=10 } k = 42 fill 0 0.step(num-2){|i| rect 36,k,20,1 k+=10 } end def draw end when :EmbeddedIteration def setup box_size = 11 box_space = 12 margine = 7 size 200,200 background 0 no_stroke margine.step(height-margine,box_space){|i| if box_size > 0 margine.step(width-margine,box_space){|j| fill 255-box_size*10 rect j,i,box_size,box_size } box_size -= 0.6 end } end def draw end when :Conditionals2 def setup size 200,200 background 0 2.step(width-1,2){|i| case when (i%20).zero? stroke 255 line i,40,i,height/2 when (i%10).zero? stroke 153 line i,20,i,180 else stroke 102 line i,height/2,i,height-40 end } end def draw end when :Conditionals1 def setup size 200,200 background 0 10.step(width-1, 10){|i| #range pixels is (0...200) if (i%20).zero? stroke 153 line i,40,i,height/2 else stroke 102 line i,20,i,180 end } end def draw end end
JavaのforをRubyで記述する場合は、stepが便利ですね^^
Rubyの反復処理は、eachやmapに浸っていたから、stepが一寸新鮮ですw;