cf3 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -0
- data/README.md +12 -9
- data/lib/cf3.rb +14 -11
- data/lib/cf3/version.rb +1 -1
- data/samples/accident.rb +8 -9
- data/samples/alhambra.rb +13 -6
- data/samples/alhambra2.rb +98 -0
- data/samples/creature.rb +4 -8
- data/samples/data/java_args.txt +1 -1
- data/samples/escher.rb +3 -3
- data/samples/fern.rb +10 -7
- data/samples/hex_tube.rb +1 -1
- data/samples/pcr.rb +3 -3
- data/samples/rubystar.rb +79 -0
- data/samples/spiral.rb +3 -3
- data/samples/star.rb +43 -0
- data/samples/tree.rb +11 -22
- data/samples/vine.rb +2 -5
- data/test/test_cf3.rb +3 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f8af1424885f56dc32e59cbde844fceb924a4f9
|
4
|
+
data.tar.gz: 69c5707acfd748da7428921c2da6a2e085dbbffc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ffc79ae3dbe15ec0df3b529d8e2fb5df121d1074b681a86d2f950754d09d5d1860fb464feb1d684c5308be499396efd3ffd069700d19f53b8db742431d214d
|
7
|
+
data.tar.gz: 5eca072d46f2571e3524c038c13a1c440d832082c681ccb129baf8d74f093f2160a8222184b6f9a1948d6e3d2e8c11aaef02dc6526bf9faf5ea95ef8875b0419
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.0.3 Change to use HSB 360 1 1 1 (ie just like cfdg)
|
2
|
+
* rotation of primitives like shapes now in degrees (vs radians)
|
3
|
+
* examples updated, includes a colorful alhambra design
|
4
|
+
|
5
|
+
|
1
6
|
v0.0.2 Second Gem Release
|
2
7
|
* extract samples to cf3work/samples, was cf3samples/samples
|
3
8
|
* gives me an opportunity to create a lock for bundler?
|
data/README.md
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
**context-free DSL for ruby-1.9 and CF3 syntax**
|
4
4
|
|
5
|
-
Very much derived from [context-free.rb][] by Jeremy Ashkenas this version is updated to be more in line with CF3 and ruby 1.9 syntax. Tested as working with last rubygems release of ruby-processing (v 1.0.11) as well as the current [version][] (v 2.1.
|
5
|
+
Very much derived from [context-free.rb][] by Jeremy Ashkenas this version is updated to be more in line with CF3 and ruby 1.9 syntax. Tested as working with last rubygems release of ruby-processing (v 1.0.11) as well as the current [version][] (v 2.1.4).
|
6
6
|
[context-free.rb]:https://github.com/jashkenas/context_free/
|
7
7
|
[version]:https://github.com/monkstone/ruby-processing/releases/
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
To use this library you need install jruby (preferably jruby-1.7.4+), you will also need [ruby-processing][] to be installed (minimum version 1.0.11, preferred version 2.1.
|
10
|
+
To use this library you need install jruby (preferably jruby-1.7.4+), you will also need [ruby-processing][] to be installed (minimum version 1.0.11, preferred version 2.1.4). There are three ways you can install this library:-
|
11
11
|
|
12
12
|
***rake test and gem install***
|
13
13
|
|
@@ -16,7 +16,7 @@ Either clone this repository, or download a [snapshot][].
|
|
16
16
|
```bash
|
17
17
|
cd cf3ruby
|
18
18
|
jruby -S rake test # builds and tests gem (mouse click on frame for test image to show)
|
19
|
-
jruby -S gem install cf3-0.0.
|
19
|
+
jruby -S gem install cf3-0.0.3.gem # may need sudo access
|
20
20
|
```
|
21
21
|
|
22
22
|
***local bundle install***
|
@@ -25,25 +25,28 @@ Either clone this repository, or download a [snapshot].
|
|
25
25
|
|
26
26
|
```bash
|
27
27
|
cd cf3
|
28
|
-
bundle install
|
28
|
+
bundle install # using regular installed bundler may need to set GEM_PATH
|
29
|
+
jruby -S bundle install # if you installed bundler with jruby
|
29
30
|
```
|
30
31
|
|
31
32
|
***gem install from rubygems***
|
32
33
|
```bash
|
33
|
-
gem install cf3
|
34
|
+
gem install cf3 # regular install may need to set GEM_PATH env variable
|
35
|
+
jruby -S gem install cf3 # jruby install
|
34
36
|
```
|
35
37
|
it couldn't be easier could it?
|
36
38
|
|
37
39
|
## Usage
|
38
40
|
|
39
|
-
Extract the included samples to your home directory
|
41
|
+
Extract the included samples to your home directory (HOME/cf3work/samples)
|
40
42
|
```bash
|
41
|
-
|
43
|
+
cf3samples # should work
|
44
|
+
jruby -S cf3samples # else if installed with jruby this should also work
|
42
45
|
```
|
43
46
|
|
44
|
-
As for running ruby-processing,
|
47
|
+
As for running ruby-processing, ( _it requires the external jruby flag prior to ruby-processing-2.1.2_ )
|
45
48
|
```bash
|
46
|
-
rp5 run
|
49
|
+
rp5 run city.rb # providing you installed both ruby-processing and cf3ruby using jruby
|
47
50
|
|
48
51
|
```
|
49
52
|
You should read the [ruby-processing_documentation][] on using rubygems.
|
data/lib/cf3.rb
CHANGED
@@ -14,7 +14,7 @@ module Processing
|
|
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
|
17
|
-
|
17
|
+
RADIANS = (Math::PI / 180.0)
|
18
18
|
# Define a context-free system. Use this method to create a ContextFree
|
19
19
|
# object. Call render() on it to make it draw.
|
20
20
|
def self.define(&block)
|
@@ -96,7 +96,7 @@ module Processing
|
|
96
96
|
when :x, :y
|
97
97
|
old_ops[key] = value * old_ops[:size]
|
98
98
|
when :rotation
|
99
|
-
old_ops[key] = value *
|
99
|
+
old_ops[key] = value * RADIANS
|
100
100
|
when :hue, :saturation, :brightness, :alpha
|
101
101
|
adjusted = old_ops[:color].dup
|
102
102
|
adjusted[HSB_ORDER[key]] *= value
|
@@ -170,7 +170,7 @@ module Processing
|
|
170
170
|
rotation: 0, flip: false,
|
171
171
|
size: 20, width: 20, height: 20,
|
172
172
|
start_x: width/2, start_y: height/2,
|
173
|
-
color: [
|
173
|
+
color: [180, 0.5, 0.5, 1],
|
174
174
|
stop_size: 1.5}
|
175
175
|
@values.merge!(starting_values)
|
176
176
|
@finished = false
|
@@ -178,7 +178,7 @@ module Processing
|
|
178
178
|
@app.rect_mode CENTER
|
179
179
|
@app.ellipse_mode CENTER
|
180
180
|
@app.no_stroke
|
181
|
-
@app.color_mode HSB, 1.0
|
181
|
+
@app.color_mode HSB, 360, 1.0, 1.0, 1.0 # match cfdg
|
182
182
|
@app.translate @values[:start_x], @values[:start_y]
|
183
183
|
self.send(rule_name, {})
|
184
184
|
end
|
@@ -204,32 +204,35 @@ module Processing
|
|
204
204
|
|
205
205
|
# Square, circle, and ellipse are the primitive drawing
|
206
206
|
# methods, but hopefully triangles will be added soon.
|
207
|
-
def square(some_options=
|
207
|
+
def square(some_options={})
|
208
208
|
size, options = *get_shape_values(some_options)
|
209
|
+
rot = options[:rotation]
|
210
|
+
@app.rotate(rot) if rot
|
209
211
|
@app.rect(0, 0, size, size)
|
212
|
+
@app.rotate(-rot) if rot
|
210
213
|
end
|
211
214
|
|
212
215
|
|
213
|
-
def circle(some_options=
|
216
|
+
def circle(some_options={})
|
214
217
|
size, options = *get_shape_values(some_options)
|
215
218
|
@app.ellipse(0, 0, size, size)
|
216
219
|
end
|
217
220
|
|
218
|
-
def triangle(some_options=
|
219
|
-
rot = some_options[:rotation]
|
220
|
-
@app.rotate(rot) if rot
|
221
|
+
def triangle(some_options={})
|
221
222
|
size, options = *get_shape_values(some_options)
|
223
|
+
rot = options[:rotation]
|
224
|
+
@app.rotate(rot) if rot
|
222
225
|
@app.triangle(0, TRIANGLE_TOP * size, 0.5 * size, TRIANGLE_BOTTOM * size, -0.5 * size, TRIANGLE_BOTTOM * size)
|
223
226
|
@app.rotate(-rot) if rot
|
224
227
|
end
|
225
228
|
|
226
229
|
|
227
230
|
def ellipse(some_options={})
|
228
|
-
rot = some_options[:rotation]
|
229
|
-
@app.rotate(rot) if rot
|
230
231
|
size, options = *get_shape_values(some_options)
|
231
232
|
width = options[:width] || options[:size]
|
232
233
|
height = options[:height] || options[:size]
|
234
|
+
rot = some_options[:rotation]
|
235
|
+
@app.rotate(rot) if rot
|
233
236
|
@app.oval(options[:x] || 0, options[:y] || 0, width, height)
|
234
237
|
@app.rotate(-rot) if rot
|
235
238
|
end
|
data/lib/cf3/version.rb
CHANGED
data/samples/accident.rb
CHANGED
@@ -47,21 +47,21 @@ def setup_the_sunstar
|
|
47
47
|
|
48
48
|
shape :sunstar do
|
49
49
|
split do
|
50
|
-
sun brightness: 0.
|
50
|
+
sun brightness: 0.9, alpha: 1.0
|
51
51
|
rewind
|
52
|
-
star brightness: 0.
|
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,
|
59
|
-
flat size: 1,
|
58
|
+
flat size: 1, hue: 65, sat: 0.9, brightness: 0.9
|
59
|
+
flat size: 1, hue: 65, sat: 1.0, brightness: 1.0, flip: true
|
60
60
|
end
|
61
61
|
|
62
62
|
shape :kite do
|
63
|
-
sharp size: 1,
|
64
|
-
sharp size: 1,
|
63
|
+
sharp size: 1, hue: 0, sat: 0.9, brightness: 0.9
|
64
|
+
sharp size: 1, hue: 0, sat: 1.0, brightness: 1.0, rotation: 180, flip: true
|
65
65
|
end
|
66
66
|
|
67
67
|
shape :star do
|
@@ -85,9 +85,8 @@ def setup_the_sunstar
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def setup
|
88
|
-
size 800,
|
89
|
-
background
|
90
|
-
smooth
|
88
|
+
size 800, 800
|
89
|
+
background 255
|
91
90
|
setup_the_sunstar
|
92
91
|
draw_it
|
93
92
|
end
|
data/samples/alhambra.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require 'cf3'
|
2
2
|
|
3
|
+
GOLD = [33, 0.967, 0.592, 1]
|
4
|
+
BLACK = [0, 0.909, 0.129, 1]
|
5
|
+
GREEN = [148, 0.696, 0.271, 1]
|
6
|
+
BLUE = [225, 0.777, 0.475, 1]
|
7
|
+
RED = [17, 0.983, 0.231, 1]
|
8
|
+
COLORS = [GOLD, BLACK, GREEN, BLUE, RED]
|
9
|
+
|
3
10
|
def setup_the_tiles
|
4
11
|
@tiles= ContextFree.define do
|
5
12
|
############ Begin defining custom terminal, an wavy_triangle triangle
|
@@ -56,9 +63,9 @@ def setup_the_tiles
|
|
56
63
|
|
57
64
|
########### End definition of custom terminal 'wavy_triangle' shape
|
58
65
|
shape :tiles do
|
59
|
-
|
60
|
-
|
61
|
-
wavy_triangle size: 1, x: (i + 0.5 * j%2), y: j * 0.9
|
66
|
+
20.times do |i|
|
67
|
+
20.times do |j|
|
68
|
+
wavy_triangle size: 1, x: (i + 0.5 * j%2), y: j * 0.9, color: COLORS[i % 5]
|
62
69
|
end
|
63
70
|
end
|
64
71
|
end
|
@@ -66,7 +73,7 @@ def setup_the_tiles
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def setup
|
69
|
-
size
|
76
|
+
size 1024, 720
|
70
77
|
background 255
|
71
78
|
smooth
|
72
79
|
setup_the_tiles
|
@@ -74,6 +81,6 @@ def setup
|
|
74
81
|
end
|
75
82
|
|
76
83
|
def draw_it
|
77
|
-
@tiles.render :tiles, start_x: -
|
78
|
-
size: height/6
|
84
|
+
@tiles.render :tiles, start_x: -200, start_y: 0,
|
85
|
+
size: height/6
|
79
86
|
end
|
@@ -0,0 +1,98 @@
|
|
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
|
data/samples/creature.rb
CHANGED
@@ -18,8 +18,8 @@ def setup_the_creature
|
|
18
18
|
end
|
19
19
|
|
20
20
|
shape :legs do
|
21
|
-
circle hue:
|
22
|
-
legs y: 0.1, size: 0.
|
21
|
+
circle hue: 54, saturation: 0.5, brightness: 1.0
|
22
|
+
legs y: 0.1, size: 0.96
|
23
23
|
end
|
24
24
|
|
25
25
|
shape :legs, 0.01 do
|
@@ -38,10 +38,6 @@ def setup
|
|
38
38
|
size 600, 600
|
39
39
|
setup_the_creature
|
40
40
|
no_stroke
|
41
|
-
color_mode HSB, 1.0
|
42
|
-
smooth
|
43
|
-
draw_it
|
44
|
-
# save_frame("creature.png")
|
45
41
|
end
|
46
42
|
|
47
43
|
def draw
|
@@ -49,9 +45,9 @@ def draw
|
|
49
45
|
end
|
50
46
|
|
51
47
|
def draw_it
|
52
|
-
background
|
48
|
+
background 0
|
53
49
|
@creature.render :start, size: height/5, stop_size: 0.8,
|
54
|
-
start_x: width/2, start_y: height/3
|
50
|
+
start_x: width/2, start_y: height/3
|
55
51
|
end
|
56
52
|
|
57
53
|
def mouse_clicked
|
data/samples/data/java_args.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
-Xmn128m -
|
1
|
+
-Xmn128m -Xms512m -Xmx512m -XX:+OptimizeStringConcat -XX:CompileCommand=dontinline,org.jruby.runtime.invokedynamic.InvokeDynamicSupport::invocationFallback
|
2
2
|
|
data/samples/escher.rb
CHANGED
@@ -86,15 +86,15 @@ def setup_the_birds
|
|
86
86
|
end
|
87
87
|
|
88
88
|
shape :bird do
|
89
|
-
wavy_diamond color: [
|
89
|
+
wavy_diamond color: [38, 1, 1, 1]
|
90
90
|
end
|
91
91
|
|
92
92
|
shape :bird do
|
93
|
-
wavy_diamond color: [
|
93
|
+
wavy_diamond color: [180, 1, 1, 1]
|
94
94
|
end
|
95
95
|
|
96
96
|
shape :bird do
|
97
|
-
wavy_diamond color: [
|
97
|
+
wavy_diamond color: [36, 1, 1, 1]
|
98
98
|
end
|
99
99
|
|
100
100
|
shape :bird do
|
data/samples/fern.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
require 'cf3'
|
2
2
|
|
3
|
+
#######################################################
|
4
|
+
# This sketch takes some time to develop, #
|
5
|
+
# clicking the mouse, allows you view current state #
|
6
|
+
# final state background green #
|
7
|
+
#######################################################
|
8
|
+
|
3
9
|
def setup_the_fern
|
4
10
|
|
5
11
|
@fern = ContextFree.define do
|
6
12
|
|
7
13
|
shape :start do
|
8
|
-
fern rotation: 50, hue:
|
14
|
+
fern rotation: 50, hue: 306
|
9
15
|
end
|
10
16
|
|
11
17
|
shape :fern do
|
12
18
|
circle size: 0.75, rotation: -10
|
13
19
|
split do
|
14
|
-
fern size: 0.92, y: -2, rotation: -5, hue:
|
20
|
+
fern size: 0.92, y: -2, rotation: -5, hue: 306
|
15
21
|
rewind
|
16
22
|
fern size: 0.5, y: -2, rotation: 90
|
17
23
|
rewind
|
@@ -26,9 +32,6 @@ def setup
|
|
26
32
|
size 600, 600
|
27
33
|
setup_the_fern
|
28
34
|
no_stroke
|
29
|
-
color_mode HSB, 1.0
|
30
|
-
smooth
|
31
|
-
draw_it
|
32
35
|
end
|
33
36
|
|
34
37
|
def draw
|
@@ -36,8 +39,8 @@ def draw
|
|
36
39
|
end
|
37
40
|
|
38
41
|
def draw_it
|
39
|
-
background
|
40
|
-
@fern.render :start, size: height/23, color: [
|
42
|
+
background 119, 0.25, 0.2, 1.0
|
43
|
+
@fern.render :start, size: height/23, color: [126, 0.4, 0.9, 0.55], stop_size: 1,
|
41
44
|
start_x: width/2.5, start_y: height/1.285
|
42
45
|
end
|
43
46
|
|
data/samples/hex_tube.rb
CHANGED
data/samples/pcr.rb
CHANGED
@@ -36,12 +36,12 @@ def setup_the_gel
|
|
36
36
|
end
|
37
37
|
|
38
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:
|
39
|
+
hbar size: 0.8, ht: 0.1, brightness: 0.3, alpha: 0.3, hue: 251, saturation: 1.0
|
40
40
|
band brightness: 0.5
|
41
41
|
end
|
42
42
|
|
43
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: -
|
44
|
+
hbar size: 0.8, ht: 0.15, brightness: 0.8, alpha: 0.6, hue: -36, saturation: 1.0
|
45
45
|
band brightness: 0.5
|
46
46
|
end
|
47
47
|
|
@@ -81,7 +81,7 @@ end
|
|
81
81
|
|
82
82
|
def draw_it
|
83
83
|
@pcr.render :gel, start_x: -50, start_y: height/2,
|
84
|
-
size: height/5, color: [
|
84
|
+
size: height/5, color: [252, 0.8, 0.8, 1.0]
|
85
85
|
end
|
86
86
|
|
87
87
|
def mouse_clicked
|
data/samples/rubystar.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#########################
|
2
|
+
# rubystar.rb
|
3
|
+
# Adding two custom "triangle" shapes.
|
4
|
+
# These flat and sharp primitives are
|
5
|
+
# used to make dart and kite shapes (for penrose?)
|
6
|
+
#########################
|
7
|
+
require 'cf3'
|
8
|
+
|
9
|
+
PHI = (1 + Math.sqrt(5)) / 2
|
10
|
+
|
11
|
+
def setup_the_sunstar
|
12
|
+
@hexa = ContextFree.define do
|
13
|
+
############ Begin defining custom terminals, as a sharp and flat triangles
|
14
|
+
class << self
|
15
|
+
include Math
|
16
|
+
define_method(:sharp) do |some_options|
|
17
|
+
size, options = *self.get_shape_values(some_options)
|
18
|
+
rot = options[:rotation]
|
19
|
+
rotate(rot) if rot # NB: sin(0) = 0, cos(0) = 1
|
20
|
+
@app.triangle(0, 0, size, 0, size * cos(PI/5), size * sin(PI/5))
|
21
|
+
rotate(-rot) if rot
|
22
|
+
end
|
23
|
+
define_method(:flat) do |some_options|
|
24
|
+
size, options = *self.get_shape_values(some_options)
|
25
|
+
rot = options[:rotation]
|
26
|
+
rotate(rot) if rot
|
27
|
+
f = (options[:flip])? -1 : 1 # flip adjustment NB: sin(0) = 0, cos(0) = 1
|
28
|
+
@app.triangle(0, 0, size/PHI, 0, size * cos(PI * f/5), size * sin(PI * f/5))
|
29
|
+
rotate(-rot) if rot
|
30
|
+
end
|
31
|
+
end
|
32
|
+
########### End definition of custom terminals 'sharp and flat'
|
33
|
+
shape :tiling do
|
34
|
+
sun brightness: 0.8
|
35
|
+
star brightness: 0.8, alpha: 0.8
|
36
|
+
tiling size: 1/PHI, brightness: 1.0
|
37
|
+
end
|
38
|
+
|
39
|
+
shape :dart do
|
40
|
+
flat size: 1, color: [65, 0.6, 0.6, 1]
|
41
|
+
flat size: 1, color: [65, 1.0, 1.0, 1], flip: true
|
42
|
+
end
|
43
|
+
|
44
|
+
shape :kite do
|
45
|
+
sharp size: 1, color: [0, 0.6, 0.6, 1]
|
46
|
+
sharp size: 1, color: [0, 1.0, 1.0, 1], rotation: 180, flip: true
|
47
|
+
end
|
48
|
+
|
49
|
+
shape :star do
|
50
|
+
split do
|
51
|
+
5.times do |i|
|
52
|
+
dart rotation: 72 * i
|
53
|
+
rewind
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
shape :sun do
|
59
|
+
split do
|
60
|
+
5.times do |i|
|
61
|
+
kite rotation: 72 * i
|
62
|
+
rewind
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def setup
|
70
|
+
size 800, 800
|
71
|
+
background 150, 20, 0, 1
|
72
|
+
setup_the_sunstar
|
73
|
+
draw_it
|
74
|
+
end
|
75
|
+
|
76
|
+
def draw_it
|
77
|
+
@hexa.render :tiling, start_x: width/2, start_y: height/2,
|
78
|
+
size: height
|
79
|
+
end
|
data/samples/spiral.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Contributed by Monkstone.
|
2
2
|
|
3
|
-
|
3
|
+
require 'cf3'
|
4
4
|
|
5
5
|
def setup_the_spiral
|
6
6
|
@spiral = ContextFree.define do
|
@@ -16,7 +16,7 @@ def setup_the_spiral
|
|
16
16
|
end
|
17
17
|
|
18
18
|
shape :base do
|
19
|
-
triangle hue:
|
19
|
+
triangle hue: 180
|
20
20
|
base rotation: 3, size: 0.98, x: 0.09, brightness: 1.01
|
21
21
|
end
|
22
22
|
|
@@ -50,4 +50,4 @@ def draw_it
|
|
50
50
|
@spiral.render :start, size: height/5, stop_size: 1,
|
51
51
|
color: [0.35, 0.4, 0.9, 0.25],
|
52
52
|
start_x: width/2, start_y: height/2
|
53
|
-
end
|
53
|
+
end
|
data/samples/star.rb
ADDED
@@ -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
|
+
sqstar size: 0.8, x: -1
|
15
|
+
rewind
|
16
|
+
trstar x: 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
shape :sqstar do
|
21
|
+
square
|
22
|
+
square rotation: 45
|
23
|
+
end
|
24
|
+
|
25
|
+
shape :trstar do
|
26
|
+
triangle
|
27
|
+
triangle rotation: 180
|
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
|
data/samples/tree.rb
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
require 'cf3'
|
6
6
|
load_library :control_panel
|
7
7
|
|
8
|
-
attr_reader :panel
|
8
|
+
attr_reader :panel, :hide
|
9
9
|
|
10
10
|
def setup_the_trees
|
11
|
-
|
12
11
|
control_panel do |panel|
|
13
|
-
|
12
|
+
panel.look_feel "Metal"
|
14
13
|
panel.slider :srand, 0..100
|
14
|
+
@panel = panel
|
15
15
|
end
|
16
16
|
|
17
17
|
@tree = ContextFree.define do
|
@@ -42,7 +42,7 @@ def setup_the_trees
|
|
42
42
|
shape :leaf do
|
43
43
|
the_size = rand(25)
|
44
44
|
the_x = [1, 0, 0, 0][rand(4)]
|
45
|
-
circle size: the_size, hue:
|
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
|
@@ -59,40 +59,29 @@ end
|
|
59
59
|
|
60
60
|
def setup
|
61
61
|
size 800, 800
|
62
|
+
@hide = true
|
62
63
|
setup_the_trees
|
63
64
|
no_stroke
|
64
|
-
smooth
|
65
65
|
frame_rate 5
|
66
66
|
draw_it
|
67
67
|
end
|
68
68
|
|
69
69
|
def draw
|
70
|
-
|
71
|
-
|
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
|
70
|
+
unless hide
|
71
|
+
panel.set_visible(true)
|
85
72
|
end
|
86
73
|
end
|
87
74
|
|
88
75
|
def draw_it
|
89
76
|
Kernel::srand(@srand) if @srand
|
90
|
-
|
77
|
+
background(color(rand(0 .. 255), rand(0 .. 255), rand(0 .. 255), 255))
|
91
78
|
@tree.render :seed, start_x: width/2, start_y: height+20,
|
92
|
-
size: height/60, color: [
|
79
|
+
size: height/60, color: [252, 0.15, 0.8, 1]
|
93
80
|
end
|
94
81
|
|
95
82
|
def mouse_clicked
|
83
|
+
@hide = false
|
96
84
|
panel.set_visible(true)
|
97
85
|
draw_it
|
86
|
+
@hide = true
|
98
87
|
end
|
data/samples/vine.rb
CHANGED
@@ -37,9 +37,6 @@ def setup
|
|
37
37
|
size 700, 700
|
38
38
|
setup_the_vine
|
39
39
|
no_stroke
|
40
|
-
color_mode HSB, 1.0
|
41
|
-
smooth
|
42
|
-
draw_it
|
43
40
|
end
|
44
41
|
|
45
42
|
def draw
|
@@ -47,8 +44,8 @@ def draw
|
|
47
44
|
end
|
48
45
|
|
49
46
|
def draw_it
|
50
|
-
background
|
51
|
-
@vine.render :root, size: height/75, color: [
|
47
|
+
background 270, 1.0, 0.15, 1.0
|
48
|
+
@vine.render :root, size: height/75, color: [270, 0.1, 0.9, 1.0],
|
52
49
|
start_x: width/2, start_y: height/2
|
53
50
|
end
|
54
51
|
|
data/test/test_cf3.rb
CHANGED
@@ -5,15 +5,14 @@ def setup
|
|
5
5
|
@triangle = ContextFree.define do
|
6
6
|
shape :tri do
|
7
7
|
circle
|
8
|
-
triangle brightness: 0
|
9
|
-
circle brightness:
|
8
|
+
triangle brightness: 0.8
|
9
|
+
circle brightness: 1.0, size: 0.02
|
10
10
|
end
|
11
11
|
end
|
12
|
-
color_mode HSB, 1.0
|
13
12
|
end
|
14
13
|
|
15
14
|
def draw_it
|
16
|
-
background
|
15
|
+
background 0.2
|
17
16
|
@triangle.render :tri, size: height/2
|
18
17
|
end
|
19
18
|
|
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.
|
4
|
+
version: 0.0.3
|
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-
|
12
|
+
date: 2013-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-processing
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/cf3/version.rb
|
80
80
|
- samples/accident.rb
|
81
81
|
- samples/alhambra.rb
|
82
|
+
- samples/alhambra2.rb
|
82
83
|
- samples/bar_code.rb
|
83
84
|
- samples/city.rb
|
84
85
|
- samples/creature.rb
|
@@ -92,8 +93,10 @@ files:
|
|
92
93
|
- samples/isosceles.rb
|
93
94
|
- samples/levy.rb
|
94
95
|
- samples/pcr.rb
|
96
|
+
- samples/rubystar.rb
|
95
97
|
- samples/sierpinski.rb
|
96
98
|
- samples/spiral.rb
|
99
|
+
- samples/star.rb
|
97
100
|
- samples/tree.rb
|
98
101
|
- samples/tree4.rb
|
99
102
|
- samples/vine.rb
|