Skip to content

Commit

Permalink
Update bw_shader.rb
Browse files Browse the repository at this point in the history
Use tap to avoid temporary variable shape
  • Loading branch information
monkstone authored Mar 13, 2020
1 parent 01fe889 commit ee99cf2
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions shaders/bw_shader.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'picrate'

class BwShader < Processing::App
Expand All @@ -21,29 +23,29 @@ def setup
def draw
background(0)
shader(bw_shader)
translate(width/2, height/2)
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)
create_shape.tap do |sh|
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
end
sh.end_shape
sh
end
end

Expand Down

0 comments on commit ee99cf2

Please sign in to comment.