Skip to content

Commit 5fd235d

Browse files
committed
Use tap for PShape
1 parent 27c3162 commit 5fd235d

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

processing_app/library/vecmath/arcball/arcball_shape.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
def setup
55
sketch_title 'Arcball Shape'
66
ArcBall.init(self)
7-
@my_cube = create_shape BOX, 400, 400, 400
8-
my_cube.set_fill(color(100, 10, 100))
7+
@my_cube = create_shape(BOX, 400, 400, 400).tap do |shp|
8+
shp.set_fill(color(100, 10, 100))
9+
end
910
end
1011

1112
def draw

processing_app/topics/shaders/glsl_heightmap_noise.rb

+19-14
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ def create_plane(xsegs, ysegs)
7676
grid(xsegs, ysegs) do |x, y| # using JRubyArt grid method
7777
u = x / xsegs.to_f
7878
v = y / ysegs.to_f
79-
79+
8080
# generate positions for the vertices of each cell
8181
# (-0.5 to center the shape around the origin)
8282
positions << Vec3D.new(u - 0.5, v - 0.5, 0)
8383
positions << Vec3D.new(u + usegsize - 0.5, v - 0.5, 0)
8484
positions << Vec3D.new(u + usegsize - 0.5, v + vsegsize - 0.5, 0)
8585
positions << Vec3D.new(u - 0.5, v + vsegsize - 0.5, 0)
86-
86+
8787
# generate texture coordinates for the vertices of each cell
8888
tex_coords << Vec2D.new(u, v)
8989
tex_coords << Vec2D.new(u + usegsize, v)
@@ -95,19 +95,24 @@ def create_plane(xsegs, ysegs)
9595

9696
texture_mode(NORMAL) # set texture_mode to normalized (range 0 to 1)
9797
tex = images[0]
98-
99-
mesh = create_shape # create the initial PShape
100-
renderer = ShapeRender.new(mesh) # initialize the shape renderer
101-
mesh.begin_shape(QUADS) # define the PShape type: QUADS
102-
mesh.no_stroke
103-
mesh.texture(tex) # set a texture to make a textured PShape
104-
# put all the vertices, uv texture coordinates and normals into the PShape
105-
positions.each_with_index do |p, i|
106-
p.to_vertex_uv(renderer, tex_coords[i]) # NB: tex_coords as Vec2D
107-
# p.to_vertex_uv(renderer, u, v) # u, v as floats is the alternate form
98+
# create the initial PShape
99+
create_shape.tap do |mesh|
100+
# initialize the shape renderer
101+
renderer = ShapeRender.new(mesh)
102+
# define the PShape type: QUADS
103+
mesh.begin_shape(QUADS)
104+
# set a texture to make a textured PShape
105+
mesh.no_stroke
106+
mesh.texture(tex)
107+
# put all the vertices, uv texture coordinates and normals into the PShape
108+
positions.each_with_index do |p, i|
109+
# NB: tex_coords as Vec2D
110+
p.to_vertex_uv(renderer, tex_coords[i])
111+
# p.to_vertex_uv(renderer, u, v) # u, v as floats is the alternate form
112+
end
113+
mesh.end_shape
108114
end
109-
mesh.end_shape
110-
mesh # our work is done here, return DA MESH! -)
115+
# our work is done here, return DA MESH! -)
111116
end
112117

113118
def key_pressed

0 commit comments

Comments
 (0)