cf3 0.0.5 → 1.0.0
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.
- checksums.yaml +5 -5
- data/CHANGELOG +6 -0
- data/Gemfile +1 -1
- data/README.md +21 -21
- data/Rakefile +6 -2
- data/cf3ruby.gemspec +13 -13
- data/lib/cf3.rb +75 -90
- data/lib/cf3/version.rb +1 -1
- data/samples/Rakefile +30 -0
- data/samples/accident.rb +34 -30
- data/samples/alhambra.rb +32 -29
- data/samples/bar_code.rb +26 -22
- data/samples/city.rb +14 -11
- data/samples/creature.rb +10 -6
- data/samples/dark_star.rb +5 -3
- data/samples/data/java_args.txt +1 -2
- data/samples/dragon.rb +8 -4
- data/samples/escher.rb +115 -116
- data/samples/fern.rb +10 -6
- data/samples/hex_tube.rb +16 -13
- data/samples/isosceles.rb +16 -11
- data/samples/levy.rb +4 -1
- data/samples/pcr.rb +28 -24
- data/samples/rubystar.rb +23 -17
- data/samples/sierpinski.rb +15 -11
- data/samples/spiral.rb +14 -10
- data/samples/star.rb +10 -6
- data/samples/tree.rb +19 -16
- data/samples/tree4.rb +12 -8
- data/samples/vine.rb +11 -7
- data/samples/xcross.rb +10 -7
- data/samples/y.rb +12 -8
- data/test/test_cf3.rb +11 -7
- metadata +23 -20
data/lib/cf3/version.rb
CHANGED
data/samples/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Simple demo Rakefile to autorun samples in current directory
|
2
|
+
# adjust path to k9 executable, and or opts as required
|
3
|
+
|
4
|
+
SAMPLES_DIR = './'
|
5
|
+
|
6
|
+
desc 'run demo'
|
7
|
+
task default: [:demo]
|
8
|
+
|
9
|
+
desc 'demo'
|
10
|
+
task :demo do
|
11
|
+
samples_list.shuffle.each { |sample| run_sample sample }
|
12
|
+
end
|
13
|
+
|
14
|
+
def samples_list
|
15
|
+
files = []
|
16
|
+
Dir.chdir(SAMPLES_DIR)
|
17
|
+
Dir.glob('*.rb').each do |file|
|
18
|
+
files << File.join(SAMPLES_DIR, file)
|
19
|
+
end
|
20
|
+
return files
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_sample(sample_name)
|
24
|
+
puts "Running #{sample_name}...quit to run next sample"
|
25
|
+
open("|k9 -r #{sample_name}", 'r') do |io|
|
26
|
+
while l = io.gets
|
27
|
+
puts(l.chop)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/samples/accident.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
#########################
|
2
|
-
# rubystar.rb
|
2
|
+
# rubystar.rb
|
3
3
|
#########################
|
4
|
-
require 'cf3'
|
4
|
+
require 'cf3'
|
5
5
|
|
6
6
|
PHI = (1 + Math.sqrt(5)) / 2
|
7
7
|
|
8
8
|
def setup_the_sunstar
|
9
9
|
@hexa = ContextFree.define do
|
10
|
-
############ Begin defining custom terminals, as a sharp and flat triangles
|
10
|
+
############ Begin defining custom terminals, as a sharp and flat triangles
|
11
11
|
class << self
|
12
12
|
include Math
|
13
|
-
define_method(:sharp) do |some_options|
|
14
|
-
|
15
|
-
|
13
|
+
define_method(:sharp) do |some_options|
|
14
|
+
options = get_shape_values(some_options)
|
15
|
+
size = options[:size]
|
16
|
+
rot = options[:rotation]
|
16
17
|
#f = (options[:flip])? -1 : 1
|
17
|
-
@app.rotate(rot) if rot
|
18
|
+
@app.rotate(rot) if rot
|
18
19
|
#@app.triangle(0, 0, size * cos(0), size * sin(0), size * cos(PI * f/5), size * sin(PI*f/5))
|
19
20
|
@app.triangle(0, 0, size * cos(0), size * sin(0), size * cos(PI/5), size * sin(PI/5))
|
20
21
|
@app.rotate(-rot) if rot
|
21
22
|
end
|
22
|
-
define_method(:flat) do |some_options|
|
23
|
-
|
23
|
+
define_method(:flat) do |some_options|
|
24
|
+
options = get_shape_values(some_options)
|
25
|
+
size = options[:size]
|
24
26
|
rot = options[:rotation]
|
25
27
|
f = (options[:flip])? -1 : 1 # NB custom flip adjustment
|
26
28
|
@app.triangle(0, 0, size * cos(0), size * sin(0), size/PHI * cos(PI * f/5 ), size/PHI * sin(PI * f/5))
|
@@ -28,51 +30,49 @@ def setup_the_sunstar
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
########### End definition of custom terminals 'sharp and flat'
|
31
|
-
|
33
|
+
|
32
34
|
shape :tiling do
|
33
35
|
outer brightness: 1.0
|
34
36
|
end
|
35
|
-
|
36
|
-
|
37
|
+
|
37
38
|
shape :outer do
|
38
39
|
split do
|
39
|
-
10.times do
|
40
|
+
10.times do
|
40
41
|
sunstar y: sqrt((PHI)** - 0.125), rotation: 36
|
41
42
|
end
|
42
43
|
rewind
|
43
44
|
end
|
44
45
|
outer size: 1/PHI
|
45
|
-
end
|
46
|
-
|
47
|
-
|
46
|
+
end
|
47
|
+
|
48
48
|
shape :sunstar do
|
49
49
|
split do
|
50
|
-
sun brightness: 0.9, alpha: 1.0
|
50
|
+
sun brightness: 0.9, alpha: 1.0
|
51
51
|
rewind
|
52
52
|
star brightness: 0.9, alpha: 0.8
|
53
53
|
rewind
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
shape :dart do
|
58
|
-
flat size: 1, hue: 65, sat: 0.9, brightness: 0.9
|
58
|
+
flat size: 1, hue: 65, sat: 0.9, brightness: 0.9
|
59
59
|
flat size: 1, hue: 65, sat: 1.0, brightness: 1.0, flip: true
|
60
60
|
end
|
61
|
-
|
62
|
-
shape :kite do
|
63
|
-
sharp size: 1, hue: 0, sat: 0.9, brightness: 0.9
|
61
|
+
|
62
|
+
shape :kite do
|
63
|
+
sharp size: 1, hue: 0, sat: 0.9, brightness: 0.9
|
64
64
|
sharp size: 1, hue: 0, sat: 1.0, brightness: 1.0, rotation: 180, flip: true
|
65
65
|
end
|
66
|
-
|
67
|
-
shape :star do
|
66
|
+
|
67
|
+
shape :star do
|
68
68
|
split do
|
69
69
|
5.times do |i|
|
70
|
-
dart rotation: 72 * i
|
70
|
+
dart rotation: 72 * i
|
71
71
|
rewind
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
shape :sun do
|
77
77
|
split do
|
78
78
|
5.times do |i|
|
@@ -84,14 +84,18 @@ def setup_the_sunstar
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
def
|
87
|
+
def settings
|
88
88
|
size 800, 800
|
89
|
-
|
89
|
+
end
|
90
|
+
|
91
|
+
def setup
|
92
|
+
sketch_title 'Accident'
|
93
|
+
background 255
|
90
94
|
setup_the_sunstar
|
91
95
|
draw_it
|
92
96
|
end
|
93
97
|
|
94
98
|
def draw_it
|
95
|
-
@hexa.render :tiling, start_x: width * 0.75, start_y: height/2.64,
|
96
|
-
size: height/6
|
99
|
+
@hexa.render :tiling, start_x: width * 0.75, start_y: height/2.64,
|
100
|
+
size: height/6
|
97
101
|
end
|
data/samples/alhambra.rb
CHANGED
@@ -8,34 +8,36 @@ RED = [17, 0.983, 0.231, 1]
|
|
8
8
|
COLORS = [GOLD, BLACK, GREEN, BLUE, RED]
|
9
9
|
|
10
10
|
def setup_the_tiles
|
11
|
-
@tiles= ContextFree.define do
|
12
|
-
############ Begin defining custom terminal, an wavy_triangle triangle
|
13
|
-
class << self
|
11
|
+
@tiles = ContextFree.define do
|
12
|
+
############ Begin defining custom terminal, an wavy_triangle triangle
|
13
|
+
class << self
|
14
|
+
SQRT3 = Math.sqrt(3)
|
14
15
|
define_method(:wavy_triangle) do |some_options| # wavy_triangle triangle
|
15
|
-
|
16
|
+
options = get_shape_values(some_options)
|
17
|
+
size = options[:size]
|
16
18
|
rot = options[:rotation]
|
17
19
|
disp = 0.32 # could introduce a rule option?
|
18
20
|
x0 = options[:x]
|
19
21
|
y0 = options[:y]
|
20
22
|
pts = Array.new(12)
|
21
|
-
pts[0] =
|
22
|
-
pts[1] =
|
23
|
-
pts[2] =
|
24
|
-
pts[3] = get_mid_point(pts[0], pts[1])
|
25
|
-
pts[4] = get_mid_point(pts[1], pts[2])
|
26
|
-
pts[5] = get_mid_point(pts[0], pts[2])
|
27
|
-
pts[6] = get_mid_point(pts[0], pts[3])
|
28
|
-
|
29
|
-
pts[7] = get_mid_point(pts[3], pts[1])
|
30
|
-
|
23
|
+
pts[0] = Vec2D.new(x0, y0 - size / SQRT3) # A
|
24
|
+
pts[1] = Vec2D.new(x0 - 0.5 * size, y0 + SQRT3 * size / 6) # B
|
25
|
+
pts[2] = Vec2D.new(x0 + 0.5 * size, y0 + SQRT3 * size / 6) # C
|
26
|
+
pts[3] = get_mid_point(pts[0], pts[1]) # Ab
|
27
|
+
pts[4] = get_mid_point(pts[1], pts[2]) # Bc
|
28
|
+
pts[5] = get_mid_point(pts[0], pts[2]) # Ca
|
29
|
+
pts[6] = get_mid_point(pts[0], pts[3]) # Aba
|
30
|
+
pts[6] += adjust_bezier(PI/3, disp * size) # Aba
|
31
|
+
pts[7] = get_mid_point(pts[3], pts[1]) # Abb
|
32
|
+
pts[7] += adjust_bezier(PI/3, -disp * size) # Abb
|
31
33
|
pts[8] = get_mid_point(pts[1], pts[4])
|
32
|
-
|
34
|
+
pts[8] += adjust_bezier(PI/2, -disp * size)
|
33
35
|
pts[9] = get_mid_point(pts[4], pts[2])
|
34
|
-
|
36
|
+
pts[9] += adjust_bezier(PI/2, disp * size)
|
35
37
|
pts[10] = get_mid_point(pts[2], pts[5])
|
36
|
-
|
38
|
+
pts[10] += adjust_bezier(-PI/3, -disp * size)
|
37
39
|
pts[11] = get_mid_point(pts[5], pts[0])
|
38
|
-
|
40
|
+
pts[11] += adjust_bezier(-PI/3, disp * size)
|
39
41
|
rotate(rot) if rot
|
40
42
|
begin_shape
|
41
43
|
vertex(pts[0].x, pts[0].y)
|
@@ -45,22 +47,20 @@ def setup_the_tiles
|
|
45
47
|
bezier_vertex(pts[4].x, pts[4].y, pts[9].x, pts[9].y, pts[2].x, pts[2].y)
|
46
48
|
bezier_vertex(pts[2].x, pts[2].y, pts[10].x, pts[10].y, pts[5].x, pts[5].y)
|
47
49
|
bezier_vertex(pts[5].x, pts[5].y, pts[11].x, pts[11].y, pts[0].x, pts[0].y)
|
48
|
-
end_shape(CLOSE)
|
50
|
+
end_shape(CLOSE)
|
49
51
|
rotate(-rot) if rot
|
50
52
|
end
|
51
|
-
|
53
|
+
|
52
54
|
private
|
53
|
-
def adjust_bezier(
|
54
|
-
|
55
|
+
def adjust_bezier(theta, disp)
|
56
|
+
Vec2D.new(Math.cos(theta) * disp, Math.sin(theta) * disp)
|
55
57
|
end
|
56
|
-
|
58
|
+
|
57
59
|
def get_mid_point(a, b)
|
58
|
-
|
59
|
-
mid.div(2)
|
60
|
-
return mid
|
60
|
+
(a + b) / 2.0
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
########### End definition of custom terminal 'wavy_triangle' shape
|
65
65
|
shape :tiles do
|
66
66
|
20.times do |i|
|
@@ -72,10 +72,13 @@ def setup_the_tiles
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def
|
75
|
+
def settings
|
76
76
|
size 1024, 720
|
77
|
+
end
|
78
|
+
|
79
|
+
def setup
|
80
|
+
sketch_title 'Alhambra Tiling'
|
77
81
|
background 255
|
78
|
-
smooth
|
79
82
|
setup_the_tiles
|
80
83
|
draw_it
|
81
84
|
end
|
data/samples/bar_code.rb
CHANGED
@@ -9,77 +9,81 @@ require 'cf3'
|
|
9
9
|
def setup_the_barcode
|
10
10
|
@barcode = ContextFree.define do
|
11
11
|
############ Begin defining custom terminal, a proportional vertical bar
|
12
|
-
class << self
|
13
|
-
define_method(:vbar) do |some_options|
|
14
|
-
|
12
|
+
class << self
|
13
|
+
define_method(:vbar) do |some_options|
|
14
|
+
options = self.get_shape_values(some_options)
|
15
|
+
size = options[:size]
|
15
16
|
w = some_options[:w]|| 0.1 # default vbar width is 0.1
|
16
|
-
ratio = w * size
|
17
|
+
ratio = w * size
|
17
18
|
rot = options[:rotation]
|
18
19
|
rect_mode(CENTER)
|
19
|
-
rotate(rot) if rot
|
20
|
+
rotate(rot) if rot
|
20
21
|
rect(-0.5 * ratio, -0.4 * size, 0.5 * ratio, 0.6 * size)
|
21
22
|
rotate(-rot) if rot
|
22
|
-
end
|
23
|
+
end
|
23
24
|
end
|
24
25
|
########### End definition of custom terminal 'vbar'
|
25
|
-
|
26
|
+
|
26
27
|
shape :strip do
|
27
28
|
2.times do
|
28
|
-
end_bar x: 0.09
|
29
|
-
end
|
29
|
+
end_bar x: 0.09
|
30
|
+
end
|
30
31
|
4.times do
|
31
32
|
five x: 0.04
|
32
33
|
end
|
33
34
|
2.times do
|
34
35
|
end_bar x: 0.09
|
35
|
-
end
|
36
|
+
end
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
shape :bar, 1 do # wide
|
39
40
|
vbar size: 0.8, w: 0.08, brightness: -1
|
40
41
|
end
|
41
|
-
|
42
|
+
|
42
43
|
shape :bar, 1 do # wide
|
43
44
|
vbar size: 0.8, w: 0.06, brightness: -1
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
shape :bar, 1.6 do # narrow
|
47
48
|
vbar size: 0.8, w: 0.02, brightness: -1
|
48
49
|
end
|
49
|
-
|
50
|
+
|
50
51
|
shape :bar, 1.6 do # narrow
|
51
52
|
vbar size: 0.8, w: 0.03, brightness: -1
|
52
53
|
end
|
53
|
-
|
54
|
+
|
54
55
|
shape :end_bar, 1.6 do # narrow extra long
|
55
56
|
vbar size: 1, w: 0.03, brightness: -1
|
56
57
|
end
|
57
58
|
|
58
59
|
shape :five do
|
59
60
|
5.times do
|
60
|
-
|
61
|
-
|
62
|
-
end
|
61
|
+
bar x: 0.06
|
62
|
+
end
|
63
63
|
end
|
64
64
|
end
|
65
|
+
end
|
65
66
|
|
66
|
-
def
|
67
|
+
def settings
|
67
68
|
size 350, 200
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup
|
72
|
+
sketch_title 'Bar Code'
|
68
73
|
text_font(create_font("Dialog.plain", 24), 24)
|
69
74
|
background 255, 255, 0
|
70
75
|
draw_text
|
71
|
-
smooth
|
72
76
|
setup_the_barcode
|
73
77
|
draw_it
|
74
78
|
end
|
75
79
|
|
76
80
|
def draw_it
|
77
|
-
@barcode.render :strip, start_x: 0, start_y: height,
|
81
|
+
@barcode.render :strip, start_x: 0, start_y: height,
|
78
82
|
size: height
|
79
83
|
end
|
80
84
|
|
81
85
|
def draw_text
|
82
|
-
code = "23467"
|
86
|
+
code = "23467"
|
83
87
|
fill 0
|
84
88
|
text code, 40, 80
|
85
89
|
end
|
data/samples/city.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# city.rb after city.cfdg
|
2
2
|
|
3
|
-
require 'cf3'
|
3
|
+
require 'cf3'
|
4
4
|
|
5
5
|
def setup_the_city
|
6
6
|
@city = ContextFree.define do
|
7
|
-
|
7
|
+
|
8
8
|
shape :neighborhood do
|
9
9
|
split do
|
10
10
|
block x: -0.25, y: -0.25
|
@@ -16,29 +16,32 @@ def setup_the_city
|
|
16
16
|
block x: -0.25, y: 0.25
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
shape :block do
|
21
21
|
buildings size: 0.85
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
shape :block, 5 do
|
25
25
|
neighborhood size: 0.5, rotation: rand(-PI..PI), hue: rand(2), brightness: rand(0.75..1.75)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
shape :block, 0.1 do
|
29
29
|
# Do nothing
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
shape :buildings do
|
33
33
|
square
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def settings
|
40
40
|
size 600, 600
|
41
|
-
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup
|
44
|
+
sketch_title 'City'
|
42
45
|
setup_the_city
|
43
46
|
@background = color 255, 255, 255
|
44
47
|
draw_it
|
@@ -50,8 +53,8 @@ end
|
|
50
53
|
|
51
54
|
def draw_it
|
52
55
|
background @background
|
53
|
-
@city.render :neighborhood,
|
54
|
-
start_x: width/2, start_y: height/2,
|
56
|
+
@city.render :neighborhood,
|
57
|
+
start_x: width/2, start_y: height/2,
|
55
58
|
size: height/2.5, color: [0.1, 0.1, 0.1]
|
56
59
|
end
|
57
60
|
|
data/samples/creature.rb
CHANGED
@@ -4,7 +4,7 @@ require 'cf3'
|
|
4
4
|
|
5
5
|
def setup_the_creature
|
6
6
|
@creature = ContextFree.define do
|
7
|
-
|
7
|
+
|
8
8
|
shape :start do
|
9
9
|
rot = 0
|
10
10
|
split do
|
@@ -16,26 +16,30 @@ def setup_the_creature
|
|
16
16
|
legs rotation: 360
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
shape :legs do
|
21
21
|
circle hue: 54, saturation: 0.5, brightness: 1.0
|
22
22
|
legs y: 0.1, size: 0.96
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
shape :legs, 0.01 do
|
26
26
|
circle
|
27
27
|
split do
|
28
|
-
legs rotation: 3
|
28
|
+
legs rotation: 3
|
29
29
|
rewind
|
30
30
|
legs rotation: -3
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def settings
|
38
38
|
size 600, 600
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup
|
42
|
+
sketch_title 'Creature'
|
39
43
|
setup_the_creature
|
40
44
|
no_stroke
|
41
45
|
end
|