Skip to content

Commit bd97a5c

Browse files
committed
favor latest video library beta over gl graphics
1 parent cac6b37 commit bd97a5c

File tree

4 files changed

+162
-44
lines changed

4 files changed

+162
-44
lines changed

library/video/mirror.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
4+
# Test Class for Video Library
5+
class Mirror < Processing::App
6+
7+
load_library :video
8+
attr_reader :video, :cols, :rows
9+
# Size of each cell in the grid
10+
CELL_SIZE = 20
11+
12+
def setup
13+
sketch_title 'mirror'
14+
frame_rate(30)
15+
@cols = width / CELL_SIZE
16+
@rows = height / CELL_SIZE
17+
colorMode(RGB, 255, 255, 255, 100)
18+
# This the default video input, try test_capture to find name of your Camera
19+
@video = Java::ProcessingVideo::Capture.new(self, "UVC Camera (046d:0825)")
20+
# Start capturing the images from the camera
21+
video.start
22+
background(0)
23+
end
24+
25+
def draw
26+
return unless video.available # ruby guard clause
27+
28+
video.read
29+
video.loadPixels
30+
grid(width, height, cols, rows) do |x, y|
31+
loc = (video.width - x - 1) + y * video.width # Reversing x to mirror the image
32+
col = color(
33+
red(video.pixels[loc]),
34+
green(video.pixels[loc]),
35+
blue(video.pixels[loc]),
36+
75 # alpha
37+
)
38+
# Code for drawing a single rect
39+
# Using translate in order for rotation to work properly
40+
push_matrix
41+
translate(x + CELL_SIZE / 2, y + CELL_SIZE / 2)
42+
# Rotation formula based on brightness
43+
rotate((2 * PI * brightness(col) / 255.0))
44+
rect_mode(CENTER)
45+
fill(col)
46+
no_stroke
47+
# Rects are larger than the cell for some overlap
48+
rect(0, 0, CELL_SIZE + 6, CELL_SIZE + 6)
49+
pop_matrix
50+
end
51+
end
52+
53+
def settings
54+
size(480, 360)
55+
end
56+
end
57+
58+
Mirror.new

library/video/test_capture.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
4+
# Test Class for Video Library
5+
class TestCapture < Processing::App
6+
7+
load_library :video, :video_event
8+
9+
include_package 'processing.video'
10+
11+
attr_reader :cam
12+
13+
def setup
14+
sketch_title 'Test Capture'
15+
cameras = Capture.list
16+
fail 'There are no matching cameras.' if cameras.length.zero?
17+
start_capture(cameras[0])
18+
end
19+
20+
def start_capture(cam_string)
21+
# The camera can be initialized directly using an
22+
# element from the array returned by list:
23+
@cam = Capture.new(self, cam_string)
24+
p format('Using camera %s', cam_string)
25+
cam.start
26+
end
27+
28+
def draw
29+
return unless cam.available
30+
cam.read
31+
image(cam, 0, 0, width, height)
32+
# The following does the same, and is faster when just drawing the image
33+
# without any additional resizing, transformations, or tint.
34+
# set(0, 0, cam)
35+
end
36+
37+
def settings
38+
size 960, 720, P2D
39+
end
40+
end
41+
42+
TestCapture.new

picrate.geany

Lines changed: 0 additions & 44 deletions
This file was deleted.

picrate_samples.geany

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[editor]
2+
line_wrapping=false
3+
line_break_column=72
4+
auto_continue_multiline=true
5+
6+
[file_prefs]
7+
final_new_line=true
8+
ensure_convert_new_lines=false
9+
strip_trailing_spaces=true
10+
replace_tabs=true
11+
12+
[indentation]
13+
indent_width=2
14+
indent_type=0
15+
indent_hard_tab_width=8
16+
detect_indent=false
17+
detect_indent_width=false
18+
indent_mode=2
19+
20+
[project]
21+
name=picrate_samples
22+
base_path=/home/pi/picrate_samples
23+
description=Exploring PiCrate
24+
file_patterns=*.rb;*.glsl;*.txt;
25+
26+
[long line marker]
27+
long_line_behaviour=1
28+
long_line_column=72
29+
30+
[files]
31+
current_page=3
32+
FILE_NAME_0=667;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fbasics%2Farrays%2Farray.rb;0;2
33+
FILE_NAME_1=1664;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fadvanced_data%2Fload_save_json.rb;0;2
34+
FILE_NAME_2=259;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fjruby_install.sh;0;2
35+
FILE_NAME_3=236;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Ftest.sh;0;2
36+
37+
[VTE]
38+
last_dir=/home/pi
39+
40+
[build-menu]
41+
EX_00_LB=_Execute
42+
EX_00_CM=jruby --dev "%f"
43+
EX_00_WD=
44+
RubyFT_00_LB=_Rubocop
45+
RubyFT_00_CM=rubocop --fail-level F "%f"
46+
RubyFT_00_WD=
47+
filetypes=Ruby;
48+
RubyFT_01_LB=_Rubocop autocorrect
49+
RubyFT_01_CM=rubocop -a --fail-level F "%f"
50+
RubyFT_01_WD=
51+
NF_00_LB=
52+
NF_00_CM=
53+
NF_00_WD=
54+
NF_01_LB=
55+
NF_01_CM=
56+
NF_01_WD=
57+
NF_02_LB=
58+
NF_02_CM=
59+
NF_02_WD=
60+
RubyFT_02_LB=_Reek
61+
RubyFT_02_CM=reek --failure-exit-code=0 "%f"
62+
RubyFT_02_WD=

0 commit comments

Comments
 (0)