cf3 0.0.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/{CHANGELOG → CHANGELOG.md} +13 -0
  4. data/Gemfile +1 -1
  5. data/README.md +21 -21
  6. data/Rakefile +7 -3
  7. data/bin/cf3samples +4 -4
  8. data/cf3ruby.gemspec +12 -13
  9. data/docs/.sass-cache/cd612fe6616e7f514a2421dc73159618de35b85d/jekyll-theme-cayman.scssc +0 -0
  10. data/docs/.sass-cache/cd612fe6616e7f514a2421dc73159618de35b85d/normalize.scssc +0 -0
  11. data/docs/.sass-cache/cd612fe6616e7f514a2421dc73159618de35b85d/rouge-github.scssc +0 -0
  12. data/docs/.sass-cache/cd612fe6616e7f514a2421dc73159618de35b85d/variables.scssc +0 -0
  13. data/docs/README.md +1 -0
  14. data/docs/_config.yml +31 -0
  15. data/docs/_site/README.md +1 -0
  16. data/docs/_site/about/index.html +52 -0
  17. data/docs/_site/assets/css/style.css +809 -0
  18. data/docs/_site/assets/y.png +0 -0
  19. data/docs/_site/example/index.html +113 -0
  20. data/docs/_site/favicon.ico +0 -0
  21. data/docs/_site/feed.xml +10 -0
  22. data/docs/_site/index.html +51 -0
  23. data/docs/_site/robots.txt +1 -0
  24. data/docs/_site/sitemap.xml +12 -0
  25. data/docs/about.md +14 -0
  26. data/docs/assets/y.png +0 -0
  27. data/docs/example.md +73 -0
  28. data/docs/favicon.ico +0 -0
  29. data/docs/index.md +10 -0
  30. data/lib/cf3/version.rb +1 -1
  31. data/lib/cf3.rb +85 -100
  32. data/samples/Rakefile +30 -0
  33. data/samples/accident.rb +34 -30
  34. data/samples/alhambra.rb +32 -29
  35. data/samples/bar_code.rb +26 -22
  36. data/samples/city.rb +14 -11
  37. data/samples/creature.rb +10 -6
  38. data/samples/dark_star.rb +5 -3
  39. data/samples/data/java_args.txt +1 -2
  40. data/samples/dragon.rb +8 -4
  41. data/samples/escher.rb +115 -116
  42. data/samples/fern.rb +13 -9
  43. data/samples/hex_tube.rb +16 -13
  44. data/samples/isosceles.rb +16 -11
  45. data/samples/levy.rb +5 -2
  46. data/samples/pcr.rb +28 -24
  47. data/samples/rubystar.rb +23 -17
  48. data/samples/sierpinski.rb +15 -11
  49. data/samples/spiral.rb +14 -10
  50. data/samples/star.rb +10 -6
  51. data/samples/tree.rb +20 -17
  52. data/samples/tree4.rb +12 -8
  53. data/samples/vine.rb +11 -7
  54. data/samples/xcross.rb +10 -7
  55. data/samples/y.rb +13 -9
  56. data/test/test_cf3.rb +11 -7
  57. metadata +50 -42
data/samples/levy.rb CHANGED
@@ -17,12 +17,15 @@ def setup_the_levy
17
17
  end
18
18
  end
19
19
 
20
+ def settings
21
+ size 400, 400
22
+ end
20
23
 
21
24
  def setup
22
- size 400, 400
25
+ sketch_title 'Levy Fractal'
23
26
  setup_the_levy
24
27
  draw_it
25
- save_frame("levy.png")
28
+ save_frame(data_path('levy.png'))
26
29
  end
27
30
 
28
31
 
data/samples/pcr.rb CHANGED
@@ -9,23 +9,24 @@ require 'cf3'
9
9
  def setup_the_gel
10
10
  @pcr = ContextFree.define do
11
11
  ############ Begin defining custom terminal, a proportional horizontal bar
12
- class << self
12
+ class << self
13
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
14
+ options = get_shape_values(some_options)
15
+ size = options[:size]
16
+ ht = some_options[:ht] || 0.1 # default hbar width is 0.1
17
+ ratio = ht * 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 * size, -0.5 * ratio, 0.5 * size, 0.5 * ratio)
21
22
  end
22
23
  end
23
24
  ########### End definition of custom terminal 'hbar'
24
-
25
+
25
26
  shape :gel do
26
27
  dna brightness: 1.0
27
28
  end
28
-
29
+
29
30
  shape :dna do
30
31
  split do
31
32
  26.times do
@@ -34,43 +35,46 @@ def setup_the_gel
34
35
  end
35
36
  end
36
37
  end
37
-
38
- shape :band do # narrow band with 0.66' probability
38
+
39
+ shape :band do # narrow band with 0.66' probability
39
40
  hbar size: 0.8, ht: 0.1, brightness: 0.3, alpha: 0.3, hue: 251, saturation: 1.0
40
41
  band brightness: 0.5
41
42
  end
42
-
43
- shape :band, 0.5 do # double width band with 0.33' probability
43
+
44
+ shape :band, 0.5 do # double width band with 0.33' probability
44
45
  hbar size: 0.8, ht: 0.15, brightness: 0.8, alpha: 0.6, hue: -36, saturation: 1.0
45
46
  band brightness: 0.5
46
47
  end
47
-
48
- shape :band, 0.08 do # a low probability empty rule used to end recursion
49
- end
50
-
51
- shape :band do
48
+
49
+ shape :band, 0.08 do # a low probability empty rule used to end recursion
50
+ end
51
+
52
+ shape :band do
52
53
  band y: -0.23
53
54
  end
54
-
55
- shape :band do
55
+
56
+ shape :band do
56
57
  band y: 0.17
57
58
  end
58
-
59
+
59
60
  shape :band do
60
- band y: 0.29
61
+ band y: 0.29
61
62
  end
62
63
 
63
64
  shape :band do
64
- band y: -0.33
65
+ band y: -0.33
65
66
  end
66
67
 
67
68
  end
68
69
  end
69
70
 
70
- def setup
71
+ def settings
71
72
  size 500, 300
73
+ end
74
+
75
+ def setup
76
+ sketch_title 'PCR gel'
72
77
  background 0, 0, 180
73
- smooth
74
78
  setup_the_gel
75
79
  draw_it
76
80
  end
@@ -80,7 +84,7 @@ def draw
80
84
  end
81
85
 
82
86
  def draw_it
83
- @pcr.render :gel, start_x: -50, start_y: height/2,
87
+ @pcr.render :gel, start_x: -50, start_y: height/2,
84
88
  size: height/5, color: [252, 0.8, 0.8, 1.0]
85
89
  end
86
90
 
data/samples/rubystar.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #########################
2
- # rubystar.rb
2
+ # rubystar.rb
3
3
  # Adding two custom "triangle" shapes.
4
4
  # These flat and sharp primitives are
5
5
  # used to make dart and kite shapes (for penrose?)
@@ -10,18 +10,20 @@ PHI = (1 + Math.sqrt(5)) / 2
10
10
 
11
11
  def setup_the_sunstar
12
12
  @hexa = ContextFree.define do
13
- ############ Begin defining custom terminals, as a sharp and flat triangles
13
+ ############ Begin defining custom terminals, as a sharp and flat triangles
14
14
  class << self
15
15
  include Math
16
- define_method(:sharp) do |some_options|
17
- size, options = *self.get_shape_values(some_options)
16
+ define_method(:sharp) do |some_options|
17
+ options = get_shape_values(some_options)
18
+ size = options[:size]
18
19
  rot = options[:rotation]
19
- rotate(rot) if rot # NB: sin(0) = 0, cos(0) = 1
20
+ rotate(rot) if rot # NB: sin(0) = 0, cos(0) = 1
20
21
  @app.triangle(0, 0, size, 0, size * cos(PI/5), size * sin(PI/5))
21
22
  rotate(-rot) if rot
22
23
  end
23
- define_method(:flat) do |some_options|
24
- size, options = *self.get_shape_values(some_options)
24
+ define_method(:flat) do |some_options|
25
+ options = get_shape_values(some_options)
26
+ size = options[:size]
25
27
  rot = options[:rotation]
26
28
  rotate(rot) if rot
27
29
  f = (options[:flip])? -1 : 1 # flip adjustment NB: sin(0) = 0, cos(0) = 1
@@ -30,31 +32,31 @@ def setup_the_sunstar
30
32
  end
31
33
  end
32
34
  ########### End definition of custom terminals 'sharp and flat'
33
- shape :tiling do
35
+ shape :tiling do
34
36
  sun brightness: 0.8
35
37
  star brightness: 0.8, alpha: 0.8
36
38
  tiling size: 1/PHI, brightness: 1.0
37
39
  end
38
-
40
+
39
41
  shape :dart do
40
42
  flat size: 1, color: [65, 0.6, 0.6, 1]
41
43
  flat size: 1, color: [65, 1.0, 1.0, 1], flip: true
42
44
  end
43
-
45
+
44
46
  shape :kite do
45
47
  sharp size: 1, color: [0, 0.6, 0.6, 1]
46
48
  sharp size: 1, color: [0, 1.0, 1.0, 1], rotation: 180, flip: true
47
49
  end
48
-
49
- shape :star do
50
+
51
+ shape :star do
50
52
  split do
51
53
  5.times do |i|
52
- dart rotation: 72 * i
54
+ dart rotation: 72 * i
53
55
  rewind
54
56
  end
55
57
  end
56
58
  end
57
-
59
+
58
60
  shape :sun do
59
61
  split do
60
62
  5.times do |i|
@@ -66,14 +68,18 @@ def setup_the_sunstar
66
68
  end
67
69
  end
68
70
 
69
- def setup
71
+ def settings
70
72
  size 800, 800
73
+ end
74
+
75
+ def setup
76
+ sketch_title 'Ruby Star'
71
77
  background 150, 20, 0, 1
72
78
  setup_the_sunstar
73
79
  draw_it
74
80
  end
75
81
 
76
82
  def draw_it
77
- @hexa.render :tiling, start_x: width/2, start_y: height/2,
78
- size: height
83
+ @hexa.render :tiling, start_x: width/2, start_y: height/2,
84
+ size: height
79
85
  end
@@ -1,42 +1,46 @@
1
- require 'cf3'
1
+ require 'cf3'
2
2
 
3
3
  load_library 'control_panel'
4
4
 
5
5
  attr_accessor :resolution, :panel, :hide
6
6
 
7
- def setup_the_triangle
7
+ def setup_the_triangle
8
8
  @triangle = ContextFree.define do
9
9
  shape :tri do
10
- triangle size: 0.5, rotation: 180
10
+ triangle size: 0.5
11
11
  split do
12
- tri size: 0.5, y: -0.578, x: 0,
12
+ tri size: 0.5, y: -0.578, x: 0,
13
13
  hue: 288, saturation: 0.2, brightness: 0.8
14
14
  rewind
15
- tri size: 0.5, y: 0.289, x: -0.5, hue: 72,
15
+ tri size: 0.5, y: 0.289, x: -0.5, hue: 72,
16
16
  saturation: 0.2, brightness: 0.8
17
17
  rewind
18
- tri size: 0.5, y: 0.289, x: 0.5, hue: 72,
18
+ tri size: 0.5, y: 0.289, x: 0.5, hue: 72,
19
19
  saturation: 0.2, brightness: 0.8
20
20
  end
21
- end
21
+ end
22
22
  end
23
23
  end
24
24
 
25
- def setup
25
+ def settings
26
26
  size 600, 600
27
+ end
28
+
29
+ def setup
30
+ sketch_title 'Sierpinski'
27
31
  setup_the_triangle
28
32
  no_stroke
29
33
  @hide = false
30
34
  @resolution = 5
31
35
  control_panel do |p|
32
- p.look_feel "Metal" # optionall set look and feel
36
+ p.look_feel 'Nimbus' # optional set look and feel
33
37
  p.slider :resolution, (2..50), 5
34
38
  @panel = p
35
39
  end
36
40
  end
37
41
 
38
42
  def draw
39
- unless hide
43
+ unless hide
40
44
  panel.set_visible(true) # display panel after sketch frame
41
45
  @hide = true
42
46
  end
@@ -45,5 +49,5 @@ def draw
45
49
  end
46
50
 
47
51
  def mouse_clicked
48
- @hide = false
52
+ @hide = false
49
53
  end
data/samples/spiral.rb CHANGED
@@ -4,7 +4,7 @@ require 'cf3'
4
4
 
5
5
  def setup_the_spiral
6
6
  @spiral = ContextFree.define do
7
-
7
+
8
8
  shape :start do
9
9
  split do
10
10
  star rotation: 240
@@ -14,14 +14,14 @@ def setup_the_spiral
14
14
  star rotation: 0
15
15
  end
16
16
  end
17
-
17
+
18
18
  shape :base do
19
19
  triangle hue: 180
20
20
  base rotation: 3, size: 0.98, x: 0.09, brightness: 1.01
21
21
  end
22
-
22
+
23
23
  shape :star do
24
- split do
24
+ split do
25
25
  base brightness: 0.8, rotation: 80
26
26
  rewind
27
27
  base brightness: 0.8, rotation: 40
@@ -29,25 +29,29 @@ def setup_the_spiral
29
29
  base brightness: 0.8, rotation: 0
30
30
  end
31
31
  end
32
-
32
+
33
33
  end
34
34
  end
35
-
36
- def setup
35
+
36
+ def settings
37
37
  size 600, 600
38
+ end
39
+
40
+ def setup
41
+ sketch_title 'Spiral'
38
42
  setup_the_spiral
39
43
  no_stroke
40
44
  color_mode HSB, 1.0
41
45
  draw_it
42
46
  end
43
-
47
+
44
48
  def draw
45
49
  # Do nothing.
46
50
  end
47
-
51
+
48
52
  def draw_it
49
53
  background 0.33, 0.25, 0.2
50
54
  @spiral.render :start, size: height/5, stop_size: 1,
51
- color: [0.35, 0.4, 0.9, 0.25],
55
+ color: [0.35, 0.4, 0.9, 0.25],
52
56
  start_x: width/2, start_y: height/2
53
57
  end
data/samples/star.rb CHANGED
@@ -5,10 +5,14 @@ require 'cf3'
5
5
  # from primitive terminals (renders on mouse clicked)
6
6
  ###
7
7
 
8
+ def settings
9
+ size 400, 200
10
+ end
11
+
8
12
  def setup
9
- size 400, 200
13
+ sketch_title 'Star Shapes'
10
14
  @stars = ContextFree.define do
11
-
15
+
12
16
  shape :stars do
13
17
  split do
14
18
  sqstar size: 0.8, x: -1
@@ -16,21 +20,21 @@ def setup
16
20
  trstar x: 1
17
21
  end
18
22
  end
19
-
23
+
20
24
  shape :sqstar do
21
25
  square
22
26
  square rotation: 45
23
27
  end
24
-
28
+
25
29
  shape :trstar do
26
30
  triangle
27
31
  triangle rotation: 180
28
32
  end
29
- end
33
+ end
30
34
  end
31
35
 
32
36
  def draw_it
33
- background 0.2
37
+ background 0.2
34
38
  @stars.render :stars, size: height/2, color: [220, 1, 1, 1]
35
39
  end
36
40
 
data/samples/tree.rb CHANGED
@@ -9,25 +9,25 @@ attr_reader :panel, :hide
9
9
 
10
10
  def setup_the_trees
11
11
  control_panel do |panel|
12
- panel.look_feel "Metal"
13
- panel.slider :srand, 0..100
12
+ panel.look_feel 'Nimbus'
13
+ panel.slider :srand, (0..100), 48.85
14
14
  @panel = panel
15
15
  end
16
-
16
+
17
17
  @tree = ContextFree.define do
18
-
18
+
19
19
  shape :seed do
20
20
  square
21
21
  leaf y: 0 if size < 4.5 && rand < 0.018
22
22
  flower y: 0 if size < 2.0 && rand < 0.02
23
23
  seed y: -1, size: 0.986, rotation: 3, brightness: 0.989
24
24
  end
25
-
25
+
26
26
  shape :seed, 0.1 do
27
27
  square
28
28
  seed flip: true
29
29
  end
30
-
30
+
31
31
  shape :seed, 0.04 do
32
32
  square
33
33
  split do
@@ -38,27 +38,30 @@ def setup_the_trees
38
38
  seed size: 0.8, rotation: rand(50)
39
39
  end
40
40
  end
41
-
41
+
42
42
  shape :leaf do
43
43
  the_size = rand(25)
44
44
  the_x = [1, 0, 0, 0][rand(4)]
45
45
  circle size: the_size, hue: 54, saturation: 1.25, brightness: 0.9, x: the_x
46
46
  end
47
-
47
+
48
48
  shape :flower do
49
- split saturation: 0, brightness: rand(1.3)+4.7, w: rand(15)+10, h: rand(2)+2 do
50
- (0 .. 135).step(45) do |rot|
49
+ split saturation: 0, brightness: rand(1.3..6.0), w: rand(15..25), h: rand(2..4) do
50
+ (0..135).step(45) do |rot|
51
51
  oval rotation: rot
52
- end
52
+ end
53
53
  end
54
- end
55
- end
54
+ end
55
+ end
56
56
  end
57
57
 
58
+ def settings
59
+ size 800, 800
60
+ end
58
61
 
59
62
  def setup
60
- size 800, 800
61
- @hide = true
63
+ sketch_title 'Tree'
64
+ @hide = false
62
65
  setup_the_trees
63
66
  no_stroke
64
67
  frame_rate 5
@@ -74,13 +77,13 @@ end
74
77
  def draw_it
75
78
  Kernel::srand(@srand) if @srand
76
79
  background(color(rand(0 .. 255), rand(0 .. 255), rand(0 .. 255), 255))
77
- @tree.render :seed, start_x: width/2, start_y: height+20,
80
+ @tree.render :seed, start_x: width/2, start_y: height+20,
78
81
  size: height/60, color: [252, 0.15, 0.8, 1]
79
82
  end
80
83
 
81
84
  def mouse_clicked
82
85
  @hide = false
83
- panel.set_visible(true)
86
+ panel.set_visible(true)
84
87
  draw_it
85
88
  @hide = true
86
89
  end