ruby-processing 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +12 -0
- data/lib/ruby-processing.rb +2 -1
- data/lib/ruby-processing/app.rb +7 -5
- data/lib/ruby-processing/exporters/creator.rb +7 -4
- data/lib/ruby-processing/helpers/numeric.rb +11 -0
- data/lib/ruby-processing/helpers/string.rb +8 -0
- data/lib/ruby-processing/runner.rb +11 -10
- data/lib/ruby-processing/runners/watch.rb +33 -0
- data/samples/bezier_playground.rb +243 -0
- data/samples/flight_patterns.rb +1 -1
- data/samples/learning_processing/chapter_16/01_display_video.rb +1 -1
- data/samples/learning_processing/chapter_16/02_manipulate_video_image.rb +1 -1
- data/samples/processing_app/basics/arrays/array.rb +41 -0
- data/samples/processing_app/basics/arrays/array_2d.rb +38 -0
- data/samples/processing_app/basics/arrays/array_objects.rb +67 -0
- data/samples/processing_app/basics/color/brightness.rb +30 -0
- data/samples/processing_app/basics/color/color_wheel.rb +97 -0
- data/samples/processing_app/basics/color/creating.rb +37 -0
- data/samples/processing_app/basics/color/hue.rb +29 -0
- data/samples/processing_app/basics/color/linear_gradient.rb +47 -0
- data/samples/processing_app/basics/color/radial_gradient.rb +52 -0
- data/samples/processing_app/basics/color/reading/data/cait.jpg +0 -0
- data/samples/processing_app/basics/color/reading/reading.rb +43 -0
- data/samples/processing_app/basics/color/relativity.rb +38 -0
- data/samples/processing_app/basics/color/saturation.rb +35 -0
- data/samples/processing_app/basics/color/wave_gradient.rb +45 -0
- data/samples/processing_app/basics/control/conditionals1.rb +51 -0
- data/samples/processing_app/basics/control/conditionals2.rb +44 -0
- data/samples/processing_app/basics/control/embedded_iteration.rb +42 -0
- data/samples/processing_app/basics/control/iteration.rb +61 -0
- data/samples/processing_app/basics/control/logical_operators.rb +59 -0
- data/samples/processing_app/basics/data/characters_strings/characters_strings.rb +87 -0
- data/samples/processing_app/basics/data/characters_strings/data/Eureka-90.vlw +0 -0
- data/samples/processing_app/basics/data/characters_strings/data/rathausFrog.jpg +0 -0
- data/samples/processing_app/basics/data/datatype_conversion.rb +45 -0
- data/samples/processing_app/basics/data/integers_floats.rb +34 -0
- data/samples/processing_app/basics/data/true_false.rb +37 -0
- data/samples/processing_app/basics/data/variable_scope.rb +80 -0
- data/samples/processing_app/basics/data/variables.rb +40 -0
- data/samples/processing_app/basics/form/bezier.rb +23 -0
- data/samples/processing_app/basics/form/bezier_ellipse.rb +110 -0
- data/samples/processing_app/basics/form/pie_chart.rb +31 -0
- data/samples/processing_app/basics/form/points_lines.rb +37 -0
- data/samples/processing_app/basics/form/shape_primitives.rb +25 -0
- data/samples/processing_app/basics/form/triangle_strip.rb +43 -0
- data/samples/processing_app/basics/form/vertices.rb +51 -0
- data/samples/processing_app/basics/image/alphamask.rb +23 -0
- data/samples/processing_app/basics/image/background_image.rb +30 -0
- data/samples/processing_app/basics/image/create_image.rb +23 -0
- data/samples/processing_app/basics/image/data/construct.jpg +0 -0
- data/samples/processing_app/basics/image/data/eames.jpg +0 -0
- data/samples/processing_app/basics/image/data/jelly.jpg +0 -0
- data/samples/processing_app/basics/image/data/mask.jpg +0 -0
- data/samples/processing_app/basics/image/data/milan_rubbish.jpg +0 -0
- data/samples/processing_app/basics/image/data/teddy.gif +0 -0
- data/samples/processing_app/basics/image/data/test.jpg +0 -0
- data/samples/processing_app/basics/image/data/wash.jpg +0 -0
- data/samples/processing_app/basics/image/load_display_image.rb +25 -0
- data/samples/processing_app/basics/image/pointillism.rb +30 -0
- data/samples/processing_app/basics/image/request_image.rb +71 -0
- data/samples/processing_app/basics/image/sprite.rb +38 -0
- data/samples/processing_app/basics/image/transparency.rb +27 -0
- data/samples/processing_app/basics/input/clock.rb +46 -0
- data/samples/processing_app/basics/input/constrain.rb +39 -0
- data/samples/processing_app/basics/input/easing.rb +33 -0
- data/samples/processing_app/basics/input/keyboard.rb +36 -0
- data/samples/processing_app/basics/input/keyboard_2.rb +45 -0
- data/samples/processing_app/basics/input/keyboard_functions.rb +87 -0
- data/samples/processing_app/basics/input/milliseconds.rb +25 -0
- data/samples/processing_app/basics/input/mouse_1d.rb +34 -0
- data/samples/processing_app/basics/input/mouse_2d.rb +25 -0
- data/samples/processing_app/basics/input/mouse_functions.rb +73 -0
- data/samples/processing_app/basics/input/mouse_press.rb +21 -0
- data/samples/processing_app/basics/input/mouse_signals.rb +45 -0
- data/samples/processing_app/basics/input/storing_input.rb +39 -0
- data/samples/processing_app/basics/math/additive_wave.rb +66 -0
- data/samples/processing_app/basics/math/arctangent.rb +54 -0
- data/samples/processing_app/topics/simulate/chain.rb +82 -0
- data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +166 -0
- data/samples/processing_app/topics/simulate/simple_particle_system.rb +113 -0
- data/samples/processing_app/topics/simulate/spring.rb +85 -0
- data/samples/processing_app/topics/simulate/springs.rb +125 -0
- metadata +93 -2
data/samples/flight_patterns.rb
CHANGED
@@ -5,7 +5,7 @@ require 'ruby-processing'
|
|
5
5
|
|
6
6
|
class FlightPatterns < Processing::App
|
7
7
|
load_libraries 'boids', 'opengl'
|
8
|
-
|
8
|
+
import "processing.opengl" if library_loaded? "opengl"
|
9
9
|
|
10
10
|
def setup
|
11
11
|
library_loaded?(:opengl) ? setup_opengl : render_mode(P3D)
|
@@ -5,7 +5,7 @@ class CaptureVideoSketch < Processing::App
|
|
5
5
|
# Step 1. Import the video library
|
6
6
|
load_library "video"
|
7
7
|
# We need the video classes to be included here.
|
8
|
-
|
8
|
+
import "processing.video"
|
9
9
|
|
10
10
|
def setup
|
11
11
|
# Step 2. Declare a Capture object
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# * An array is a list of data. Each piece of data in an array
|
4
|
+
# * is identified by an index number representing its position in
|
5
|
+
# * the array. Arrays are zero based, which means that the first
|
6
|
+
# * element in the array is [0], the second element is [1], and so on.
|
7
|
+
# * In this example, an array named "coswav" is created and
|
8
|
+
# * filled with the cosine values. This data is displayed three
|
9
|
+
# * separate ways on the screen.
|
10
|
+
|
11
|
+
class ArrayExample < Processing::App
|
12
|
+
|
13
|
+
def setup
|
14
|
+
|
15
|
+
coswave = []
|
16
|
+
|
17
|
+
0.upto( width ) do |i|
|
18
|
+
amount = map i, 0, width, 0, PI
|
19
|
+
coswave[i] = cos( amount ).abs
|
20
|
+
end
|
21
|
+
|
22
|
+
0.upto( width ) do |i|
|
23
|
+
stroke( coswave[i] * 255 )
|
24
|
+
line i, 0, i, height/3
|
25
|
+
end
|
26
|
+
|
27
|
+
0.upto( width ) do |i|
|
28
|
+
stroke( coswave[i] * 255 / 4 )
|
29
|
+
line i, height/3, i, height/3*2
|
30
|
+
end
|
31
|
+
|
32
|
+
0.upto( width ) do |i|
|
33
|
+
stroke( 255 - coswave[i] * 255 )
|
34
|
+
line i, height/3*2, i, height
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
ArrayExample.new :title => "Array Example", :width => 200, :height => 200
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# * Demonstrates the syntax for creating a two-dimensional (2D) array.
|
4
|
+
# * Values in a 2D array are accessed through two index values.
|
5
|
+
# * 2D arrays are useful for storing images. In this example, each dot
|
6
|
+
# * is colored in relation to its distance from the center of the image.
|
7
|
+
|
8
|
+
class Array2d < Processing::App
|
9
|
+
|
10
|
+
def setup
|
11
|
+
|
12
|
+
distances = Array.new( width ) { Array.new( height ) } # [width][height]
|
13
|
+
|
14
|
+
max_distance = dist( width/2, height/2, width, height )
|
15
|
+
|
16
|
+
width.times do |x|
|
17
|
+
height.times do |y|
|
18
|
+
distance = dist( width/2, height/2, x, y )
|
19
|
+
distances[x][y] = distance / max_distance * 255
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
background 0
|
24
|
+
|
25
|
+
x = 0; while x < distances.length
|
26
|
+
y = 0; while y < distances[x].length
|
27
|
+
stroke distances[x][y]
|
28
|
+
point x, y
|
29
|
+
y += 2
|
30
|
+
end
|
31
|
+
x += 2
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
Array2d.new :title => "Array 2d", :width => 200, :height => 200
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# * Demonstrates the syntax for creating an array of custom objects.
|
4
|
+
|
5
|
+
class ArrayObjects < Processing::App
|
6
|
+
|
7
|
+
UNIT = 40
|
8
|
+
|
9
|
+
def setup
|
10
|
+
|
11
|
+
@num = width/UNIT ** 2
|
12
|
+
@mods = []
|
13
|
+
|
14
|
+
basis = (height/UNIT).to_i
|
15
|
+
|
16
|
+
basis.times do |i|
|
17
|
+
basis.times do |j|
|
18
|
+
@mods << CustomObject.new( j*UNIT, i*UNIT, UNIT/2, UNIT/2, random( 0.05, 0.8 ) )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
background 176
|
23
|
+
no_stroke
|
24
|
+
end
|
25
|
+
|
26
|
+
def draw
|
27
|
+
stroke(second * 4)
|
28
|
+
|
29
|
+
@mods.each do |mod|
|
30
|
+
mod.update; mod.draw
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# the custom object
|
35
|
+
|
36
|
+
class CustomObject
|
37
|
+
|
38
|
+
def initialize( mx, my, x, y, speed )
|
39
|
+
@mx, @my = my, mx # This is backwards because the Processing example is backwards.
|
40
|
+
@x, @y = x.to_i, y.to_i
|
41
|
+
@xdir, @ydir = 1, 1
|
42
|
+
@speed = speed
|
43
|
+
@size = UNIT
|
44
|
+
end
|
45
|
+
|
46
|
+
def update
|
47
|
+
@x += @speed * @xdir
|
48
|
+
if @x >= @size || @x <= 0
|
49
|
+
@xdir *= -1
|
50
|
+
@x += @xdir
|
51
|
+
@y += @ydir
|
52
|
+
end
|
53
|
+
if @y >= @size || @x <= 0
|
54
|
+
@ydir *= -1
|
55
|
+
@y += @ydir
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def draw
|
60
|
+
$app.point( @mx + @x - 1, @my + @y - 1 )
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
ArrayObjects.new :title => "Array Objects", :width => 200, :height => 200
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Brightness
|
4
|
+
# by Rusty Robison.
|
5
|
+
#
|
6
|
+
# Brightness is the relative lightness or darkness of a color.
|
7
|
+
# Move the cursor vertically over each bar to alter its brightness.
|
8
|
+
|
9
|
+
class Brightness < Processing::App
|
10
|
+
|
11
|
+
def setup
|
12
|
+
no_stroke
|
13
|
+
color_mode HSB, 360, height, height
|
14
|
+
@bar_width = 5
|
15
|
+
@brightness = Array.new(width/@bar_width, 0)
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
19
|
+
(width/@bar_width).times do |i|
|
20
|
+
n = i * @bar_width
|
21
|
+
range = (n..n+@bar_width)
|
22
|
+
@brightness[i] = mouse_y if range.include? mouse_x
|
23
|
+
fill n, height, @brightness[i]
|
24
|
+
rect n, 0, @bar_width, height
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
Brightness.new :title => "Brightness", :width => 200, :height => 200
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Subtractive Color Wheel
|
4
|
+
# by Ira Greenberg.
|
5
|
+
#
|
6
|
+
# The primaries are red, yellow, and blue. The
|
7
|
+
# secondaries are green, purple, and orange. The
|
8
|
+
# tertiaries are yellow-orange, red-orange, red-purple,
|
9
|
+
# blue-purple, blue-green, and yellow-green.
|
10
|
+
#
|
11
|
+
# Create a shade or tint of the
|
12
|
+
# subtractive color wheel using
|
13
|
+
# SHADE or TINT parameters.
|
14
|
+
|
15
|
+
class ColorWheel < Processing::App
|
16
|
+
|
17
|
+
def setup
|
18
|
+
background 127
|
19
|
+
smooth
|
20
|
+
ellipse_mode RADIUS
|
21
|
+
no_stroke
|
22
|
+
|
23
|
+
@style = :tint # use :shade or :tint
|
24
|
+
create_wheel width/2, height/2, @style
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def create_wheel( x, y, value_shift )
|
29
|
+
|
30
|
+
segs = 12
|
31
|
+
steps = 6
|
32
|
+
rot_adjust = (360.0 / segs / 2.0) * PI / 180
|
33
|
+
radius = 95.0
|
34
|
+
seg_width = radius / steps
|
35
|
+
interval = TWO_PI / segs
|
36
|
+
|
37
|
+
case value_shift
|
38
|
+
when :shade
|
39
|
+
steps.times do |j|
|
40
|
+
cols = [
|
41
|
+
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
|
42
|
+
color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0),
|
43
|
+
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
|
44
|
+
color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0),
|
45
|
+
color(255-(255/steps)*j, 0, 0),
|
46
|
+
color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j),
|
47
|
+
color(255-(255/steps)*j, 0, 255-(255/steps)*j),
|
48
|
+
color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j),
|
49
|
+
color(0, 0, 255-(255/steps)*j),
|
50
|
+
color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j),
|
51
|
+
color(0, 255-(255/steps)*j, 0),
|
52
|
+
color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0)
|
53
|
+
]
|
54
|
+
segs.times do |i|
|
55
|
+
fill cols[i]
|
56
|
+
arc x, y, radius, radius, interval*i+rot_adjust, interval*(i+1)+rot_adjust
|
57
|
+
end
|
58
|
+
radius -= seg_width
|
59
|
+
end
|
60
|
+
|
61
|
+
when :tint
|
62
|
+
steps.times do |j|
|
63
|
+
cols = [
|
64
|
+
color((255/steps)*j, (255/steps)*j, 0),
|
65
|
+
color((255/steps)*j, ((255/1.5)/steps)*j, 0),
|
66
|
+
color((255/steps)*j, ((255/2)/steps)*j, 0),
|
67
|
+
color((255/steps)*j, ((255/2.5)/steps)*j, 0),
|
68
|
+
color((255/steps)*j, 0, 0),
|
69
|
+
color((255/steps)*j, 0, ((255/2)/steps)*j),
|
70
|
+
color((255/steps)*j, 0, (255/steps)*j),
|
71
|
+
color(((255/2)/steps)*j, 0, (255/steps)*j),
|
72
|
+
color(0, 0, (255/steps)*j),
|
73
|
+
color(0, (255/steps)*j, ((255/2.5)/steps)*j),
|
74
|
+
color(0, (255/steps)*j, 0),
|
75
|
+
color(((255/2)/steps)*j, (255/steps)*j, 0)
|
76
|
+
]
|
77
|
+
segs.times do |i|
|
78
|
+
fill cols[i]
|
79
|
+
arc x, y, radius, radius, interval*i+rot_adjust, interval*(i+1)+rot_adjust
|
80
|
+
end
|
81
|
+
radius -= seg_width
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def draw
|
87
|
+
# Empty draw method. Things only change when you click.
|
88
|
+
end
|
89
|
+
|
90
|
+
def mouse_pressed
|
91
|
+
@style = @style == :tint ? :shade : :tint
|
92
|
+
create_wheel width/2, height/2, @style
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
ColorWheel.new :title => "Color Wheel", :width => 200, :height => 200
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Creating Colors (Homage to Albers).
|
4
|
+
#
|
5
|
+
# Creating variables for colors that may be referred to
|
6
|
+
# in the program by their name, rather than a number.
|
7
|
+
|
8
|
+
class Creating < Processing::App
|
9
|
+
|
10
|
+
def setup
|
11
|
+
|
12
|
+
redder = color 204, 102, 0
|
13
|
+
yellower = color 204, 153, 0
|
14
|
+
orangish = color 153, 51, 0
|
15
|
+
|
16
|
+
# These statements are equivalent to the statements above.
|
17
|
+
# Programmers may use the format they prefer.
|
18
|
+
|
19
|
+
# redder = 0xFFCC6600
|
20
|
+
# yellower = 0xFFCC9900
|
21
|
+
# orangish = 0xFF993300
|
22
|
+
|
23
|
+
no_stroke
|
24
|
+
|
25
|
+
fill orangish
|
26
|
+
rect 0, 0, 200, 200
|
27
|
+
|
28
|
+
fill yellower
|
29
|
+
rect 40, 60, 120, 120
|
30
|
+
|
31
|
+
fill redder
|
32
|
+
rect 60, 90, 80, 80
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
Creating.new :title => "Creating", :width => 200, :height => 200
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Hue is the color reflected from or transmitted through an object
|
4
|
+
# and is typically referred to as the name of the color (red, blue, yellow, etc.)
|
5
|
+
# Move the cursor vertically over each bar to alter its hue.
|
6
|
+
|
7
|
+
class Hue < Processing::App
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@bar_width = 5
|
11
|
+
@hue = Array.new( (width/@bar_width), 0 )
|
12
|
+
|
13
|
+
color_mode HSB, 360, height, height
|
14
|
+
no_stroke
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
(width/@bar_width).times do |i|
|
19
|
+
n = i * @bar_width
|
20
|
+
range = (n..n+@bar_width)
|
21
|
+
@hue[i] = mouse_y if range.include?(mouse_x)
|
22
|
+
fill @hue[i], height/1.2, height/1.2
|
23
|
+
rect n, 0, @bar_width, height
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
Hue.new :title => "Hue", :width => 200, :height => 200
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Simple Linear Gradient
|
4
|
+
# by Ira Greenberg.
|
5
|
+
#
|
6
|
+
# Using the convenient red(), green()
|
7
|
+
# and blue() component functions,
|
8
|
+
# generate some linear gradients.
|
9
|
+
|
10
|
+
class LinearGradient < Processing::App
|
11
|
+
|
12
|
+
def setup
|
13
|
+
b1 = color 190
|
14
|
+
b2 = color 20
|
15
|
+
set_gradient 0, 0, width.to_f, height.to_f, b1, b2, :y_axis
|
16
|
+
|
17
|
+
c1 = color 255, 120, 0
|
18
|
+
c2 = color 10, 45, 255
|
19
|
+
c3 = color 10, 255, 15
|
20
|
+
c4 = color 125, 2, 140
|
21
|
+
c5 = color 255, 255, 0
|
22
|
+
c6 = color 25, 255, 200
|
23
|
+
set_gradient 25, 25, 75, 75, c1, c2, true
|
24
|
+
set_gradient 100, 25, 75, 75, c3, c4, false
|
25
|
+
set_gradient 25, 100, 75, 75, c2, c5, false
|
26
|
+
set_gradient 100, 100, 75, 75, c4, c6, true
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_gradient( x, y, w, h, c1, c2, vertical )
|
30
|
+
delta_r = red(c2) - red(c1)
|
31
|
+
delta_g = green(c2) - green(c1)
|
32
|
+
delta_b = blue(c2) - blue(c1)
|
33
|
+
|
34
|
+
x.upto( x+w ) do |i|
|
35
|
+
y.upto( y+w ) do |j|
|
36
|
+
c = color(red(c1)+(j-y)*(delta_r/h),
|
37
|
+
green(c1)+(j-y)*(delta_g/h),
|
38
|
+
blue(c1)+(j-y)*(delta_b/h) )
|
39
|
+
|
40
|
+
vertical ? set(i, j, c) : set(j, i, c)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
LinearGradient.new :title => "Linear Gradient", :width => 200, :height => 200
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'ruby-processing'
|
2
|
+
|
3
|
+
# Simple Radial Gradient
|
4
|
+
# by Ira Greenberg.
|
5
|
+
#
|
6
|
+
# Using the convenient red(), green()
|
7
|
+
# and blue() component functions,
|
8
|
+
# generate an array of radial gradients.
|
9
|
+
|
10
|
+
class RadialGradient < Processing::App
|
11
|
+
|
12
|
+
def setup
|
13
|
+
background 0
|
14
|
+
smooth
|
15
|
+
no_fill
|
16
|
+
stroke_width 1.8
|
17
|
+
|
18
|
+
columns = 4
|
19
|
+
radius = (width / columns) / 2
|
20
|
+
diameter = radius * 2
|
21
|
+
|
22
|
+
(width / diameter).times do |left|
|
23
|
+
(height / diameter).times do |top|
|
24
|
+
create_gradient(
|
25
|
+
radius+left*diameter, radius+top*diameter, radius, random_color, random_color
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def random_color
|
32
|
+
color(rand(255), rand(255), rand(255))
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_gradient( x, y, radius, c1, c2 )
|
36
|
+
|
37
|
+
delta_r = red(c2) - red(c1)
|
38
|
+
delta_g = green(c2) - green(c1)
|
39
|
+
delta_b = blue(c2) - blue(c1)
|
40
|
+
|
41
|
+
radius.times do |r|
|
42
|
+
c = color(red(c1) + r * (delta_r / radius),
|
43
|
+
green(c1) + r * (delta_g / radius),
|
44
|
+
blue(c1) + r * (delta_b / radius))
|
45
|
+
stroke c
|
46
|
+
ellipse x, y, r*2, r*2
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
RadialGradient.new :title => "Radial Gradient", :width => 200, :height => 200
|