Sha256: 9ce69424826bb7d21743246435f6b03842ea526aec766f70e845952845c521a7

Contents?: true

Size: 923 Bytes

Versions: 5

Compression:

Stored size: 923 Bytes

Contents

# Texture from Jason Liebig's FLICKR collection of vintage labels and wrappers:
# http://www.flickr.com/photos/jasonliebigstuff/3739263136/in/photostream/

attr_reader :label, :can, :angle, :bw_shader

def setup
  size(640, 360, P3D)  
  @label = load_image('lachoy.jpg')
  @can = create_can(100, 200, 32, label)
  @bw_shader = load_shader('bwfrag.glsl')
  @angle = 0
end

def draw    
  background(0)  
  shader(bw_shader)    
  translate(width/2, height/2)
  rotate_y(angle)  
  shape(can)  
  @angle += 0.01
end

def create_can(r, h, detail, tex)
  texture_mode(NORMAL)
  sh = create_shape
  sh.begin_shape(QUAD_STRIP)
  sh.no_stroke
  sh.texture(tex)
  (0 .. detail).each do |i|
    angle = TAU / detail
    x = sin(i * angle)
    z = cos(i * angle)
    u = i.to_f / detail
    sh.normal(x, 0, z)
    sh.vertex(x * r, -h/2, z * r, u, 0)
    sh.vertex(x * r, +h/2, z * r, u, 1)    
  end
  sh.end_shape 
  return sh
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-processing-2.6.2 samples/processing_app/topics/shaders/bw_shader.rb
ruby-processing-2.6.1 samples/processing_app/topics/shaders/bw_shader.rb
ruby-processing-2.6.0 samples/processing_app/topics/shaders/bw_shader.rb
ruby-processing-2.5.1 samples/processing_app/topics/shaders/bw_shader.rb
ruby-processing-2.5.0 samples/processing_app/topics/shaders/bw_shader.rb