Sha256: 3790dd5849a0e8f8693a68bd6a5d0aa8d1d6b8dad8c614ade8b016d5ea068ecb

Contents?: true

Size: 826 Bytes

Versions: 9

Compression:

Stored size: 826 Bytes

Contents

require 'ruby-processing'

# Embedding "for" structures allows repetition in two dimensions. 

class EmbeddedIteration < Processing::App

  def setup
    
    background 0
    no_stroke
    
    box_size = 11.0
    box_space = 12.0
    margin = 7
    
    # Draw gray boxes 
    
    (margin...height-margin).step(box_space) do |i|
    # or, if you feel more java-loopy:
    # i = margin; while i < height-margin
    	
    	if box_size > 0
 
    		(margin...width-margin).step(box_space) do |j|
    		
    			fill( 255 - box_size * 10 )
    			rect j, i, box_size, box_size
    		end
    		
    	end
    	
    	box_size -= 0.6
    	
    	# for java loops, don't forget to increment with while:
    	# i += box_space
    end
    
  end
  
end

EmbeddedIteration.new :title => "Embedded Iteration", :width => 200, :height => 200

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby-processing-1.0.11 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.10.1 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.9 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.4 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.3 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.5 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.6 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.7 samples/processing_app/basics/control/embedded_iteration.rb
ruby-processing-1.0.8 samples/processing_app/basics/control/embedded_iteration.rb