Skip to content

Commit 8922ed5

Browse files
committed
use data_path wrapper, mainly shaders
1 parent 1a3b1d0 commit 8922ed5

28 files changed

+161
-144
lines changed

processing_app/topics/shaders/blur_filter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
def setup
1212
sketch_title 'Blur filter'
13-
@blur = load_shader('blur.glsl')
13+
@blur = load_shader(data_path('blur.glsl'))
14+
# @blur = load_shader('blur.glsl')
1415
stroke(255, 0, 0)
1516
rectMode(CENTER)
1617
end

processing_app/topics/shaders/bw_shader.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
def setup
77
sketch_title 'Bw shader'
8-
@label = load_image('lachoy.jpg') # sketch needs --noruby flag to run
8+
# @label = load_image('lachoy.jpg') # sketch needs --noruby flag to run
99
# @label = load_image((File.absolute_path('data/lachoy.jpg')) # no flag required
10-
# @label = load_image((data_path('lachoy.jpg')) # no flag required
10+
@label = load_image((data_path('lachoy.jpg')) # no flag required
1111
@can = create_can(100, 200, 32, label)
12-
@bw_shader = load_shader('bwfrag.glsl') # sketch needs --noruby flag to run
12+
# @bw_shader = load_shader('bwfrag.glsl') # sketch needs --noruby flag to run
1313
# @bw_shader = load_shader(File.absolute_path('data/bwfrag.glsl')) # no flag required
14-
# @bw_shader = load_shader(data_path('bwfrag.glsl')) # no flag required since jruby_art-1.1
14+
@bw_shader = load_shader(data_path('bwfrag.glsl')) # no flag required since jruby_art-1.1
1515
@angle = 0
1616
end
1717

processing_app/topics/shaders/conway.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def setup
88
sketch_title 'Conway'
99
@pg = createGraphics(400, 400, P2D)
1010
pg.no_smooth
11-
@conway = load_shader('conway.glsl') # sketch needs --noruby flag to run
11+
# @conway = load_shader('conway.glsl') # sketch needs --noruby flag to run
1212
# @conway = load_shader(File.absolute_path('data/conway.glsl')) # no flag required
13-
# @conway = load_shader(data_path('conway.glsl')) # no flag required
13+
@conway = load_shader(data_path('conway.glsl')) # no flag required
1414
conway.set('resolution', width.to_f, height.to_f)
1515
@time = Time.now
1616
end

processing_app/topics/shaders/deform.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def setup
1414
sketch_title 'Deform'
1515

1616
textureWrap(REPEAT)
17-
@tex = loadImage('tex1.jpg')
18-
19-
@deform = loadShader('deform.glsl')
17+
@tex = load_image(data_path('tex1.jpg'))
18+
@deform = load_shader(data_path('deform.glsl'))
19+
# @tex = loadImage('tex1.jpg')
20+
# @deform = loadShader('deform.glsl')
2021
deform.set('resolution', width.to_f, height.to_f)
2122
end
2223

processing_app/topics/shaders/edge_detect.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@
1111
def setup
1212
sketch_title 'Edge detect'
1313
@enabled = true
14-
@img = load_image('leaves.jpg');
15-
@edges = load_shader('edges.glsl')
14+
@img = load_image(data_path('leaves.jpg'))
15+
@edges = load_shader(data_path('edges.glsl'))
16+
# @img = load_image('leaves.jpg') # use --noruby flag
17+
# @edges = load_shader('edges.glsl') # use --nojruby flag
1618
end
1719

1820
def draw
1921
shader(edges) if enabled
2022
image(img, 0, 0)
2123
end
2224

23-
def mousePressed
25+
def mouse_pressed
2426
@enabled = !enabled
2527
if (!enabled == true)
26-
resetShader
28+
reset_shader
2729
end
2830
end
2931

processing_app/topics/shaders/glossy_fish_eye.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#
21
# Glossy Fish Eye
3-
#
4-
# A fish-eye shader is used on the main surface and
5-
# a glossy specular reflection shader is used on the
6-
# offscreen canvas.
72
#
3+
# A fish-eye shader is used on the main surface and
4+
# a glossy specular reflection shader is used on the
5+
# offscreen canvas.
86

97
attr_reader :ball, :canvas, :glossy, :fisheye, :img, :use_fish_eye
8+
SHADERS = %w(FishEye.glsl GlossyFrag.glsl GlossyVert.glsl).freeze
109

1110
def setup
1211
sketch_title 'Glossy fish eye'
1312
@canvas = create_graphics(width, height, P3D)
1413
@use_fish_eye = true
15-
@fisheye = load_shader('FishEye.glsl')
14+
shaders = SHADERS.map { |shader| data_path(shader) }
15+
@fisheye = load_shader(shaders[0])
1616
fisheye.set('aperture', 180.0)
17-
@glossy = load_shader('GlossyFrag.glsl', 'GlossyVert.glsl')
17+
@glossy = load_shader(shaders[1], shaders[2])
1818
glossy.set('AmbientColour', 0.0, 0.0, 0.0)
1919
glossy.set('DiffuseColour', 0.9, 0.2, 0.2)
2020
glossy.set('SpecularColour', 1.0, 1.0, 1.0)
@@ -34,26 +34,26 @@ def draw
3434
canvas.background(0)
3535
canvas.push_matrix
3636
canvas.rotate_y(frame_count * 0.01)
37-
canvas.point_light(204, 204, 204, 1000, 1000, 1000)
38-
canvas.pop_matrix
39-
(0 ... canvas.width + 100).step(100) do |x|
40-
(0 ... canvas.width + 100).step(100) do |y|
41-
(0 ... canvas.width + 100).step(100) do |z|
37+
canvas.point_light(204, 204, 204, 1_000, 1_000, 1_000)
38+
canvas.pop_matrix
39+
(0...canvas.width + 100).step(100) do |x|
40+
(0...canvas.width + 100).step(100) do |y|
41+
(0...canvas.width + 100).step(100) do |z|
4242
canvas.push_matrix
4343
canvas.translate(x, y, -z)
4444
canvas.shape(ball)
4545
canvas.pop_matrix
4646
end
4747
end
4848
end
49-
canvas.end_draw
50-
shader(fisheye) if use_fish_eye
49+
canvas.end_draw
50+
shader(fisheye) if use_fish_eye
5151
image(canvas, 0, 0, width, height)
5252
end
5353

5454
def mouse_pressed
5555
@use_fish_eye = !use_fish_eye
56-
reset_shader
56+
reset_shader
5757
end
5858

5959
def settings

processing_app/topics/shaders/glsl_heightmap_noise.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# Photographs by Folkert Gorter (@folkertgorter / http://superfamous.com/)
1212
# made available under a CC Attribution 3.0 license.
1313
#
14-
1514
DIM = 300 # the grid dimensions of the heightmap
1615
attr_reader :blur_factor # the blur for the displacement map
1716
attr_reader :resize_factor # the resize factor for the displacement map
@@ -24,18 +23,19 @@
2423
attr_reader :images # array to hold 2 input images
2524
attr_reader :color_map # variable to keep track of the current colorMap
2625

27-
2826
def setup
29-
sketch_title 'Glsl heightmap noise'
27+
sketch_title 'Glsl Heightmap Noise'
3028
@blur_factor = 3
3129
@resize_factor = 0.25
32-
displace_strength = 0.25 # the displace strength of the GLSL shader displacement effect
30+
displace_strength = 0.25 # the displace strength of the GLSL shader
3331
# load the images
3432
textures = %w(Texture01.jpg Texture02.jpg)
35-
@images = textures.map { |texture| load_image(texture) }
33+
@images = textures.map { |texture| load_image(data_path(texture)) }
3634
@color_map = 0
3735
# load the PShader with a fragment and a vertex shader
38-
@displace = load_shader('displaceFrag.glsl', 'displaceVert.glsl')
36+
shader_name = %w(displaceFrag.glsl displaceVert.glsl)
37+
shaders = shader_name.map { |s| data_path(s) }
38+
@displace = load_shader(shaders[0], shaders[1])
3939
displace.set('displaceStrength', displace_strength) # set the displace_strength
4040
displace.set('colorMap', images[color_map]) # set the initial colorMap
4141
# create the heightmap PShape (see custom creation method) and put it in the

processing_app/topics/shaders/image_filtering/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222

2323
def run_sample(sample_name)
2424
puts "Running #{sample_name}...quit to run next sample"
25-
open("|k9 --nojruby run #{sample_name}", "r") do |io|
25+
open("|k9 run #{sample_name}", "r") do |io|
2626
while l = io.gets
2727
puts(l.chop)
2828
end

processing_app/topics/shaders/image_filtering/bicubic.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ def setup
1414
@panel = c
1515
end
1616
@hide = false
17-
@my_image = load_image('texture.jpg')
18-
@bicubic = load_shader('bicubic.glsl')
17+
@my_image = load_image(data_path('texture.jpg'))
18+
@bicubic = load_shader(data_path('bicubic.glsl'))
19+
# @my_image = load_image('texture.jpg')
20+
# @bicubic = load_shader('bicubic.glsl')
1921
bicubic.set('sketchSize', width.to_f, height.to_f)
2022
sketch_title 'Bicubic'
2123
end

processing_app/topics/shaders/image_filtering/bilateral.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
attr_reader :apply, :bilateral, :my_image
88

99
def setup
10-
@my_image = load_image('texture.jpg')
11-
@bilateral = load_shader('bilateral.glsl')
10+
@my_image = load_image(data_path('texture.jpg'))
11+
@bilateral = load_shader(data_path('bilateral.glsl'))
12+
# @my_image = load_image('texture.jpg')
13+
# @bilateral = load_shader('bilateral.glsl')
1214
bilateral.set('sketchSize', width.to_f, height.to_f)
1315
sketch_title 'Bilateral'
1416
end

0 commit comments

Comments
 (0)