Sha256: 1335a592f2bfab4f88aa6a82338e1692836392f762c22270daf7e46484bed85a

Contents?: true

Size: 964 Bytes

Versions: 6

Compression:

Stored size: 964 Bytes

Contents

# Explode 
# by Daniel Shiffman. 
# 
# Mouse horizontal location controls breaking apart of image and 
# Maps pixels from a 2D image into 3D space. Pixel brightness controls 
# translation along z axis. 
CELL_SIZE = 2

def setup    
  size 640, 360, P3D    
  @img = load_image 'eames.jpg'
  @columns = @img.width / CELL_SIZE
  @rows = @img.height / CELL_SIZE    
end

def draw    
  background 0    
  (0...@columns).each { |i|        
    (0...@rows).each { |j|            
      x = i * CELL_SIZE + CELL_SIZE / 2
      y = j * CELL_SIZE + CELL_SIZE / 2            
      loc = x + y * @img.width            
      c = @img.pixels[loc]            
      z = (mouse_x / width.to_f) * brightness( @img.pixels[loc] ) - 20            
      push_matrix            
      translate x + 200, y + 100, z            
      fill c, 204
      no_stroke
      rect_mode CENTER            
      rect 0, 0, CELL_SIZE, CELL_SIZE            
      pop_matrix
    }
  }
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/topics/image_processing/explode.rb
ruby-processing-2.6.2 samples/processing_app/topics/image_processing/explode.rb
ruby-processing-2.6.1 samples/processing_app/topics/image_processing/explode.rb
ruby-processing-2.6.0 samples/processing_app/topics/image_processing/explode.rb
ruby-processing-2.5.1 samples/processing_app/topics/image_processing/explode.rb
ruby-processing-2.5.0 samples/processing_app/topics/image_processing/explode.rb