Skip to content

Commit b211b41

Browse files
committed
Change GfxRender and ShapeRender examples
1 parent e8b86d1 commit b211b41

File tree

7 files changed

+100
-12
lines changed

7 files changed

+100
-12
lines changed

contributed/cairo_tiling.rb

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env jruby
2+
3+
require 'propane'
4+
5+
class CairoTiling < Propane::App
6+
ANGLE = PI / 2
7+
PTS = [Vec2D.new(-30, 0), Vec2D.new(30, 0), Vec2D.new(45, 45), Vec2D.new(0, 60), Vec2D.new(-45, 45)]
8+
S = 15
9+
W = 12 * S
10+
H = 6 * S
11+
12+
def settings
13+
size(W * 3, H * 6)
14+
end
15+
16+
def setup
17+
sketch_title 'Cairo tiling'
18+
cols = width + W
19+
rows = height + H
20+
grid(cols, rows, W, H) do |x, y|
21+
(y % W).zero? ? composite_tile(x + W / 2, y, S) : composite_tile(x, y, S)
22+
end
23+
end
24+
25+
# An example of GfxRenderer usage for Vec3D => vertex conversion
26+
def renderer
27+
@renderer ||= Propane::GfxRender.new(self.g)
28+
end
29+
30+
def composite_tile(x, y, s)
31+
stroke_weight 2
32+
fill(255, 220, 0)
33+
pentagon(x, y, s)
34+
fill(255, 220, 155)
35+
pentagon(x + 6 * s, y, s, r = 1)
36+
fill(0, 100, 200)
37+
pentagon(x - 6 * s, y, s, r = 3)
38+
fill(140, 180, 255)
39+
pentagon(x, y, s, r = 2)
40+
end
41+
42+
def pentagon(xo, yo, _s, r = 0)
43+
push_matrix
44+
translate(xo, yo)
45+
rotate(ANGLE * r)
46+
begin_shape
47+
PTS.map { |vec| vec.to_vertex(renderer) }
48+
end_shape
49+
pop_matrix
50+
end
51+
end
52+
53+
CairoTiling.new

contributed/ribbon_doodle.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def mouse_moved
8686

8787
# An example of GfxRenderer usage for Vec3D => vertex conversion
8888
def renderer
89-
@renderer ||= Propane::GfxRender.new(self.g)
89+
@renderer ||= Propane::GfxRender.new(g)
9090
end
9191
end
9292

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env jruby -v -W2
2+
# frozen_string_literal: true
3+
require 'propane'
4+
# Demo of Mouse Button
5+
class MouseButtonDemo < Propane::App
6+
# Click within the image and press
7+
# the left and right mouse buttons to
8+
# change the value of the rectangle
9+
10+
def settings
11+
size 300, 200
12+
end
13+
14+
def setup
15+
sketch_title 'Mouse Button Demo'
16+
end
17+
18+
def draw
19+
rect(25, 25, 150, 80)
20+
end
21+
22+
def key_pressed
23+
case key
24+
when 'c', 'C'
25+
fill 0
26+
when 'b', 'B'
27+
fill 255
28+
when 'c', 'C'
29+
fill 125
30+
else
31+
fill 200, 0, 0
32+
end
33+
end
34+
end
35+
36+
MouseButtonDemo.new

processing_app/topics/lsystems/david_tour.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_grammar(gen)
5858
def translate_rules(prod)
5959
swap = false
6060
[].tap do |points| # An array to store lines as a flat array of points
61-
prod.scan(/./) do |ch||
61+
prod.scan(/./) do |ch|
6262
case ch
6363
when 'F'
6464
points << xpos << ypos << (@xpos += draw_length * Math.cos(theta)) << (@ypos -= draw_length * Math.sin(theta))

processing_app/topics/lsystems/mpeano.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def generate(gen)
6464

6565
def translate_rules(prod)
6666
[].tap do |points| # An empty array to store line vertices
67-
prod.scan(/./) do |ch||
67+
prod.scan(/./) do |ch|
6868
case ch
6969
when 'F'
7070
points << xpos << ypos << (@xpos -= draw_length * cos(theta)) << (@ypos -= draw_length * sin(theta))

processing_app/topics/lsystems/peano.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def translate_rules(prod)
7070
coss = ->(orig, alpha, len) { orig + len * DegLut.cos(alpha) }
7171
sinn = ->(orig, alpha, len) { orig - len * DegLut.sin(alpha) }
7272
[].tap do |pts| # An array to store line vertices as Vec2D
73-
prod.scan(/./) do |ch||
73+
prod.scan(/./) do |ch|
7474
case ch
7575
when 'F'
7676
pts << vec.copy

processing_app/topics/shaders/glsl_heightmap_noise.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414

1515
require 'propane'
1616

17-
module Renderer
18-
java_import 'monkstone.vecmath.Propane::ShapeRender'
19-
end
20-
2117
class HeightMap < Propane::App
22-
include Renderer
2318
SHADERS = %w(displaceFrag.glsl displaceVert.glsl).freeze
2419
SHADER_NAME = %i(frag vert).freeze
2520
DIM = 300 # the grid dimensions of the heightmap
@@ -106,13 +101,12 @@ def create_plane(xsegs, ysegs)
106101
tex = images[0]
107102

108103
mesh = create_shape # create the initial PShape
109-
renderer = Propane::ShapeRender.new(mesh) # initialize the shape renderer
110104
mesh.begin_shape(QUADS) # define the PShape type: QUADS
111105
mesh.no_stroke
112106
mesh.texture(tex) # set a texture to make a textured PShape
113107
# put all the vertices, uv texture coordinates and normals into the PShape
114108
positions.each_with_index do |p, i|
115-
p.to_vertex_uv(renderer, tex_coords[i]) # NB: tex_coords as Vec2D
109+
p.to_vertex_uv(renderer(mesh), tex_coords[i]) # NB: tex_coords as Vec2D
116110
# p.to_vertex_uv(renderer, u, v) # u, v as floats is the alternate form
117111
end
118112
mesh.end_shape
@@ -128,6 +122,11 @@ def key_released
128122
puts format('key pressed: %s', key)
129123
end # cycle through colorMaps (set variable and set colorMap in PShader)
130124
end
125+
126+
# An example of GfxRenderer usage for Vec3D => vertex conversion
127+
def renderer(shape)
128+
@renderer ||= Propane::ShapeRender.new(shape)
129+
end
131130
end
132131

133-
HeightMap.new
132+
HeightMap.new

0 commit comments

Comments
 (0)