cf3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.yardopts +5 -0
- data/CHANGELOG +3 -0
- data/CONTRIBUTING.md +32 -0
- data/Gemfile +4 -0
- data/LICENSE.md +675 -0
- data/README.md +35 -0
- data/Rakefile +15 -0
- data/bin/cf3samples +16 -0
- data/cf3ruby.gemspec +29 -0
- data/lib/cf3.rb +240 -0
- data/lib/cf3/version.rb +3 -0
- data/samples/accident.rb +98 -0
- data/samples/alhambra.rb +79 -0
- data/samples/bar_code.rb +85 -0
- data/samples/city.rb +60 -0
- data/samples/creature.rb +59 -0
- data/samples/dark_star.rb +47 -0
- data/samples/data/java_args.txt +2 -0
- data/samples/dragon.rb +40 -0
- data/samples/escher.rb +124 -0
- data/samples/fern.rb +46 -0
- data/samples/grapher.rb +47 -0
- data/samples/hex_tube.rb +47 -0
- data/samples/isosceles.rb +36 -0
- data/samples/levy.rb +38 -0
- data/samples/pcr.rb +89 -0
- data/samples/sierpinski.rb +44 -0
- data/samples/spiral.rb +53 -0
- data/samples/tree.rb +98 -0
- data/samples/tree4.rb +65 -0
- data/samples/vine.rb +57 -0
- data/samples/y.rb +46 -0
- data/test/test_cf3.rb +26 -0
- metadata +128 -0
data/samples/grapher.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#########################
|
2
|
+
# grapher.rb by Martin Prout after grapher.cfdg
|
3
|
+
#########################
|
4
|
+
require 'cf3'
|
5
|
+
#load_library :cf3
|
6
|
+
|
7
|
+
def setup_the_hextube
|
8
|
+
@hexa = ContextFree.define do
|
9
|
+
############ Begin defining custom terminal, as a hexagon (path C++ cfdg)
|
10
|
+
class << self
|
11
|
+
define_method(:hexagon) do |some_options|
|
12
|
+
size, options = *self.get_shape_values(some_options)
|
13
|
+
rot = (options[:rotation])? options[:rotation]: 0
|
14
|
+
no_fill
|
15
|
+
stroke(*options[:color])
|
16
|
+
stroke_weight(size/30)
|
17
|
+
begin_shape
|
18
|
+
6.times do |i|
|
19
|
+
vertex(size * Math.cos(Math::PI * i/3 + rot), size * Math.sin(Math::PI * i/3 + rot))
|
20
|
+
end
|
21
|
+
end_shape(CLOSE)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
########### End definition of custom terminal 'hexagon'
|
25
|
+
shape :hextube do
|
26
|
+
hexa brightness: 1.0
|
27
|
+
end
|
28
|
+
|
29
|
+
shape :hexa do |i = nil, j = 0.5|
|
30
|
+
hexagon size: 1, brightness: 1.0
|
31
|
+
hexa size: 0.9, rotation: 5 *j
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def setup
|
37
|
+
size 800, 800
|
38
|
+
background 0
|
39
|
+
smooth
|
40
|
+
setup_the_hextube
|
41
|
+
draw_it
|
42
|
+
end
|
43
|
+
|
44
|
+
def draw_it
|
45
|
+
@hexa.render :hextube, start_x: width/2, start_y: height/2,
|
46
|
+
size: height/2.1, color: [0, 1, 1, 0.5]
|
47
|
+
end
|
data/samples/hex_tube.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#########################
|
2
|
+
# hextube.rb by Martin Prout
|
3
|
+
#########################
|
4
|
+
require 'cf3'
|
5
|
+
#load_library :cf3
|
6
|
+
|
7
|
+
def setup_the_hextube
|
8
|
+
@hexa = ContextFree.define do
|
9
|
+
############ Begin defining custom terminal, as a hexagon (path C++ cfdg)
|
10
|
+
class << self
|
11
|
+
define_method(:hexagon) do |some_options|
|
12
|
+
size, options = *self.get_shape_values(some_options)
|
13
|
+
rot = (options[:rotation])? options[:rotation]: 0
|
14
|
+
no_fill
|
15
|
+
stroke(*options[:color])
|
16
|
+
stroke_weight(size/30)
|
17
|
+
begin_shape
|
18
|
+
6.times do |i|
|
19
|
+
vertex(size * Math.cos(Math::PI * i/3 + rot), size * Math.sin(Math::PI * i/3 + rot))
|
20
|
+
end
|
21
|
+
end_shape(CLOSE)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
########### End definition of custom terminal 'hexagon'
|
25
|
+
shape :hextube do
|
26
|
+
hexa brightness: 1.0
|
27
|
+
end
|
28
|
+
|
29
|
+
shape :hexa do |i = nil, j = 0.5|
|
30
|
+
hexagon size: 1, brightness: 1.0
|
31
|
+
hexa size: 0.9, rotation: 5 *j
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def setup
|
37
|
+
size 800, 800
|
38
|
+
background 0
|
39
|
+
smooth
|
40
|
+
setup_the_hextube
|
41
|
+
draw_it
|
42
|
+
end
|
43
|
+
|
44
|
+
def draw_it
|
45
|
+
@hexa.render :hextube, start_x: width/2, start_y: height/2,
|
46
|
+
size: height/2.1, color: [0, 1, 1, 0.5]
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'cf3'
|
2
|
+
|
3
|
+
def setup_the_spiral
|
4
|
+
@spiral= ContextFree.define do
|
5
|
+
############ Begin defining custom terminal, an isoceles triangle
|
6
|
+
class << self
|
7
|
+
define_method(:isoceles) do |some_options| # isoceles triangle
|
8
|
+
size, options = *self.get_shape_values(some_options)
|
9
|
+
rot = options[:rotation]
|
10
|
+
rotate(rot) if rot
|
11
|
+
$app.triangle(-0.5 * size, -0.5 * size, -0.5 * size, 0.5 * size, 0.5 * size, 0.5 * size)
|
12
|
+
rotate(-rot) if rot
|
13
|
+
end
|
14
|
+
end
|
15
|
+
########### End definition of custom terminal 'isoceles'
|
16
|
+
shape :spiral do
|
17
|
+
isoceles brightness: -1, rotation: 90
|
18
|
+
spiral rotation: 135, size: 1/sqrt(2), x: 1/sqrt(2)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup
|
24
|
+
size 800, 500
|
25
|
+
setup_the_spiral
|
26
|
+
draw_it
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw
|
30
|
+
# Do nothing.
|
31
|
+
end
|
32
|
+
|
33
|
+
def draw_it
|
34
|
+
background 255
|
35
|
+
@spiral.render :spiral, size: height, start_x: width/3, start_y: height/2
|
36
|
+
end
|
data/samples/levy.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# levy.rb ruby-processing NB: :alpha is now implemented ruby-processing
|
2
|
+
require 'cf3'
|
3
|
+
|
4
|
+
def setup_the_levy
|
5
|
+
@levy = ContextFree.define do
|
6
|
+
shape :start do
|
7
|
+
levy brightness: 0.9
|
8
|
+
end
|
9
|
+
shape :levy do
|
10
|
+
square alpha: 0.1
|
11
|
+
split do
|
12
|
+
levy size: 1/Math.sqrt(2), rotation: -45, x: 0.5, brightness: 0.9
|
13
|
+
rewind
|
14
|
+
levy size: 1/Math.sqrt(2), rotation: 45, x: 0.5, brightness: 0.9
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def setup
|
22
|
+
size 400, 400
|
23
|
+
setup_the_levy
|
24
|
+
draw_it
|
25
|
+
save_frame("levy.png")
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def draw
|
30
|
+
# Do nothing.
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def draw_it
|
35
|
+
background 255
|
36
|
+
@levy.render :start, size: 250, stop_size: 2,
|
37
|
+
start_x: width/4, start_y: height/2
|
38
|
+
end
|
data/samples/pcr.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
##############################
|
2
|
+
# electrophoresis.rb whatever
|
3
|
+
# demonstrates the hbar custom
|
4
|
+
# terminal. Also weighted rules
|
5
|
+
# by Martin Prout
|
6
|
+
##############################
|
7
|
+
require 'cf3'
|
8
|
+
|
9
|
+
def setup_the_gel
|
10
|
+
@pcr = ContextFree.define do
|
11
|
+
############ Begin defining custom terminal, a proportional horizontal bar
|
12
|
+
class << self
|
13
|
+
define_method(:hbar) do |some_options|
|
14
|
+
size, options = *self.get_shape_values(some_options)
|
15
|
+
ht = some_options[:ht]|| 0.1 # default hbar width is 0.1
|
16
|
+
ratio = ht * size
|
17
|
+
rot = options[:rotation]
|
18
|
+
rect_mode(CENTER)
|
19
|
+
rotate(rot) if rot
|
20
|
+
rect(-0.5 * size, -0.5 * ratio, 0.5 * size, 0.5 * ratio)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
########### End definition of custom terminal 'hbar'
|
24
|
+
|
25
|
+
shape :gel do
|
26
|
+
dna brightness: 1.0
|
27
|
+
end
|
28
|
+
|
29
|
+
shape :dna do
|
30
|
+
split do
|
31
|
+
26.times do
|
32
|
+
band x: 0.6
|
33
|
+
rewind
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
shape :band do # narrow band with 0.66' probability
|
39
|
+
hbar size: 0.8, ht: 0.1, brightness: 0.3, alpha: 0.3, hue: 0.7, saturation: 1.0
|
40
|
+
band brightness: 0.5
|
41
|
+
end
|
42
|
+
|
43
|
+
shape :band, 0.5 do # double width band with 0.33' probability
|
44
|
+
hbar size: 0.8, ht: 0.15, brightness: 0.8, alpha: 0.6, hue: -0.1, saturation: 1.0
|
45
|
+
band brightness: 0.5
|
46
|
+
end
|
47
|
+
|
48
|
+
shape :band, 0.08 do # a low probability empty rule used to end recursion
|
49
|
+
end
|
50
|
+
|
51
|
+
shape :band do
|
52
|
+
band y: -0.23
|
53
|
+
end
|
54
|
+
|
55
|
+
shape :band do
|
56
|
+
band y: 0.17
|
57
|
+
end
|
58
|
+
|
59
|
+
shape :band do
|
60
|
+
band y: 0.29
|
61
|
+
end
|
62
|
+
|
63
|
+
shape :band do
|
64
|
+
band y: -0.33
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def setup
|
71
|
+
size 500, 300
|
72
|
+
background 0, 0, 180
|
73
|
+
smooth
|
74
|
+
setup_the_gel
|
75
|
+
draw_it
|
76
|
+
end
|
77
|
+
|
78
|
+
def draw
|
79
|
+
# needed to have a draw loop so we can re-run on mouse click
|
80
|
+
end
|
81
|
+
|
82
|
+
def draw_it
|
83
|
+
@pcr.render :gel, start_x: -50, start_y: height/2,
|
84
|
+
size: height/5, color: [0.7, 0.8, 0.8, 1.0]
|
85
|
+
end
|
86
|
+
|
87
|
+
def mouse_clicked
|
88
|
+
draw_it
|
89
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'cf3'
|
2
|
+
|
3
|
+
load_library 'control_panel'
|
4
|
+
|
5
|
+
attr_accessor :resolution, :panel
|
6
|
+
|
7
|
+
def setup_the_triangle
|
8
|
+
|
9
|
+
@triangle = ContextFree.define do
|
10
|
+
shape :tri do
|
11
|
+
triangle size: 0.5, rotation: PI
|
12
|
+
split do
|
13
|
+
tri size: 0.5, y: -0.578, x: 0,
|
14
|
+
hue: 0.8, saturation: 0.2, brightness: 0.8
|
15
|
+
rewind
|
16
|
+
tri size: 0.5, y: 0.289, x: -0.5, hue: 0.2,
|
17
|
+
saturation: 0.2, brightness: 0.8
|
18
|
+
rewind
|
19
|
+
tri size: 0.5, y: 0.289, x: 0.5, hue: 0.2,
|
20
|
+
saturation: 0.2, brightness: 0.8
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup
|
28
|
+
size 600, 600
|
29
|
+
setup_the_triangle
|
30
|
+
no_stroke
|
31
|
+
color_mode HSB, 1.0
|
32
|
+
smooth
|
33
|
+
@resolution = 5
|
34
|
+
control_panel do |p|
|
35
|
+
p.slider :resolution, (2..50), 5
|
36
|
+
@panel = p
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def draw
|
41
|
+
panel.set_visible(self.visible) # display panel after sketch frame
|
42
|
+
background 0.1
|
43
|
+
@triangle.render :tri, size: height/1.1, color: [0, 0.5, 1], stop_size: @resolution, start_y: height/1.65
|
44
|
+
end
|
data/samples/spiral.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Contributed by Monkstone.
|
2
|
+
|
3
|
+
load_library :cf3
|
4
|
+
|
5
|
+
def setup_the_spiral
|
6
|
+
@spiral = ContextFree.define do
|
7
|
+
|
8
|
+
shape :start do
|
9
|
+
split do
|
10
|
+
star rotation: 240
|
11
|
+
rewind
|
12
|
+
star rotation: 120
|
13
|
+
rewind
|
14
|
+
star rotation: 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
shape :base do
|
19
|
+
triangle hue: 0.5
|
20
|
+
base rotation: 3, size: 0.98, x: 0.09, brightness: 1.01
|
21
|
+
end
|
22
|
+
|
23
|
+
shape :star do
|
24
|
+
split do
|
25
|
+
base brightness: 0.8, rotation: 80
|
26
|
+
rewind
|
27
|
+
base brightness: 0.8, rotation: 40
|
28
|
+
rewind
|
29
|
+
base brightness: 0.8, rotation: 0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def setup
|
37
|
+
size 600, 600
|
38
|
+
setup_the_spiral
|
39
|
+
no_stroke
|
40
|
+
color_mode HSB, 1.0
|
41
|
+
draw_it
|
42
|
+
end
|
43
|
+
|
44
|
+
def draw
|
45
|
+
# Do nothing.
|
46
|
+
end
|
47
|
+
|
48
|
+
def draw_it
|
49
|
+
background 0.33, 0.25, 0.2
|
50
|
+
@spiral.render :start, size: height/5, stop_size: 1,
|
51
|
+
color: [0.35, 0.4, 0.9, 0.25],
|
52
|
+
start_x: width/2, start_y: height/2
|
53
|
+
end
|
data/samples/tree.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# tree.rb by jashkenas
|
2
|
+
# This sketch demonstrates a lil' Ruby DSL for defining
|
3
|
+
# context-free drawings. Each shape rule calls itself by chance.
|
4
|
+
|
5
|
+
require 'cf3'
|
6
|
+
load_library :control_panel
|
7
|
+
|
8
|
+
attr_reader :panel
|
9
|
+
|
10
|
+
def setup_the_trees
|
11
|
+
|
12
|
+
control_panel do |panel|
|
13
|
+
@panel = panel
|
14
|
+
panel.slider :srand, 0..100
|
15
|
+
end
|
16
|
+
|
17
|
+
@tree = ContextFree.define do
|
18
|
+
|
19
|
+
shape :seed do
|
20
|
+
square
|
21
|
+
leaf y: 0 if size < 4.5 && rand < 0.018
|
22
|
+
flower y: 0 if size < 2.0 && rand < 0.02
|
23
|
+
seed y: -1, size: 0.986, rotation: 3, brightness: 0.989
|
24
|
+
end
|
25
|
+
|
26
|
+
shape :seed, 0.1 do
|
27
|
+
square
|
28
|
+
seed flip: true
|
29
|
+
end
|
30
|
+
|
31
|
+
shape :seed, 0.04 do
|
32
|
+
square
|
33
|
+
split do
|
34
|
+
seed flip: true
|
35
|
+
rewind
|
36
|
+
seed size: 0.8, rotation: rand(50), flip: true
|
37
|
+
rewind
|
38
|
+
seed size: 0.8, rotation: rand(50)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
shape :leaf do
|
43
|
+
the_size = rand(25)
|
44
|
+
the_x = [1, 0, 0, 0][rand(4)]
|
45
|
+
circle size: the_size, hue: 0.15, saturation: 1.25, brightness: 1.9, x: the_x, color: [0.95, 0.15]
|
46
|
+
end
|
47
|
+
|
48
|
+
shape :flower do
|
49
|
+
split saturation: 0, brightness: rand(1.3)+4.7, set_width: rand(15)+10, set_height: rand(2)+2 do
|
50
|
+
oval rotation: 0
|
51
|
+
oval rotation: 45
|
52
|
+
oval rotation: 90
|
53
|
+
oval rotation: 135
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def setup
|
61
|
+
size 800, 800
|
62
|
+
setup_the_trees
|
63
|
+
no_stroke
|
64
|
+
smooth
|
65
|
+
frame_rate 5
|
66
|
+
draw_it
|
67
|
+
end
|
68
|
+
|
69
|
+
def draw
|
70
|
+
panel.set_visible(true) if self.visible
|
71
|
+
# Do nothing.
|
72
|
+
end
|
73
|
+
|
74
|
+
def draw_the_background
|
75
|
+
color_mode RGB, 1
|
76
|
+
color = [0.0, 0.0, 0.00]
|
77
|
+
background *color
|
78
|
+
count = height/2
|
79
|
+
push_matrix
|
80
|
+
size = height / count
|
81
|
+
(2*count).times do |i|
|
82
|
+
color[2] = color[2] + (0.07/count)
|
83
|
+
fill *color
|
84
|
+
rect 0, i, width, 1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def draw_it
|
89
|
+
Kernel::srand(@srand) if @srand
|
90
|
+
draw_the_background
|
91
|
+
@tree.render :seed, start_x: width/2, start_y: height+20,
|
92
|
+
size: height/60, color: [0.7, 0.15, 0.8]
|
93
|
+
end
|
94
|
+
|
95
|
+
def mouse_clicked
|
96
|
+
panel.set_visible(true)
|
97
|
+
draw_it
|
98
|
+
end
|