cf3 0.0.1

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.
@@ -0,0 +1,85 @@
1
+ #########################
2
+ # bar_code.rb (2 of 5)
3
+ # demonstrates the vbar
4
+ # custom terminal
5
+ #########################
6
+ require 'cf3'
7
+
8
+
9
+ def setup_the_barcode
10
+ @barcode = ContextFree.define do
11
+ ############ Begin defining custom terminal, a proportional vertical bar
12
+ class << self
13
+ define_method(:vbar) do |some_options|
14
+ size, options = *self.get_shape_values(some_options)
15
+ w = some_options[:w]|| 0.1 # default vbar width is 0.1
16
+ ratio = w * size
17
+ rot = options[:rotation]
18
+ rect_mode(CENTER)
19
+ rotate(rot) if rot
20
+ rect(-0.5 * ratio, -0.4 * size, 0.5 * ratio, 0.6 * size)
21
+ rotate(-rot) if rot
22
+ end
23
+ end
24
+ ########### End definition of custom terminal 'vbar'
25
+
26
+ shape :strip do
27
+ 2.times do
28
+ end_bar x: 0.09
29
+ end
30
+ 4.times do
31
+ five x: 0.04
32
+ end
33
+ 2.times do
34
+ end_bar x: 0.09
35
+ end
36
+ end
37
+
38
+ shape :bar, 1 do # wide
39
+ vbar size: 0.8, w: 0.08, brightness: -1
40
+ end
41
+
42
+ shape :bar, 1 do # wide
43
+ vbar size: 0.8, w: 0.06, brightness: -1
44
+ end
45
+
46
+ shape :bar, 1.6 do # narrow
47
+ vbar size: 0.8, w: 0.02, brightness: -1
48
+ end
49
+
50
+ shape :bar, 1.6 do # narrow
51
+ vbar size: 0.8, w: 0.03, brightness: -1
52
+ end
53
+
54
+ shape :end_bar, 1.6 do # narrow extra long
55
+ vbar size: 1, w: 0.03, brightness: -1
56
+ end
57
+
58
+ shape :five do
59
+ 5.times do
60
+ bar x: 0.06
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def setup
67
+ size 350, 200
68
+ text_font(create_font("Dialog.plain", 24), 24)
69
+ background 255, 255, 0
70
+ draw_text
71
+ smooth
72
+ setup_the_barcode
73
+ draw_it
74
+ end
75
+
76
+ def draw_it
77
+ @barcode.render :strip, start_x: 0, start_y: height,
78
+ size: height
79
+ end
80
+
81
+ def draw_text
82
+ code = "23467"
83
+ fill 0
84
+ text code, 40, 80
85
+ end
@@ -0,0 +1,60 @@
1
+ # city.rb after city.cfdg
2
+
3
+ require 'cf3' # NB: requires ruby 1.9 for rand range
4
+
5
+ def setup_the_city
6
+ @city = ContextFree.define do
7
+
8
+ shape :neighborhood do
9
+ split do
10
+ block x: -0.25, y: -0.25
11
+ rewind
12
+ block x: 0.25, y: -0.25
13
+ rewind
14
+ block x: 0.25, y: 0.25
15
+ rewind
16
+ block x: -0.25, y: 0.25
17
+ end
18
+ end
19
+
20
+ shape :block do
21
+ buildings size: 0.85
22
+ end
23
+
24
+ shape :block, 5 do
25
+ neighborhood size: 0.5, rotation: rand(-PI..PI), hue: rand(2), brightness: rand(0.75..1.75)
26
+ end
27
+
28
+ shape :block, 0.1 do
29
+ # Do nothing
30
+ end
31
+
32
+ shape :buildings do
33
+ square
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ def setup
40
+ size 600, 600
41
+ smooth
42
+ setup_the_city
43
+ @background = color 255, 255, 255
44
+ draw_it
45
+ end
46
+
47
+ def draw
48
+ # Do nothing
49
+ end
50
+
51
+ def draw_it
52
+ background @background
53
+ @city.render :neighborhood,
54
+ start_x: width/2, start_y: height/2,
55
+ size: height/2.5, color: [0.1, 0.1, 0.1]
56
+ end
57
+
58
+ def mouse_clicked
59
+ draw_it
60
+ end
@@ -0,0 +1,59 @@
1
+ # contributed by monkstone
2
+
3
+ require 'cf3'
4
+
5
+ def setup_the_creature
6
+ @creature = ContextFree.define do
7
+
8
+ shape :start do
9
+ rot = 0
10
+ split do
11
+ 11.times do # 11 times increment rotation by 30 degrees
12
+ legs rotation: rot
13
+ rot += 30
14
+ rewind # rewind context
15
+ end
16
+ legs rotation: 360
17
+ end
18
+ end
19
+
20
+ shape :legs do
21
+ circle hue: 0.15, saturation: 0.5, brightness: 1.0, color: [0.95, 0.15]
22
+ legs y: 0.1, size: 0.965
23
+ end
24
+
25
+ shape :legs, 0.01 do
26
+ circle
27
+ split do
28
+ legs rotation: 3
29
+ rewind
30
+ legs rotation: -3
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ def setup
38
+ size 600, 600
39
+ setup_the_creature
40
+ no_stroke
41
+ color_mode HSB, 1.0
42
+ smooth
43
+ draw_it
44
+ # save_frame("creature.png")
45
+ end
46
+
47
+ def draw
48
+ # Do nothing.
49
+ end
50
+
51
+ def draw_it
52
+ background -1.0
53
+ @creature.render :start, size: height/5, stop_size: 0.8,
54
+ start_x: width/2, start_y: height/3, color: [0.75, 0.1, 0.9]
55
+ end
56
+
57
+ def mouse_clicked
58
+ draw_it
59
+ end
@@ -0,0 +1,47 @@
1
+ # by Martin Prout
2
+
3
+ require 'cf3'
4
+
5
+ def setup_the_sun
6
+ @sun = ContextFree.define do
7
+
8
+ shape :start do
9
+ rot = 0
10
+ split do
11
+ 12.times do
12
+ legs rotation: rot
13
+ rot += 30
14
+ rewind
15
+ end
16
+ legs rotation: 360
17
+ end
18
+ end
19
+
20
+ shape :legs do
21
+ circle
22
+ legs rotation: 1, y: 0.1,
23
+ size: 0.973, color: [0.22, 0.15]
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ def setup
30
+ size 600, 600
31
+ setup_the_sun
32
+ no_stroke
33
+ color_mode HSB, 1.0
34
+ draw_it
35
+ end
36
+
37
+ def draw
38
+ # Do nothing.
39
+ end
40
+
41
+ def draw_it
42
+ background 0.7
43
+ @sun.render :start, size: height/7, stop_size: 0.8,
44
+ start_x: width/2, start_y: height/2
45
+ end
46
+
47
+
@@ -0,0 +1,2 @@
1
+ -Xmn128m -Xms1024m -Xmx1024m -XX:+OptimizeStringConcat -XX:CompileCommand=dontinline,org.jruby.runtime.invokedynamic.InvokeDynamicSupport::invocationFallback
2
+
@@ -0,0 +1,40 @@
1
+ # by Martin Prout
2
+
3
+ require 'cf3'
4
+
5
+ def setup_the_dragon
6
+ @dragon = ContextFree.define do
7
+
8
+ shape :start do
9
+ dragon alpha: 1
10
+ end
11
+
12
+ shape :dragon do
13
+ square hue: 0, brightness: 0, saturation: 1, alpha: 0.02
14
+ split do
15
+ dragon size: 1/Math.sqrt(2), rotation: -45, x: 0.25, y: 0.25
16
+ rewind
17
+ dragon size: 1/Math.sqrt(2), rotation: 135, x: 0.25, y: 0.25
18
+ rewind
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ def setup
26
+ size 800, 500
27
+ setup_the_dragon
28
+ smooth
29
+ draw_it
30
+ end
31
+
32
+ def draw
33
+ # Do nothing.
34
+ end
35
+
36
+ def draw_it
37
+ background 255
38
+ @dragon.render :start, size: width*0.8, stop_size: 2,
39
+ start_x: width/3, start_y: height/3.5
40
+ end
@@ -0,0 +1,124 @@
1
+ require 'cf3'
2
+
3
+ def setup_the_birds
4
+
5
+
6
+ @birds= ContextFree.define do
7
+
8
+ ############ Begin defining custom terminal, an wavy_triangle triangle
9
+ class << self
10
+ SQRT3 = Math.sqrt(3)
11
+ define_method(:wavy_diamond) do |some_options| # wavy_triangle triangle
12
+ size, options = *self.get_shape_values(some_options)
13
+ rot = options[:rotation]
14
+ x0 = options[:x]
15
+ y0 = options[:y]
16
+ disp = options[:disp]
17
+ col = options[:color]
18
+ pts = Array.new(16)
19
+ pts[0] = PVector.new(x0 - 0.25 * size, y0 - size / SQRT3) # A
20
+ pts[2] = PVector.new(x0 + 0.75 * size, y0 - size / SQRT3) # B
21
+ pts[4] = PVector.new(x0 + 0.25 * size, y0 + (SQRT3 * size) / 6) # C
22
+ pts[6] = PVector.new(x0 - 0.75 * size, y0 + (SQRT3 * size) / 6) # D
23
+ pts[1] = get_mid_point(pts[0], pts[2])#Ab
24
+ pts[3] = get_mid_point(pts[2], pts[4])#Bc
25
+ pts[5] = get_mid_point(pts[4], pts[6])#Cd
26
+ pts[7] = get_mid_point(pts[6], pts[0])#Da
27
+ pts[8] = get_mid_point(pts[0], pts[1])#Aba
28
+ adjust_bezier(pts[8], PI/2, -disp * size)#Aba
29
+ pts[9] = get_mid_point(pts[1], pts[2])
30
+ adjust_bezier(pts[9], PI/2, disp * size)
31
+ pts[10] = get_mid_point(pts[2], pts[3])
32
+ adjust_bezier(pts[10], PI/3, disp * size)
33
+ pts[11] = get_mid_point(pts[3], pts[4])
34
+ adjust_bezier(pts[11], PI/3, -disp * size)
35
+ pts[12] = get_mid_point(pts[4], pts[5])
36
+ adjust_bezier(pts[12], PI/2, disp * size)
37
+ pts[13] = get_mid_point(pts[5], pts[6])
38
+ adjust_bezier(pts[13], PI/2, -disp * size)
39
+ pts[14] = get_mid_point(pts[6], pts[7])
40
+ adjust_bezier(pts[14], PI/3, -disp * size)
41
+ pts[15] = get_mid_point(pts[7], pts[0])
42
+ adjust_bezier(pts[15], PI/3, disp * size)
43
+ rotate(rot) if rot
44
+ fill *col
45
+ begin_shape
46
+ vertex(pts[0].x, pts[0].y)
47
+ bezier_vertex(pts[0].x, pts[0].y, pts[8].x, pts[8].y, pts[1].x, pts[1].y)
48
+ bezier_vertex(pts[1].x, pts[1].y, pts[9].x, pts[9].y, pts[2].x, pts[2].y)
49
+ bezier_vertex(pts[2].x, pts[2].y, pts[10].x, pts[10].y, pts[3].x, pts[3].y)
50
+ bezier_vertex(pts[3].x, pts[3].y, pts[11].x, pts[11].y, pts[4].x, pts[4].y)
51
+ bezier_vertex(pts[4].x, pts[4].y, pts[12].x, pts[12].y, pts[5].x, pts[5].y)
52
+ bezier_vertex(pts[5].x, pts[5].y, pts[13].x, pts[13].y, pts[6].x, pts[6].y)
53
+ bezier_vertex(pts[6].x, pts[6].y, pts[14].x, pts[14].y, pts[7].x, pts[7].y)
54
+ bezier_vertex(pts[7].x, pts[7].y, pts[15].x, pts[15].y, pts[0].x, pts[0].y)
55
+ vertex(pts[0].x, pts[0].y)
56
+ end_shape(CLOSE)
57
+ rotate(-rot) if rot
58
+ end
59
+
60
+ private
61
+ def adjust_bezier(base, theta, disp)
62
+ base.add(PVector.new(Math.cos(theta)*disp, Math.sin(theta)*disp))
63
+ end
64
+
65
+ def get_mid_point(a, b)
66
+ mid = PVector.add(a, b)
67
+ mid.div(2)
68
+ return mid
69
+ end
70
+ end
71
+
72
+ ########### End definition of custom terminal 'wavy_diamond' shape
73
+ shape :birds do
74
+ bird size: 0.1
75
+ split do
76
+ 10.times do |i|
77
+ split do
78
+ 10.times do |j|
79
+ bird size: 1, x: (i * 0.5 + 0.25 * (j%2)), y: j * 0.435
80
+ rewind
81
+ end
82
+ rewind
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ shape :bird do
89
+ wavy_diamond color: [0.7, 1, 1, 1]
90
+ end
91
+
92
+ shape :bird do
93
+ wavy_diamond color: [0.5, 1, 1, 1]
94
+ end
95
+
96
+ shape :bird do
97
+ wavy_diamond color: [0.1, 1, 1, 1]
98
+ end
99
+
100
+ shape :bird do
101
+ wavy_diamond color: [0.2, 1, 1, 1]
102
+ end
103
+
104
+ shape :bird do
105
+ wavy_diamond color: [0.01, 1, 1, 1]
106
+ end
107
+
108
+ end
109
+ end
110
+
111
+ def setup
112
+ size 1000, 800
113
+ setup_the_birds
114
+ draw_it
115
+ end
116
+
117
+ def draw_it
118
+ background 255
119
+ @birds.render :birds, :start_x => 0, :start_y => 0, size: 1000, :disp => 0.32, color: [0, 1, 1, 1]
120
+ end
121
+
122
+ def draw
123
+ # do nothing
124
+ end
@@ -0,0 +1,46 @@
1
+ require 'cf3'
2
+
3
+ def setup_the_fern
4
+
5
+ @fern = ContextFree.define do
6
+
7
+ shape :start do
8
+ fern rotation: 50, hue: 0.8
9
+ end
10
+
11
+ shape :fern do
12
+ circle size: 0.75, rotation: -10
13
+ split do
14
+ fern size: 0.92, y: -2, rotation: -5, hue: 0.85
15
+ rewind
16
+ fern size: 0.5, y: -2, rotation: 90
17
+ rewind
18
+ fern size: 0.5, y: -2, rotation: -90
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ def setup
26
+ size 600, 600
27
+ setup_the_fern
28
+ no_stroke
29
+ color_mode HSB, 1.0
30
+ smooth
31
+ draw_it
32
+ end
33
+
34
+ def draw
35
+ # Do nothing.
36
+ end
37
+
38
+ def draw_it
39
+ background 0.33, 0.25, 0.2
40
+ @fern.render :start, size: height/23, color: [0.35, 0.4, 0.9, 0.55], stop_size: 1,
41
+ start_x: width/2.5, start_y: height/1.285
42
+ end
43
+
44
+ def mouse_clicked
45
+ draw_it
46
+ end