Skip to content

Commit 574bac3

Browse files
committed
fix-ups
1 parent 27ce25f commit 574bac3

File tree

14 files changed

+348
-38
lines changed

14 files changed

+348
-38
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
4+
# Use this sketch to find available cameras you should set size to match
5+
# your web camera eg 720P camera is 960, 720. Not tested with the
6+
# RaspberryPI Camera module
7+
class CaptureTest < Processing::App
8+
9+
load_library :video # install latest beta version
10+
java_import 'processing.video.Capture'
11+
12+
attr_reader :cam, :cameras
13+
14+
def setup
15+
sketch_title 'Capture Test'
16+
@cameras = Capture.list
17+
fail 'There are no matching cameras.' if cameras.length.zero?
18+
start_capture(cameras[0])
19+
font = create_font('DejaVu Sans', 28)
20+
text_font font, 28
21+
end
22+
23+
def start_capture(cam_string)
24+
# NB: camera should be initialised as follows
25+
@cam = Capture.new(self, width, height, cam_string)
26+
p format('Using camera %s', cam_string)
27+
cam.start
28+
end
29+
30+
def draw
31+
return unless cam.available # ruby guard clause
32+
33+
cam.read
34+
set(0, 0, cam)
35+
fill 255
36+
rect 0, height - 80, width, 50
37+
fill 0
38+
text cameras[0], 30, height - 50
39+
end
40+
41+
def settings
42+
size 960, 720, P2D
43+
end
44+
end
45+
46+
CaptureTest.new
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
// This implementation is based on GLSL code by ArKano22:
6+
// http://www.gamedev.net/topic/590070-glsl-droste/
7+
#define PROCESSING_TEXTURE_SHADER
8+
uniform sampler2D texture; // iChannel0 in Shadertoy
9+
uniform float globalTime;
10+
uniform vec2 sketchSize; // iResolution in Shadertoy
11+
uniform int mode;
12+
13+
const float TWO_PI = 3.141592*2.0;
14+
//ADJUSTABLE PARAMETERS:
15+
const float Branches = 1.0;
16+
const float scale = 0.4;
17+
const float off = 0.6;
18+
//Complex Math:
19+
vec2 complexExp(in vec2 z){
20+
return vec2(exp(z.x)*cos(z.y),exp(z.x)*sin(z.y));
21+
}
22+
vec2 complexLog(in vec2 z){
23+
return vec2(log(length(z)), atan(z.y, z.x));
24+
}
25+
vec2 complexMult(in vec2 a,in vec2 b){
26+
return vec2(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x);
27+
}
28+
float complexMag(in vec2 z){
29+
return float(pow(length(z), 2.0));
30+
}
31+
vec2 complexReciprocal(in vec2 z){
32+
return vec2(z.x / complexMag(z), -z.y / complexMag(z));
33+
}
34+
vec2 complexDiv(in vec2 a,in vec2 b){
35+
return complexMult(a, complexReciprocal(b));
36+
}
37+
vec2 complexPower(in vec2 a, in vec2 b){
38+
return complexExp( complexMult(b,complexLog(a)) );
39+
}
40+
//Misc Functions:
41+
float nearestPower(in float a, in float base){
42+
return pow(base, ceil( log(abs(a))/log(base) )-1.0 );
43+
}
44+
float map(float value, float istart, float istop, float ostart, float ostop) {
45+
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
46+
}
47+
48+
void main( void ){
49+
50+
//SHIFT AND SCALE COORDINATES
51+
vec2 uv=gl_FragCoord.xy/sketchSize.xy - off;
52+
53+
//ESCHER GRID TRANSFORM:
54+
float factor = pow(1.0/scale,Branches);
55+
uv= complexPower(uv, complexDiv(vec2( log(factor) ,TWO_PI), vec2(0.0,TWO_PI) ) );
56+
57+
//RECTANGULAR DROSTE EFFECT:
58+
float FT = fract(globalTime);
59+
FT = log(FT+1.)/log(2.);
60+
uv *= 1.0+FT*(scale-1.0);
61+
62+
float npower = max(nearestPower(uv.x,scale),nearestPower(uv.y,scale));
63+
uv.x = map(uv.x,-npower,npower,-1.0,1.0);
64+
uv.y = map(uv.y,-npower,npower,-1.0,1.0);
65+
66+
//UNDO SHIFT AND SCALE:
67+
gl_FragColor = texture2D(texture,uv*off+vec2(off));
68+
}
1.8 MB
Binary file not shown.
2.08 MB
Binary file not shown.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Original shader by RavenWorks
2+
// Fake Floyd-Steinberg dithering
3+
// https://www.shadertoy.com/view/4sjGRD
4+
5+
// Adapted for PiCrate by Martin Prout <@monkstoneT>
6+
7+
#ifdef GL_ES
8+
precision mediump float;
9+
precision mediump int;
10+
#endif
11+
12+
#define PROCESSING_TEXTURE_SHADER
13+
14+
uniform sampler2D texture; // iChannel0 in Shadertoy
15+
uniform vec2 sketchSize; // iResolution in Shadertoy
16+
17+
const int lookupSize = 64;
18+
const float errorCarry = 0.3;
19+
20+
float getGrayscale(vec2 coords){
21+
vec2 uv = coords / sketchSize.xy;
22+
// processing is already using inverted y coordinates
23+
// uv.y = 1.0-uv.y;
24+
vec3 sourcePixel = texture2D(texture, uv).rgb;
25+
return length(sourcePixel*vec3(0.2126,0.7152,0.0722));
26+
}
27+
28+
// in regular glsl was
29+
// void mainImage( out vec4 fragColor, in vec2 fragCoord )
30+
31+
void main() {
32+
33+
int topGapY = int(sketchSize.y - gl_FragCoord.y);
34+
35+
int cornerGapX = int((gl_FragCoord.x < 10.0) ? gl_FragCoord.x : sketchSize.x - gl_FragCoord.x);
36+
int cornerGapY = int((gl_FragCoord.y < 10.0) ? sketchSize.y : gl_FragCoord.y - gl_FragCoord.y);
37+
int cornerThreshhold = ((cornerGapX == 0) || (topGapY == 0)) ? 5 : 4;
38+
39+
if (cornerGapX+cornerGapY < cornerThreshhold) {
40+
41+
gl_FragColor = vec4(0,0,0,1);
42+
43+
} else if (topGapY < 20) {
44+
45+
if (topGapY == 19) {
46+
47+
gl_FragColor = vec4(0,0,0,1);
48+
49+
} else {
50+
51+
gl_FragColor = vec4(1,1,1,1);
52+
53+
}
54+
55+
} else {
56+
57+
float xError = 0.0;
58+
for(int xLook=0; xLook<lookupSize; xLook++){
59+
float grayscale = getGrayscale(gl_FragCoord.xy + vec2(-lookupSize+xLook,0));
60+
grayscale += xError;
61+
float bit = grayscale >= 0.5 ? 1.0 : 0.0;
62+
xError = (grayscale - bit)*errorCarry;
63+
}
64+
65+
float yError = 0.0;
66+
for(int yLook=0; yLook<lookupSize; yLook++){
67+
float grayscale = getGrayscale(gl_FragCoord.xy + vec2(0,-lookupSize+yLook));
68+
grayscale += yError;
69+
float bit = grayscale >= 0.5 ? 1.0 : 0.0;
70+
yError = (grayscale - bit)*errorCarry;
71+
}
72+
73+
float finalGrayscale = getGrayscale(gl_FragCoord.xy);
74+
finalGrayscale += xError*0.5 + yError*0.5;
75+
float finalBit = finalGrayscale >= 0.5 ? 1.0 : 0.0;
76+
77+
gl_FragColor = vec4(finalBit,finalBit,finalBit,1);
78+
79+
}
80+
81+
}

library/video/capture/droste.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'picrate'
2+
3+
# hold down mouse to see unfiltered output
4+
class Droste < Processing::App
5+
load_library :video
6+
java_import 'processing.video.Capture'
7+
attr_reader :cam, :my_filter, :origin
8+
9+
def settings
10+
size(960, 720, P2D)
11+
end
12+
13+
def setup
14+
sketch_title 'Droste'
15+
@origin = Time.now
16+
@my_filter = load_shader(data_path('droste.glsl'))
17+
my_filter.set('sketchSize', width.to_f, height.to_f)
18+
start_capture
19+
end
20+
21+
def time
22+
(Time.now - origin) * 0.5
23+
end
24+
25+
def start_capture
26+
@cam = Capture.new(self, 960, 720, 'UVC Camera (046d:0825)')
27+
cam.start
28+
end
29+
30+
def draw
31+
return unless cam.available
32+
33+
background 0
34+
cam.read
35+
set(0, 0, cam)
36+
my_filter.set('globalTime', time)
37+
return if mouse_pressed?
38+
39+
filter(my_filter)
40+
end
41+
end
42+
43+
Droste.new

library/video/capture/steinberg.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'picrate'
2+
# From an original shader by RavenWorks
3+
# hold down mouse to see unfiltered output
4+
class Steinberg < Processing::App
5+
load_library :video
6+
java_import 'processing.video.Capture'
7+
attr_reader :cam, :my_shader
8+
9+
def settings
10+
size(640, 480, P2D)
11+
end
12+
13+
def setup
14+
sketch_title 'Steinberg'
15+
@my_shader = load_shader(data_path('steinberg.glsl'))
16+
my_shader.set('sketchSize', width.to_f, height.to_f)
17+
start_capture(width, height)
18+
end
19+
20+
def start_capture(w, h)
21+
@cam = Capture.new(self, width, height, 'UVC Camera (046d:0825)')
22+
cam.start
23+
end
24+
25+
def draw
26+
return unless cam.available
27+
28+
background 0
29+
cam.read
30+
set(0, 0, cam)
31+
# image(cam, 0, 0, width, height)
32+
return if mouse_pressed?
33+
34+
filter(my_shader)
35+
end
36+
end
37+
38+
Steinberg.new
2.08 MB
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
require 'forwardable'
4+
# placeholder for vector coordinates
5+
Vect = Struct.new(:x, :y)
6+
7+
# A class to contain frame corners, uses forwardable
8+
class Corners
9+
include Enumerable
10+
extend Forwardable
11+
def_delegators :@corners, :each_with_index, :[], :[]=, :<<
12+
attr_reader :idx
13+
14+
def initialize(width, height, ws, wh)
15+
@corners = [
16+
Vect.new(width / 2 - ws, height / 2 - wh),
17+
Vect.new(width / 2 + ws, height / 2 - wh),
18+
Vect.new(width / 2 + ws, height / 2 + wh),
19+
Vect.new(width / 2 - ws, height / 2 + wh)
20+
]
21+
@idx = -1
22+
end
23+
24+
def change_selected(mx, my)
25+
self[idx] = Vect.new(mx, my)
26+
end
27+
28+
def selected?
29+
idx != -1
30+
end
31+
32+
def select_corner(sel)
33+
@idx = sel
34+
end
35+
end

library/video/movie/loop.rb

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env jruby -w
2+
# frozen_string_literal: true
3+
24
require 'picrate'
35
# Loop.
46
#
5-
# Shows how to load and play a QuickTime movie file.
7+
# Shows how to load and play a movie file.
68
class Loop < Processing::App
79
load_libraries :video
810
include_package 'processing.video'
@@ -19,6 +21,7 @@ def setup
1921

2022
def draw
2123
return unless movie.available
24+
2225
movie.read
2326
image(movie, 0, 0, width, height)
2427
end

0 commit comments

Comments
 (0)