-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcircles.rb
More file actions
52 lines (41 loc) · 1.09 KB
/
Copy pathcircles.rb
File metadata and controls
52 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'ruby-processing'
# Simple Radial Gradient
# by Ira Greenberg.
#
# Using the convenient red(), green()
# and blue() component functions,
# generate an array of radial gradients.
class Circles < Processing::App
def setup
background 240
smooth
no_fill
stroke_width 1.8
columns = 4
radius = (width / columns) / 2
diameter = radius * 2
(width / diameter).times do |left|
(height / diameter).times do |top|
create_gradient(
radius+left*diameter, radius+top*diameter, radius, random_color, random_color
)
end
end
end
def random_color
color(rand(255), rand(255), rand(255))
end
def create_gradient( x, y, radius, c1, c2 )
delta_r = red(c2) - red(c1)
delta_g = green(c2) - green(c1)
delta_b = blue(c2) - blue(c1)
radius.times do |r|
c = color(red(c1) + r * (delta_r / radius),
green(c1) + r * (delta_g / radius),
blue(c1) + r * (delta_b / radius))
stroke c
ellipse x, y, r*2, r*2
end
end
end
Circles.new :width => 200, :height => 200