ruby-processing 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/lib/patches/JRubyApplet.diff +0 -0
- data/lib/patches/PATCHES.txt +0 -0
- data/lib/patches/PApplet.diff +0 -0
- data/lib/ruby-processing.rb +1 -1
- data/lib/ruby-processing/app.rb +20 -1
- data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
- data/lib/ruby-processing/exporters/creator.rb +1 -2
- data/lib/ruby-processing/runner.rb +4 -3
- data/lib/ruby-processing/runners/watch.rb +2 -2
- data/lib/templates/applet/index.html.erb +1 -1
- metadata +2 -145
- data/samples/learning_processing/ABOUT +0 -11
- data/samples/learning_processing/chapter_01/1_stroke_and_fill.rb +0 -18
- data/samples/learning_processing/chapter_01/2_nofill.rb +0 -20
- data/samples/learning_processing/chapter_01/3_rgb_color.rb +0 -19
- data/samples/learning_processing/chapter_01/4_alpha_transparency.rb +0 -42
- data/samples/learning_processing/chapter_01/5_zoog.rb +0 -24
- data/samples/learning_processing/chapter_02/1_zoog_again.rb +0 -41
- data/samples/learning_processing/chapter_03/1_zoog_as_dynamic_sketch.rb +0 -44
- data/samples/learning_processing/chapter_03/2_mouse_x_and_mouse_y.rb +0 -26
- data/samples/learning_processing/chapter_03/3_zoog_as_dynamic_sketch_with_variation.rb +0 -41
- data/samples/learning_processing/chapter_03/4_drawing_a_continuous_line.rb +0 -18
- data/samples/learning_processing/chapter_03/5_mouse_pressed_and_key_pressed.rb +0 -29
- data/samples/learning_processing/chapter_03/6_interactive_zoog.rb +0 -42
- data/samples/learning_processing/chapter_04/1_variable_declaration.rb +0 -24
- data/samples/learning_processing/chapter_04/2_using_variables.rb +0 -27
- data/samples/learning_processing/chapter_04/3_varying_variables.rb +0 -27
- data/samples/learning_processing/chapter_04/4_many_variables.rb +0 -38
- data/samples/learning_processing/chapter_04/5_using_system_variables.rb +0 -28
- data/samples/learning_processing/chapter_04/6_ellipse_with_variables.rb +0 -24
- data/samples/learning_processing/chapter_04/7_filling_variables_with_random_values.rb +0 -27
- data/samples/learning_processing/chapter_04/8_variable_zoog.rb +0 -50
- data/samples/learning_processing/chapter_05/01_conditionals.rb +0 -31
- data/samples/learning_processing/chapter_05/02_more_conditionals.rb +0 -38
- data/samples/learning_processing/chapter_05/03_rollovers.rb +0 -34
- data/samples/learning_processing/chapter_05/04_hold_down_the_button.rb +0 -33
- data/samples/learning_processing/chapter_05/05_button_as_switch.rb +0 -39
- data/samples/learning_processing/chapter_05/06_bouncing_ball.rb +0 -33
- data/samples/learning_processing/chapter_05/07_bouncing_color.rb +0 -37
- data/samples/learning_processing/chapter_05/08_square_following_edge.rb +0 -59
- data/samples/learning_processing/chapter_05/09_simple_gravity.rb +0 -43
- data/samples/learning_processing/chapter_05/10_zoog_and_conditionals.rb +0 -53
- data/samples/learning_processing/chapter_06/01_many_lines.rb +0 -29
- data/samples/learning_processing/chapter_06/02_many_lines_with_variables.rb +0 -53
- data/samples/learning_processing/chapter_06/03_while_loop.rb +0 -30
- data/samples/learning_processing/chapter_06/04_infinite_loop.rb +0 -25
- data/samples/learning_processing/chapter_06/05_another_infinite_loop.rb +0 -33
- data/samples/learning_processing/chapter_06/06_legs_with_a_for_loop.rb +0 -41
- data/samples/learning_processing/chapter_06/07_local_variables.rb +0 -39
- data/samples/learning_processing/chapter_06/08_lines_one_at_a_time.rb +0 -30
- data/samples/learning_processing/chapter_06/09_simple_while_loop_with_interactivity.rb +0 -41
- data/samples/learning_processing/chapter_06/10_zoog_with_arms.rb +0 -56
- data/samples/learning_processing/chapter_06/11_multiple_zoogs.rb +0 -46
- data/samples/learning_processing/chapter_07/01_defining_a_function.rb +0 -22
- data/samples/learning_processing/chapter_07/02_calling_a_function.rb +0 -22
- data/samples/learning_processing/chapter_07/03_bouncing_ball_with_functions.rb +0 -49
- data/samples/learning_processing/chapter_07/04_function_returns_distance.rb +0 -48
- data/samples/learning_processing/chapter_07/05_zoog_with_functions.rb +0 -71
- data/samples/learning_processing/chapter_08/01_car_class_and_car_variable.rb +0 -45
- data/samples/learning_processing/chapter_08/02_two_car_objects.rb +0 -60
- data/samples/learning_processing/chapter_08/03_object_oriented_zoog.rb +0 -81
- data/samples/learning_processing/chapter_10/01_catcher.rb +0 -35
- data/samples/learning_processing/chapter_10/02_bouncing_ball.rb +0 -44
- data/samples/learning_processing/chapter_10/03_bouncing_balls_with_intersection.rb +0 -69
- data/samples/learning_processing/chapter_10/04_a_timer.rb +0 -24
- data/samples/learning_processing/chapter_10/05_object_oriented_timer.rb +0 -42
- data/samples/learning_processing/chapter_10/06_simple_raindrop.rb +0 -23
- data/samples/learning_processing/chapter_10/07_drops_one_at_a_time.rb +0 -63
- data/samples/learning_processing/chapter_13/02_random_number_distribution.rb +0 -24
- data/samples/learning_processing/chapter_13/03_probabilities.rb +0 -33
- data/samples/learning_processing/chapter_13/04_perlin_noise.rb +0 -22
- data/samples/learning_processing/chapter_13/06_oscillation.rb +0 -29
- data/samples/learning_processing/chapter_13/07_wave.rb +0 -31
- data/samples/learning_processing/chapter_13/08_recursion.rb +0 -30
- data/samples/learning_processing/chapter_13/09_two_dimensional_array.rb +0 -21
- data/samples/learning_processing/chapter_13/10_two_dimensional_array_with_objects.rb +0 -54
- data/samples/learning_processing/chapter_14/01_growing_rectangle.rb +0 -26
- data/samples/learning_processing/chapter_14/02_multiple_translations.rb +0 -37
- data/samples/learning_processing/chapter_14/03_depth_rectangle.rb +0 -29
- data/samples/learning_processing/chapter_14/04_pyramid_using_beingshape.rb +0 -55
- data/samples/learning_processing/chapter_14/05_rotate_rectangle_around_center.rb +0 -28
- data/samples/learning_processing/chapter_14/06_rotate_z.rb +0 -24
- data/samples/learning_processing/chapter_14/07_rotate_x.rb +0 -24
- data/samples/learning_processing/chapter_14/08_rotate_y.rb +0 -24
- data/samples/learning_processing/chapter_14/09_rotate_all.rb +0 -24
- data/samples/learning_processing/chapter_14/10_draw_pyramid.rb +0 -59
- data/samples/learning_processing/chapter_14/12_rotating_one_square.rb +0 -25
- data/samples/learning_processing/chapter_14/13_rotating_another_square.rb +0 -25
- data/samples/learning_processing/chapter_14/14_rotating_both_squares.rb +0 -43
- data/samples/learning_processing/chapter_14/15_rotating_many_things.rb +0 -56
- data/samples/learning_processing/chapter_14/16_simple_solar_system.rb +0 -53
- data/samples/learning_processing/chapter_14/17_nested_push_and_pop.rb +0 -50
- data/samples/learning_processing/chapter_14/18_object_oriented_solar_system.rb +0 -69
- data/samples/learning_processing/chapter_15/01_hello_world_image.rb +0 -20
- data/samples/learning_processing/chapter_15/02_image_sprite.rb +0 -29
- data/samples/learning_processing/chapter_15/03_swapping_images.rb +0 -25
- data/samples/learning_processing/chapter_15/04_image_sequence.rb +0 -22
- data/samples/learning_processing/chapter_15/05_setting_pixels.rb +0 -19
- data/samples/learning_processing/chapter_15/06_pixels_2d.rb +0 -29
- data/samples/learning_processing/chapter_15/07_image_pixels.rb +0 -40
- data/samples/learning_processing/chapter_15/08_image_brightness.rb +0 -29
- data/samples/learning_processing/chapter_15/09_flashlight_effect.rb +0 -42
- data/samples/learning_processing/chapter_15/10_brightness_threshold.rb +0 -33
- data/samples/learning_processing/chapter_15/11_brightness_threshold_with_filter.rb +0 -20
- data/samples/learning_processing/chapter_15/12_pixel_neighbour_differences.rb +0 -43
- data/samples/learning_processing/chapter_15/14_pointillism.rb +0 -34
- data/samples/learning_processing/chapter_15/15_2d_image_mapped_to_3d.rb +0 -43
- data/samples/learning_processing/chapter_15/data/animal0.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal1.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal2.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal3.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal4.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal5.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/animal6.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/face.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/mysummervacation.jpg +0 -0
- data/samples/learning_processing/chapter_15/data/sunflower.jpg +0 -0
- data/samples/learning_processing/chapter_16/01_display_video.rb +0 -25
- data/samples/learning_processing/chapter_16/02_manipulate_video_image.rb +0 -24
- data/samples/learning_processing/chapter_16/03_adjust_video_brightness.rb +0 -49
- data/samples/learning_processing/chapter_17/01_simple_displaying_text.rb +0 -14
- data/samples/learning_processing/chapter_17/02_text_align.rb +0 -21
- data/samples/learning_processing/chapter_17/03_scrolling_headlines.rb +0 -35
- data/samples/learning_processing/chapter_17/04_text_mirror.rb +0 -68
- data/samples/learning_processing/chapter_17/05_rotating_text.rb +0 -22
- data/samples/learning_processing/chapter_17/06_text_breaking_up.rb +0 -73
- data/samples/learning_processing/chapter_17/07_boxes_along_a_curve.rb +0 -49
- data/samples/learning_processing/chapter_17/08_characters_along_a_curve.rb +0 -51
- data/samples/learning_processing/chapter_17/data/ArialMT-16.vlw +0 -0
- data/samples/learning_processing/chapter_17/data/Courier-Bold-20.vlw +0 -0
- data/samples/learning_processing/chapter_18/01_user_input.rb +0 -39
- data/samples/learning_processing/chapter_18/02_graphing_comma_separated_numbers_from_a_text_file.rb +0 -28
- data/samples/learning_processing/chapter_18/03_creating_object_from_a_text_file.rb +0 -64
- data/samples/learning_processing/chapter_18/data/data-1.txt +0 -1
- data/samples/learning_processing/chapter_18/data/data-2.txt +0 -10
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class FlashlightEffectSketch < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@image = load_image 'sunflower.jpg'
|
7
|
-
# Let's grab the red, green and blue component of each pixel of the image to start with.
|
8
|
-
@image_pixels = @image.pixels.map {|p| [red(p), green(p), blue(p)]}
|
9
|
-
end
|
10
|
-
|
11
|
-
def draw
|
12
|
-
load_pixels # Load the pixels array
|
13
|
-
# Two loops allow us to visit every column (x) and every row (y).
|
14
|
-
# Loop through every pixel column
|
15
|
-
width.times do |x|
|
16
|
-
# Loop through every pixel row
|
17
|
-
height.times do |y|
|
18
|
-
# Use the formula to find the 1D location
|
19
|
-
loc = x + y * width # The location in the pixel array is calculated via our formula: 1D pixel location = x + y * width
|
20
|
-
|
21
|
-
# Calculate an amount to change brightness
|
22
|
-
# based on proximity to the mouse
|
23
|
-
distance = dist(x, y, mouseX, mouseY)
|
24
|
-
|
25
|
-
# The closer the pixel is to the mouse, the lower the value of "distance"
|
26
|
-
# We want closer pixels to be brighter, however, so we invert the value with the formula: adjustment = (50-distance)/50
|
27
|
-
# Pixels with a distance of 50 (or greater) have a brightness of 0.0 (or negative which is equivalent to 0 here)
|
28
|
-
# Pixels with a distance of 0 have a brightness of 1.0.
|
29
|
-
adjustment = (50 - distance) / 50
|
30
|
-
|
31
|
-
# Set the display pixel to the image pixel
|
32
|
-
pixels[loc] = color(*@image_pixels[loc].map {|rgb| rgb * adjustment })
|
33
|
-
end
|
34
|
-
end
|
35
|
-
update_pixels
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
FlashlightEffectSketch.new :title => "Flashlight Effect", :width => 200, :height => 200
|
41
|
-
|
42
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class BrightnessThresholdSketch < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@source = load_image 'sunflower.jpg'
|
7
|
-
@destination = create_image @source.width, @source.height, RGB
|
8
|
-
end
|
9
|
-
|
10
|
-
def draw
|
11
|
-
threshold = 127
|
12
|
-
# We are going to look at both image's pixels
|
13
|
-
@source.load_pixels
|
14
|
-
@destination.load_pixels
|
15
|
-
|
16
|
-
@source.width.times do |x|
|
17
|
-
@source.height.times do |y|
|
18
|
-
loc = x + y*@source.width;
|
19
|
-
# Test the brightness against the threshold
|
20
|
-
@destination.pixels[loc] = (brightness(@source.pixels[loc]) > threshold) ? color(255) : color(0)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# We changed the pixels in @destination
|
25
|
-
@destination.update_pixels
|
26
|
-
# Display the @destination
|
27
|
-
image @destination, 0, 0
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
BrightnessThresholdSketch.new :title => "Brightness Threshold", :width => 200, :height => 200
|
33
|
-
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class BrightnessThresholdWithFilterSketch < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@img = load_image 'sunflower.jpg'
|
7
|
-
end
|
8
|
-
|
9
|
-
def draw
|
10
|
-
# Draw the image
|
11
|
-
image @img, 0, 0
|
12
|
-
# Filter the window with a threshold effect
|
13
|
-
# 0.5 means threshold is 50% brightness
|
14
|
-
filter THRESHOLD, 0.5
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
BrightnessThresholdWithFilterSketch.new :title => "Brightness Threshold With Filter", :width => 200, :height => 200
|
20
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class PixelNeighbourDifferencesSketch < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@img = load_image 'sunflower.jpg'
|
7
|
-
@destination = create_image @img.width, @img.height, RGB
|
8
|
-
end
|
9
|
-
|
10
|
-
def draw
|
11
|
-
# We are going to look at both image's pixels
|
12
|
-
@img.load_pixels
|
13
|
-
@destination.load_pixels
|
14
|
-
|
15
|
-
# Since we are looking at left neighbors
|
16
|
-
# We skip the first column
|
17
|
-
(1...width).each do |x|
|
18
|
-
(0...height).each do |y|
|
19
|
-
# Pixel location and color
|
20
|
-
loc = x + y * @img.width
|
21
|
-
pix = @img.pixels[loc]
|
22
|
-
|
23
|
-
# Pixel to the left location and color
|
24
|
-
left_loc = (x - 1) + y * @img.width
|
25
|
-
left_pix = @img.pixels[left_loc]
|
26
|
-
|
27
|
-
# New color is difference between pixel and left neighbor
|
28
|
-
diff = (brightness(pix) - brightness(left_pix)).abs
|
29
|
-
@destination.pixels[loc] = color(diff)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# We changed the pixels in @destination
|
34
|
-
@destination.update_pixels
|
35
|
-
# Display the @destination
|
36
|
-
image @destination, 0, 0
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
PixelNeighbourDifferencesSketch.new :title => "Pixel Neighbour Differences", :width => 200, :height => 200
|
42
|
-
|
43
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class PointillismSketch < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@pointillize = 10
|
7
|
-
@img = load_image 'sunflower.jpg'
|
8
|
-
background 255
|
9
|
-
frame_rate 200 # Let's run this one as fast as we can.
|
10
|
-
no_stroke
|
11
|
-
smooth
|
12
|
-
end
|
13
|
-
|
14
|
-
def draw
|
15
|
-
# Pick a random point
|
16
|
-
x, y = rand(width), rand(height)
|
17
|
-
loc = x + y * width
|
18
|
-
|
19
|
-
# Look up the RGB color in the source image
|
20
|
-
load_pixels
|
21
|
-
pixel = @img.pixels[loc]
|
22
|
-
r, g, b = red(pixel), green(pixel), blue(pixel)
|
23
|
-
|
24
|
-
# Draw an ellipse at that location with that color
|
25
|
-
fill r, g, b, 100
|
26
|
-
# Back to shapes! Instead of setting a pixel, we use the color from a pixel to draw a circle.
|
27
|
-
ellipse x, y, @pointillize, @pointillize
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
PointillismSketch.new :title => "Pointillism", :width => 200, :height => 200
|
33
|
-
|
34
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class TwoDMappedTo3dSketch < Processing::App
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@cellsize = 2
|
7
|
-
@img = load_image 'sunflower.jpg' # Load the image
|
8
|
-
@img.load_pixels
|
9
|
-
@pixels = @img.pixels
|
10
|
-
@cols = width / @cellsize # Calculate number of columns
|
11
|
-
@rows = height / @cellsize # Calculate number of rows
|
12
|
-
render_mode P3D
|
13
|
-
no_stroke
|
14
|
-
rect_mode CENTER
|
15
|
-
end
|
16
|
-
|
17
|
-
def draw
|
18
|
-
background 255
|
19
|
-
@cols.times do |i| # Begin loop for columns
|
20
|
-
x = i * @cellsize + @cellsize / 2 # x position
|
21
|
-
@rows.times do |j| # Begin loop for rows
|
22
|
-
y = j * @cellsize + @cellsize / 2 # y position
|
23
|
-
loc = x + y * width # Pixel array location
|
24
|
-
c = @pixels[loc] # Grab the color
|
25
|
-
|
26
|
-
# Calculate a z position as a function of mouse_x and pixel brightness
|
27
|
-
z = (mouse_x/width.to_f) * brightness(@pixels[loc]) - 100.0
|
28
|
-
|
29
|
-
# Translate to the location, set fill and stroke, and draw the rect
|
30
|
-
push_matrix
|
31
|
-
translate x, y, z
|
32
|
-
fill c
|
33
|
-
rect 0, 0, @cellsize, @cellsize
|
34
|
-
pop_matrix
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
TwoDMappedTo3dSketch.new :title => "2d Mapped To 3d", :width => 200, :height => 200
|
42
|
-
|
43
|
-
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class CaptureVideoSketch < Processing::App
|
4
|
-
|
5
|
-
# Step 1. Import the video library
|
6
|
-
load_library "video"
|
7
|
-
# We need the video classes to be included here.
|
8
|
-
import "processing.video"
|
9
|
-
|
10
|
-
def setup
|
11
|
-
# Step 2. Declare a Capture object
|
12
|
-
@video = Capture.new(self, width, height, 30)
|
13
|
-
end
|
14
|
-
|
15
|
-
def draw
|
16
|
-
# Step 3 and 4: Read from the camera if it's available.
|
17
|
-
@video.read if @video.available
|
18
|
-
|
19
|
-
# Step 5. Display the video image.
|
20
|
-
image @video, 0, 0
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
CaptureVideoSketch.new :title => "Capture Video", :width => 320, :height => 240
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'ruby-processing'
|
2
|
-
|
3
|
-
class ManipulateVideoImageSketch < Processing::App
|
4
|
-
|
5
|
-
load_library "video"
|
6
|
-
import "processing.video"
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@video = Capture.new(self, width, height, 30)
|
10
|
-
end
|
11
|
-
|
12
|
-
def draw
|
13
|
-
@video.read if @video.available
|
14
|
-
|
15
|
-
# Tinting using mouse location
|
16
|
-
tint mouse_x, mouse_y, 255
|
17
|
-
|
18
|
-
# A video image can also be tinted and resized just as with a PImage.
|
19
|
-
image @video, 0, 0, mouse_x, mouse_y
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
ManipulateVideoImageSketch.new :title => "Manipulate Video Image", :width => 320, :height => 240
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# Example 16-3: Adjust video brightness
|
2
|
-
require 'ruby-processing'
|
3
|
-
|
4
|
-
class AdjustVideoBrightness < Processing::App
|
5
|
-
load_library "video"
|
6
|
-
import "processing.video"
|
7
|
-
|
8
|
-
def setup
|
9
|
-
size 240, 180, P3D
|
10
|
-
|
11
|
-
# Initialize Capture object via Constructor
|
12
|
-
# video is 320 x 240, @15 fps
|
13
|
-
@video = Capture.new self, 240, 180, 15
|
14
|
-
background 0
|
15
|
-
end
|
16
|
-
|
17
|
-
def draw
|
18
|
-
# Check to see if a new frame is available
|
19
|
-
# If so, read it.
|
20
|
-
@video.read if @video.available?
|
21
|
-
|
22
|
-
load_pixels
|
23
|
-
@video.load_pixels
|
24
|
-
pixs = @video.pixels
|
25
|
-
mx, my = mouse_x, mouse_y
|
26
|
-
max_dist = 100
|
27
|
-
vid_width, vid_height = @video.width, @video.height
|
28
|
-
|
29
|
-
vid_width.times do |x|
|
30
|
-
vid_height.times do |y|
|
31
|
-
# Calculate the 1D location from a 2D grid
|
32
|
-
loc = x + y * vid_width
|
33
|
-
pix = pixs[loc]
|
34
|
-
|
35
|
-
# Calculate an amount to change brightness based on proximity to the mouse
|
36
|
-
d = dist(x, y, mx, my)
|
37
|
-
fudge = (max_dist - d) / max_dist
|
38
|
-
r, g, b = red(pix) * fudge, green(pix) * fudge, blue(pix) * fudge
|
39
|
-
|
40
|
-
# Make a new color and set pixel in the window
|
41
|
-
pixels[loc] = color(r, g, b)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
update_pixels
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
AdjustVideoBrightness.new :title => "Adjust Video Brightness"
|
@@ -1,14 +0,0 @@
|
|
1
|
-
def setup
|
2
|
-
size 200, 200
|
3
|
-
# Load Font
|
4
|
-
@font = loadFont "ArialMT-16.vlw"
|
5
|
-
end
|
6
|
-
|
7
|
-
def draw
|
8
|
-
background 255
|
9
|
-
text_font @font, 16 # Specify font to be used
|
10
|
-
fill 0 # Specify font color
|
11
|
-
|
12
|
-
# Display Text
|
13
|
-
text "Mmmmm ... Strings ..." , 10, 100
|
14
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
def setup
|
2
|
-
size 400, 200
|
3
|
-
@font = create_font "Arial", 16, true
|
4
|
-
end
|
5
|
-
|
6
|
-
def draw
|
7
|
-
background 255
|
8
|
-
stroke 175
|
9
|
-
line width/2, 0, width/2, height
|
10
|
-
text_font @font
|
11
|
-
fill 0
|
12
|
-
|
13
|
-
# text_align sets the alignment for displaying text.
|
14
|
-
# It takes one argument: CENTER, LEFT, or RIGHT.
|
15
|
-
text_align CENTER
|
16
|
-
text "This text is centered.", width / 2, 60
|
17
|
-
text_align LEFT
|
18
|
-
text "This text is left aligned.", width/2, 100
|
19
|
-
text_align RIGHT
|
20
|
-
text "This text is right aligned.", width / 2, 140
|
21
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
HEADLINES = "Processing downloads break downloading record.",
|
2
|
-
"New study shows computer programming lowers cholesterol."
|
3
|
-
|
4
|
-
def setup
|
5
|
-
size 400, 200
|
6
|
-
@f = create_font "Arial" ,16, true
|
7
|
-
@x = width
|
8
|
-
@index = 0
|
9
|
-
end
|
10
|
-
|
11
|
-
def draw
|
12
|
-
background 255
|
13
|
-
fill 0
|
14
|
-
|
15
|
-
# Display headline at x location
|
16
|
-
text_font @f, 16
|
17
|
-
text_align LEFT
|
18
|
-
|
19
|
-
# A specific string from the array is displayed according to the value
|
20
|
-
# of the "index" variable.
|
21
|
-
text HEADLINES[@index], @x, 180
|
22
|
-
|
23
|
-
# Decrement x
|
24
|
-
@x = @x - 3
|
25
|
-
|
26
|
-
# If x is less than the negative width, then it is off the screen
|
27
|
-
# text_width is used to calculate the width of the current string.
|
28
|
-
w = text_width(HEADLINES[@index])
|
29
|
-
if (@x < -w)
|
30
|
-
@x = width
|
31
|
-
# @index is incremented when the current string has left
|
32
|
-
# the screen in order to display a new string.
|
33
|
-
@index = (@index + 1) % HEADLINES.length
|
34
|
-
end
|
35
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# This example demonstrates how to use the video library. You'll need a
|
2
|
-
# video camera hooked in to your computer.
|
3
|
-
|
4
|
-
class TextMirror < Processing::App
|
5
|
-
load_library "video"
|
6
|
-
import "processing.video"
|
7
|
-
|
8
|
-
# Size of each cell in the grid, ratio of window size to video size
|
9
|
-
VIDEOSCALE = 14
|
10
|
-
|
11
|
-
# The source text used in the mosaic pattern.
|
12
|
-
# A longer String might produce more interesting results.
|
13
|
-
CHARS = "thetextmirror"
|
14
|
-
|
15
|
-
def setup
|
16
|
-
size 640, 480
|
17
|
-
smooth
|
18
|
-
# Set up columns and rows
|
19
|
-
@cols = width / VIDEOSCALE # Number of columns and...
|
20
|
-
@rows = height / VIDEOSCALE # rows in our system
|
21
|
-
@video = Capture.new(self, @cols, @rows, 15)
|
22
|
-
|
23
|
-
# Load the font
|
24
|
-
# Using a fixed-width font. In most fonts, individual characters have different widths.
|
25
|
-
# In a fixed-width font, all characters have the same width.
|
26
|
-
# This is useful here since we intend to display the letters one at a time spaced out evenly.
|
27
|
-
# See Section 17.7 for how to display text character by character with a nonfixed width font.
|
28
|
-
@f = load_font "Courier-Bold-20.vlw"
|
29
|
-
end
|
30
|
-
|
31
|
-
def draw
|
32
|
-
background 0
|
33
|
-
|
34
|
-
# Read image from the camera
|
35
|
-
@video.read if @video.available?
|
36
|
-
@video.load_pixels
|
37
|
-
|
38
|
-
# Use a variable to count through chars in String
|
39
|
-
charcount = 0
|
40
|
-
# Begin loop for rows
|
41
|
-
@rows.times do |j|
|
42
|
-
# Begin loop for columns
|
43
|
-
@cols.times do |i|
|
44
|
-
|
45
|
-
# Where are we, pixel-wise?
|
46
|
-
x = i * VIDEOSCALE
|
47
|
-
y = j * VIDEOSCALE
|
48
|
-
|
49
|
-
# Looking up the appropriate color in the pixel array
|
50
|
-
c = @video.pixels[i + j * @video.width]
|
51
|
-
|
52
|
-
# Displaying an individual character from the String instead of a rectangle
|
53
|
-
text_font @f
|
54
|
-
fill c
|
55
|
-
|
56
|
-
# One character from the source text is displayed colored accordingly to the pixel location.
|
57
|
-
# A counter variableâ charcountâ is used to walk through the source String one character at a time.
|
58
|
-
text CHARS[charcount].chr, x, y
|
59
|
-
|
60
|
-
# Go on to the next character
|
61
|
-
charcount = (charcount + 1) % CHARS.length
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
TextMirror.new :title => "Text Mirror"
|