Sha256: a280d36d4fb3c99f97d270a572acd5576f4beb22e725e52bfba3ba7c3b3e4ba5

Contents?: true

Size: 1021 Bytes

Versions: 9

Compression:

Stored size: 1021 Bytes

Contents

# Texture 3. 
# 
# Load an image and draw it onto a cylinder and a quad. 

attr_reader :tube_res, :tube_x, :tube_y, :img

def setup
  
  size 640, 360, P3D
  
  @tube_res = 32
  @tube_x = []
  @tube_y = []
  
  @img = load_image "berlin-1.jpg"
  
  angle = 270.0 / tube_res
  
  (0...tube_res).each { |i|
    tube_x.push cos( radians( i * angle ) )
    tube_y.push sin( radians( i * angle ) )
  }
  
  no_stroke
  
end

def draw
  
  background 0
  
  translate width/2, height/2
  rotate_x map( mouse_y, 0, height, -PI, PI )
  rotate_y map( mouse_x, 0, width, -PI, PI )
  
  begin_shape QUAD_STRIP
    
  texture img
  
  (0...tube_res).each { |i|
    
    x = tube_x[i] * 100
    z = tube_y[i] * 100
    u = img.width / tube_res * i
    
    vertex x, -100, z, u, 0
    vertex x,  100, z, u, img.height
    
  }
  
  end_shape
  	
  begin_shape QUADS
  
  texture img
  
  vertex   0, -100, 0,   0, 0
  vertex 100, -100, 0, 100, 0
  vertex 100,  100, 0, 100, 100
  vertex   0,  100, 0,   0, 100
  
  end_shape
  
end  

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby-processing-2.6.2 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.6.1 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.6.0 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.5.1 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.5.0 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.4.4 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.4.3 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.4.2 samples/processing_app/basics/textures/texture3.rb
ruby-processing-2.4.1 samples/processing_app/basics/textures/texture3.rb