cf3 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f8af1424885f56dc32e59cbde844fceb924a4f9
4
- data.tar.gz: 69c5707acfd748da7428921c2da6a2e085dbbffc
3
+ metadata.gz: 7e17853f9381b6ed49bc8167e843761fa8a14f21
4
+ data.tar.gz: 5dc00b417e9f3bfe81809b418507f30d015fd72c
5
5
  SHA512:
6
- metadata.gz: d4ffc79ae3dbe15ec0df3b529d8e2fb5df121d1074b681a86d2f950754d09d5d1860fb464feb1d684c5308be499396efd3ffd069700d19f53b8db742431d214d
7
- data.tar.gz: 5eca072d46f2571e3524c038c13a1c440d832082c681ccb129baf8d74f093f2160a8222184b6f9a1948d6e3d2e8c11aaef02dc6526bf9faf5ea95ef8875b0419
6
+ metadata.gz: 042745bf5d971d9f3f3d63d55f6ca0a99c1604e888b223ee29e2b6cf062f41cab21b7a6d5170d470a8dcff0dceab6b33e461e38a2d6a2271e7985741a3231c5a
7
+ data.tar.gz: f7bc02c7d7492ebef52e4c29c3ccffbefeb80ee1f42f8e7c8685b7fcd0d289b5c1a89bfccb3be6d28bce80a6a43128c7bd4ecb6c4d7d65e542abbc9fbe116f38
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.0.4 Introduce :w and :h as options to supplement size
2
+ * start support for width and height options (:w, :h)
3
+
4
+
1
5
  v0.0.3 Change to use HSB 360 1 1 1 (ie just like cfdg)
2
6
  * rotation of primitives like shapes now in degrees (vs radians)
3
7
  * examples updated, includes a colorful alhambra design
data/lib/cf3.rb CHANGED
@@ -10,7 +10,7 @@ module Processing
10
10
 
11
11
  attr_accessor :rule, :app, :width, :height
12
12
 
13
- AVAILABLE_OPTIONS = [:x, :y, :rotation, :size, :flip, :color, :hue, :saturation, :brightness, :alpha]
13
+ AVAILABLE_OPTIONS = [:x, :y, :w, :h, :rotation, :size, :flip, :color, :hue, :saturation, :brightness, :alpha]
14
14
  HSB_ORDER = {hue: 0, saturation: 1, brightness: 2, alpha: 3}
15
15
  TRIANGLE_TOP = -1 / Math.sqrt(3)
16
16
  TRIANGLE_BOTTOM = Math.sqrt(3) / 6
@@ -103,8 +103,8 @@ module Processing
103
103
  old_ops[:color] = adjusted
104
104
  when :flip
105
105
  old_ops[key] = !old_ops[key]
106
- when :width, :height
107
- old_ops[key] *= value
106
+ when :w, :h
107
+ old_ops[key] = value * old_ops[:size]
108
108
  when :color
109
109
  old_ops[key] = value
110
110
  else # Used a key that we don't know about or trying to set
@@ -168,7 +168,7 @@ module Processing
168
168
  def render(rule_name, starting_values={})
169
169
  @values = {x: 0, y: 0,
170
170
  rotation: 0, flip: false,
171
- size: 20, width: 20, height: 20,
171
+ size: 20, w: nil, h: nil,
172
172
  start_x: width/2, start_y: height/2,
173
173
  color: [180, 0.5, 0.5, 1],
174
174
  stop_size: 1.5}
@@ -206,9 +206,11 @@ module Processing
206
206
  # methods, but hopefully triangles will be added soon.
207
207
  def square(some_options={})
208
208
  size, options = *get_shape_values(some_options)
209
+ width = options[:w] || options[:size]
210
+ height = options[:h] || options[:size]
209
211
  rot = options[:rotation]
210
212
  @app.rotate(rot) if rot
211
- @app.rect(0, 0, size, size)
213
+ @app.rect(0, 0, width, height)
212
214
  @app.rotate(-rot) if rot
213
215
  end
214
216
 
@@ -229,8 +231,8 @@ module Processing
229
231
 
230
232
  def ellipse(some_options={})
231
233
  size, options = *get_shape_values(some_options)
232
- width = options[:width] || options[:size]
233
- height = options[:height] || options[:size]
234
+ width = options[:w] || options[:size]
235
+ height = options[:h] || options[:size]
234
236
  rot = some_options[:rotation]
235
237
  @app.rotate(rot) if rot
236
238
  @app.oval(options[:x] || 0, options[:y] || 0, width, height)
@@ -1,3 +1,3 @@
1
1
  module Cf3
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,23 +2,25 @@
2
2
 
3
3
  require 'cf3'
4
4
 
5
+ INV_SQRT = 1 / Math.sqrt(2)
6
+
5
7
  def setup_the_dragon
6
8
  @dragon = ContextFree.define do
7
-
9
+
8
10
  shape :start do
9
11
  dragon alpha: 1
10
12
  end
11
-
13
+
12
14
  shape :dragon do
13
15
  square hue: 0, brightness: 0, saturation: 1, alpha: 0.02
14
16
  split do
15
- dragon size: 1/Math.sqrt(2), rotation: -45, x: 0.25, y: 0.25
17
+ dragon size: INV_SQRT, rotation: -45, x: 0.25, y: 0.25
16
18
  rewind
17
- dragon size: 1/Math.sqrt(2), rotation: 135, x: 0.25, y: 0.25
19
+ dragon size: INV_SQRT, rotation: 135, x: 0.25, y: 0.25
18
20
  rewind
19
21
  end
20
22
  end
21
-
23
+
22
24
  end
23
25
  end
24
26
 
@@ -35,6 +37,6 @@ end
35
37
 
36
38
  def draw_it
37
39
  background 255
38
- @dragon.render :start, size: width*0.8, stop_size: 2,
39
- start_x: width/3, start_y: height/3.5
40
+ @dragon.render :start, size: width * 0.8, stop_size: 2,
41
+ start_x: width/3, start_y: height / 3.5
40
42
  end
@@ -3,7 +3,7 @@ require 'cf3'
3
3
  #######################################################
4
4
  # This sketch takes some time to develop, #
5
5
  # clicking the mouse, allows you view current state #
6
- # final state background green #
6
+ # in the final state background will be green #
7
7
  #######################################################
8
8
 
9
9
  def setup_the_fern
@@ -2,25 +2,23 @@ require 'cf3'
2
2
 
3
3
  load_library 'control_panel'
4
4
 
5
- attr_accessor :resolution, :panel
5
+ attr_accessor :resolution, :panel, :hide
6
6
 
7
- def setup_the_triangle
8
-
7
+ def setup_the_triangle
9
8
  @triangle = ContextFree.define do
10
9
  shape :tri do
11
- triangle size: 0.5, rotation: PI
10
+ triangle size: 0.5, rotation: 180
12
11
  split do
13
12
  tri size: 0.5, y: -0.578, x: 0,
14
- hue: 0.8, saturation: 0.2, brightness: 0.8
13
+ hue: 288, saturation: 0.2, brightness: 0.8
15
14
  rewind
16
- tri size: 0.5, y: 0.289, x: -0.5, hue: 0.2,
17
- saturation: 0.2, brightness: 0.8
15
+ tri size: 0.5, y: 0.289, x: -0.5, hue: 72,
16
+ saturation: 0.2, brightness: 0.8
18
17
  rewind
19
- tri size: 0.5, y: 0.289, x: 0.5, hue: 0.2,
20
- saturation: 0.2, brightness: 0.8
18
+ tri size: 0.5, y: 0.289, x: 0.5, hue: 72,
19
+ saturation: 0.2, brightness: 0.8
21
20
  end
22
- end
23
-
21
+ end
24
22
  end
25
23
  end
26
24
 
@@ -28,17 +26,24 @@ def setup
28
26
  size 600, 600
29
27
  setup_the_triangle
30
28
  no_stroke
31
- color_mode HSB, 1.0
32
- smooth
29
+ @hide = false
33
30
  @resolution = 5
34
31
  control_panel do |p|
32
+ p.look_feel "Metal" # optionall set look and feel
35
33
  p.slider :resolution, (2..50), 5
36
34
  @panel = p
37
35
  end
38
36
  end
39
37
 
40
38
  def draw
41
- panel.set_visible(self.visible) # display panel after sketch frame
39
+ unless hide
40
+ panel.set_visible(true) # display panel after sketch frame
41
+ @hide = true
42
+ end
42
43
  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
+ @triangle.render :tri, size: height/1.1, color: [0, 0.5, 1.0, 1.0], stop_size: @resolution, start_y: height/1.65
45
+ end
46
+
47
+ def mouse_clicked
48
+ @hide = false
44
49
  end
@@ -46,11 +46,10 @@ def setup_the_trees
46
46
  end
47
47
 
48
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
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|
51
+ oval rotation: rot
52
+ end
54
53
  end
55
54
  end
56
55
  end
@@ -42,24 +42,23 @@ end
42
42
 
43
43
  def setup
44
44
  size 600, 600
45
- # srand 5 uncomment this to get nice looking tree
46
- smooth
45
+ srand 5 # comment this to get variable tree shape
47
46
  setup_the_tree
48
- background 255 # NB color mode here is "RGB 255", within context free definition
49
- draw_it # the color mode is "HSB 1.0", supports :hue, :saturation, :brightness
50
- # save_frame "/home/tux/tree4.png"
51
47
  end
52
48
 
53
49
  def draw
54
50
  # create a draw loop
55
51
  end
56
52
 
53
+ #####
54
+ # color: [0, 0, 0, 1] even in HSB this should be black, seems to work...
55
+ #####
57
56
  def draw_it
58
- @tree.render :trunk, start_x: width/2, start_y: height * 0.9, stop_size: height/150, size: height/15
57
+ @tree.render :trunk, start_x: width/2, start_y: height * 0.9, stop_size: height/150, size: height/15, color: [0, 0, 0, 1]
59
58
  end
60
59
 
61
60
  def mouse_clicked
62
61
  java.lang.System.gc # might help to reduce runtime stack blow ups, it happens!
63
- background 1
62
+ background 200
64
63
  draw_it
65
64
  end
@@ -0,0 +1,43 @@
1
+ require 'cf3'
2
+ #######
3
+ # Simple example demonstrating rewind
4
+ # also how to make simple composite shapes
5
+ # from primitive terminals (renders on mouse clicked)
6
+ ###
7
+
8
+ def setup
9
+ size 400, 200
10
+ @stars = ContextFree.define do
11
+
12
+ shape :stars do
13
+ split do
14
+ cross size: 0.5, x: -2
15
+ rewind
16
+ plus size: 0.5, x: 2
17
+ end
18
+ end
19
+
20
+ shape :cross do
21
+ square w: 1, h: 3, rotation: -45
22
+ square w: 1, h: 3, rotation: 45
23
+ end
24
+
25
+ shape :plus do
26
+ square w: 1, h: 3
27
+ square w: 1, h: 3, rotation: 90
28
+ end
29
+ end
30
+ end
31
+
32
+ def draw_it
33
+ background 0.2
34
+ @stars.render :stars, size: height/2, color: [220, 1, 1, 1]
35
+ end
36
+
37
+ def draw
38
+ # Do nothing.
39
+ end
40
+
41
+ def mouse_clicked
42
+ draw_it
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-31 00:00:00.000000000 Z
12
+ date: 2013-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-processing
@@ -79,7 +79,6 @@ files:
79
79
  - lib/cf3/version.rb
80
80
  - samples/accident.rb
81
81
  - samples/alhambra.rb
82
- - samples/alhambra2.rb
83
82
  - samples/bar_code.rb
84
83
  - samples/city.rb
85
84
  - samples/creature.rb
@@ -88,7 +87,6 @@ files:
88
87
  - samples/dragon.rb
89
88
  - samples/escher.rb
90
89
  - samples/fern.rb
91
- - samples/grapher.rb
92
90
  - samples/hex_tube.rb
93
91
  - samples/isosceles.rb
94
92
  - samples/levy.rb
@@ -100,6 +98,7 @@ files:
100
98
  - samples/tree.rb
101
99
  - samples/tree4.rb
102
100
  - samples/vine.rb
101
+ - samples/xcross.rb
103
102
  - samples/y.rb
104
103
  - test/test_cf3.rb
105
104
  homepage: http://learning-ruby-processing.blogspot.co.uk/
@@ -1,98 +0,0 @@
1
- require 'cf3'
2
- #############
3
- # to be fixed
4
- #############
5
-
6
- GOLD = [33, 0.967, 0.592, 1]
7
- BLACK = [0, 0.909, 0.129, 1]
8
- GREEN = [148, 0.696, 0.271, 1]
9
- BLUE = [225, 0.777, 0.475, 1]
10
- RED = [17, 0.983, 0.231, 1]
11
- COLORS = [GOLD, BLACK, GREEN, BLUE, RED]
12
-
13
- def setup_the_tiles
14
- @tiles= ContextFree.define do
15
- ############ Begin defining custom terminal, an wavy_triangle triangle
16
- class << self
17
- define_method(:wavy_triangle) do |some_options| # wavy_triangle triangle
18
- size, options = *self.get_shape_values(some_options)
19
- rot = options[:rotation]
20
- disp = 0.32 # could introduce a rule option?
21
- x0 = options[:x]
22
- y0 = options[:y]
23
- pts = Array.new(12)
24
- pts[0] = PVector.new(x0, y0 - size/Math.sqrt(3)) # A
25
- pts[1] = PVector.new(x0 - 0.5 * size, y0 + (Math.sqrt(3)*size)/6) # B
26
- pts[2] = PVector.new(x0 + 0.5 * size, y0 + (Math.sqrt(3)*size)/6) # C
27
- pts[3] = get_mid_point(pts[0], pts[1]) # Ab
28
- pts[4] = get_mid_point(pts[1], pts[2]) # Bc
29
- pts[5] = get_mid_point(pts[0], pts[2]) # Ca
30
- pts[6] = get_mid_point(pts[0], pts[3]) # Aba
31
- adjust_bezier(pts[6], PI/3, disp*size) # Aba
32
- pts[7] = get_mid_point(pts[3], pts[1]) # Abb
33
- adjust_bezier(pts[7], PI/3, -disp*size) # Abb
34
- pts[8] = get_mid_point(pts[1], pts[4])
35
- adjust_bezier(pts[8], PI/2, -disp*size)
36
- pts[9] = get_mid_point(pts[4], pts[2])
37
- adjust_bezier(pts[9], PI/2, disp*size)
38
- pts[10] = get_mid_point(pts[2], pts[5])
39
- adjust_bezier(pts[10], -PI/3, -disp*size)
40
- pts[11] = get_mid_point(pts[5], pts[0])
41
- adjust_bezier(pts[11], -PI/3, disp*size)
42
- rotate(rot) if rot
43
- begin_shape
44
- vertex(pts[0].x, pts[0].y)
45
- bezier_vertex(pts[0].x, pts[0].y, pts[6].x, pts[6].y, pts[3].x, pts[3].y)
46
- bezier_vertex(pts[3].x, pts[3].y, pts[7].x, pts[7].y, pts[1].x, pts[1].y)
47
- bezier_vertex(pts[1].x, pts[1].y, pts[8].x, pts[8].y, pts[4].x, pts[4].y)
48
- bezier_vertex(pts[4].x, pts[4].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[5].x, pts[5].y)
50
- bezier_vertex(pts[5].x, pts[5].y, pts[11].x, pts[11].y, pts[0].x, pts[0].y)
51
- end_shape(CLOSE)
52
- rotate(-rot) if rot
53
- end
54
-
55
- private
56
- def adjust_bezier(base, theta, disp)
57
- base.add(PVector.new(Math.cos(theta)*disp, Math.sin(theta)*disp))
58
- end
59
-
60
- def get_mid_point(a, b)
61
- mid = PVector.add(a, b)
62
- mid.div(2)
63
- return mid
64
- end
65
- end
66
-
67
- ########### End definition of custom terminal 'wavy_triangle' shape
68
- shape :tiles do
69
- 20.times do |i|
70
- 20.times do |j|
71
- split do
72
- wavy_triangle size: 1, x: (i + 0.5 * j%2), y: j * 0.9, color: COLORS[i % 5]
73
- rewind
74
- star size: 0.4, x: (2.5 * i - 1.25 * j%2) +0.4, y: (j * 2.5 * 0.9) + 1.25, color: COLORS[j % 5]
75
- end
76
- end
77
- end
78
- end
79
-
80
- shape :star do
81
- triangle
82
- triangle rotation: 180
83
- end
84
- end
85
- end
86
-
87
- def setup
88
- size 1024, 720
89
- background 255
90
- smooth
91
- setup_the_tiles
92
- draw_it
93
- end
94
-
95
- def draw_it
96
- @tiles.render :tiles, start_x: -200, start_y: 0,
97
- size: height/6
98
- end
@@ -1,47 +0,0 @@
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