Skip to content

Commit ee99cf2

Browse files
authored
Update bw_shader.rb
Use tap to avoid temporary variable shape
1 parent 01fe889 commit ee99cf2

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

shaders/bw_shader.rb

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'picrate'
24

35
class BwShader < Processing::App
@@ -21,29 +23,29 @@ def setup
2123
def draw
2224
background(0)
2325
shader(bw_shader)
24-
translate(width/2, height/2)
26+
translate(width / 2, height / 2)
2527
rotate_y(angle)
2628
shape(can)
2729
@angle += 0.01
2830
end
2931

3032
def create_can(r, h, detail, tex)
3133
texture_mode(NORMAL)
32-
sh = create_shape
33-
sh.begin_shape(QUAD_STRIP)
34-
sh.no_stroke
35-
sh.texture(tex)
36-
(0..detail).each do |i|
37-
angle = TAU / detail
38-
x = sin(i * angle)
39-
z = cos(i * angle)
40-
u = i.to_f / detail
41-
sh.normal(x, 0, z)
42-
sh.vertex(x * r, -h/2, z * r, u, 0)
43-
sh.vertex(x * r, +h/2, z * r, u, 1)
34+
create_shape.tap do |sh|
35+
sh.begin_shape(QUAD_STRIP)
36+
sh.no_stroke
37+
sh.texture(tex)
38+
(0..detail).each do |i|
39+
angle = TAU / detail
40+
x = sin(i * angle)
41+
z = cos(i * angle)
42+
u = i.to_f / detail
43+
sh.normal(x, 0, z)
44+
sh.vertex(x * r, -h / 2, z * r, u, 0)
45+
sh.vertex(x * r, +h / 2, z * r, u, 1)
46+
end
47+
sh.end_shape
4448
end
45-
sh.end_shape
46-
sh
4749
end
4850
end
4951

0 commit comments

Comments
 (0)