Skip to content

Commit 42faafc

Browse files
author
monkstone
committed
use captureEvent, update pixelate
1 parent 13c73fe commit 42faafc

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

image_filtering/data/pixelate.glsl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// Original shader by simesgreen
55
// https://www.shadertoy.com/view/4sl3zr
66

7+
// New original shader by radiodario
8+
// https://www.shadertoy.com/view/ltjGDh
9+
710
// Ported to Processing by Raphaël de Courville <twitter: @sableRaph>
811

912
#ifdef GL_ES
@@ -14,13 +17,13 @@ precision mediump int;
1417
uniform sampler2D texture;
1518

1619
uniform vec2 sketchSize;
20+
uniform vec2 offset;
1721

18-
uniform float division;
22+
uniform float pixelSize;
1923

2024
void main(void)
2125
{
22-
vec2 uv = gl_FragCoord.xy / sketchSize.xy;
23-
vec2 divs = vec2(sketchSize.x * division / sketchSize.y, division);
24-
uv = floor(uv * divs)/ divs;
26+
// we might not need the last term
27+
vec2 uv = ((floor((gl_FragCoord.xy - offset) / pixelSize ) * 0.5) * pixelSize + offset) / sketchSize + vec2(0.5) / sketchSize;
2528
gl_FragColor = texture2D(texture, uv);
2629
}

image_filtering/pixelate.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ def draw
1818
background(0)
1919
# Draw the image on the scene
2020
image(my_image, 0, 0)
21-
oscillation = map1d(sin(frame_count * 0.005), (-1.0..1.0), (10..30)).floor
22-
my_filter.set('division', oscillation.to_f)
21+
oscillation = make_even(map1d(sin(frame_count * 0.01), (-1.0..1.0), (2..128)))
22+
offset_x = make_even(width % oscillation * 0.5).to_f
23+
offset_y = make_even(height % oscillation * 0.5).to_f
24+
my_filter.set('pixelSize', oscillation.to_f)
25+
my_filter.set('offset', offset_x, offset_y)
2326
# Applies the shader to everything that has already been drawn
2427
return if mouse_pressed?
2528
filter(my_filter)
2629
end
30+
31+
def make_even(source)
32+
(source / 2.0).floor * 2
33+
end

video_filtering/barrel_blur_chroma.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Hold mouse click to disable the filter temporarily
22
# The videoclip is from NASA: http://youtu.be/CBwdZ1yloHA
33

4-
load_library :video
4+
load_library :video, :video_event
55
include_package 'processing.video'
66

77
attr_reader :movie, :my_shader
@@ -23,9 +23,10 @@ def setup
2323

2424
def draw
2525
image(movie, 0, 0, width, height)
26-
begin # workaround to avoid reflection nonsense
27-
movie.read
28-
end if movie.available?
2926
return if mouse_pressed?
3027
filter(my_shader)
3128
end
29+
30+
def movieEvent(m)
31+
m.read
32+
end

video_filtering/black_white_capture.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def start_capture(w, h)
1414
end
1515

1616
def draw
17-
return unless (cam.available == true)
18-
cam.read
1917
image(cam, 0, 0)
2018
return if mouse_pressed?
2119
filter(my_shader)
2220
end
21+
22+
def captureEvent(c)
23+
c.read
24+
end

video_filtering/edge_detect_capture.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load_library :video
1+
load_library :video, :video_event
22
include_package 'processing.video'
33
attr_reader :cam, :my_shader
44

@@ -15,9 +15,11 @@ def start_capture(w, h)
1515
end
1616

1717
def draw
18-
return unless (cam.available == true)
19-
cam.read
2018
image(cam, 0, 0)
2119
return if mouse_pressed?
2220
filter(my_shader)
2321
end
22+
23+
def captureEvent(c)
24+
c.read
25+
end

video_filtering/ntsc.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# The videoclip is from NASA: http://youtu.be/CBwdZ1yloHA
55

6-
load_library :video
6+
load_library :video, :video_event
77
include_package 'processing.video'
88

99
attr_reader :movie, :my_shader
@@ -20,9 +20,10 @@ def setup
2020

2121
def draw
2222
image(movie, 0, 0, width, height)
23-
begin # workaround to avoid reflection nonsense
24-
movie.read
25-
end if movie.available?
2623
return if mouse_pressed?
2724
filter(my_shader)
2825
end
26+
27+
def movieEvent(m)
28+
m.read
29+
end

0 commit comments

Comments
 (0)