cf3 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ #################################################################
2
+ # tree4.rb by Martin Prout after tree4.cfdg
3
+ # A non deterministic sketch run it until you get a result you like
4
+ # uncomment "srand 5" to get a more deterministic result. It looked
5
+ # pretty good on my linux box (however I'm not sure how universal the
6
+ # random seeding is in jruby)
7
+ #################################################################
8
+
9
+ require 'cf3'
10
+
11
+ def setup_the_tree
12
+ @tree = ContextFree.define do
13
+ shape :trunk, 20 do # rule has a probability weighting of 20
14
+ circle size: 0.25, brightness: 0.5 # giving an actual probability = 0.952381
15
+ scraggle y: -0.1 # the minus is require by the upside down coordinate system
16
+ end
17
+
18
+ shape :trunk, 1 do # rule has a probability weighting of 1
19
+ branch size: 0.7 # giving an actual probability = 0.047619
20
+ end
21
+
22
+ shape :trunk, 0.02 do # empty rule top stop early
23
+ end
24
+
25
+ shape :branch do
26
+ split do # split is like a branch, rewind returns original context
27
+ trunk rotation: 10
28
+ rewind
29
+ trunk rotation: -10
30
+ end
31
+ end
32
+
33
+ shape :scraggle do # without an explicit weighting
34
+ trunk rotation: 5 # probability of each scraggle rule
35
+ end # is 0.5
36
+
37
+ shape :scraggle do
38
+ trunk rotation: -5
39
+ end
40
+ end
41
+ end
42
+
43
+ def setup
44
+ size 600, 600
45
+ # srand 5 uncomment this to get nice looking tree
46
+ smooth
47
+ 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
+ end
52
+
53
+ def draw
54
+ # create a draw loop
55
+ end
56
+
57
+ def draw_it
58
+ @tree.render :trunk, start_x: width/2, start_y: height * 0.9, stop_size: height/150, size: height/15
59
+ end
60
+
61
+ def mouse_clicked
62
+ java.lang.System.gc # might help to reduce runtime stack blow ups, it happens!
63
+ background 1
64
+ draw_it
65
+ end
@@ -0,0 +1,57 @@
1
+ # vine.rb by jashkenas, click mouse to re-run
2
+
3
+ require 'cf3'
4
+
5
+ def setup_the_vine
6
+
7
+ @vine = ContextFree.define do
8
+
9
+ shrink = 0.961
10
+
11
+ shape :root do
12
+ split do
13
+ shoot y: 1
14
+ rewind
15
+ shoot rotation: 180
16
+ end
17
+ end
18
+
19
+ shape :shoot do
20
+ square
21
+ shoot y: 0.98, rotation: 5, size: shrink + rand * 0.05, brightness: 0.990
22
+ end
23
+
24
+ shape :shoot, 0.02 do
25
+ square
26
+ split do
27
+ shoot rotation: 90
28
+ rewind
29
+ shoot rotation: -90
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ def setup
37
+ size 700, 700
38
+ setup_the_vine
39
+ no_stroke
40
+ color_mode HSB, 1.0
41
+ smooth
42
+ draw_it
43
+ end
44
+
45
+ def draw
46
+ # Do nothing.
47
+ end
48
+
49
+ def draw_it
50
+ background 0.75, 1.0, 0.15
51
+ @vine.render :root, size: height/75, color: [0.75, 0.1, 0.9],
52
+ start_x: width/2, start_y: height/2
53
+ end
54
+
55
+ def mouse_clicked
56
+ draw_it
57
+ end
@@ -0,0 +1,46 @@
1
+ # y.rb ruby-processing by Martin Prout
2
+ require 'cf3'
3
+ Y_TOP = -1 / Math.sqrt(3)
4
+ Y_BOT = Math.sqrt(3) / 6
5
+
6
+ def setup_the_triangle
7
+ @triangle = ContextFree.define do
8
+ ########
9
+ shape :start do
10
+ unit brightness: 1.0
11
+ end
12
+
13
+ shape :unit do
14
+ triangle size: 1.0
15
+ split do
16
+ unit size: 0.5, x: 0, y: Y_TOP/2, brightness: 0.8
17
+ rewind
18
+ unit size: 0.5, x: -0.25, y: -Y_TOP/4, brightness: 0.8
19
+ rewind
20
+ unit size: 0.5, x: 0.25, y: -Y_TOP/4, brightness: 0.8
21
+ end
22
+ end
23
+ ########
24
+ end
25
+ end
26
+
27
+ def setup
28
+ size 1024, 1024
29
+ setup_the_triangle
30
+ no_stroke
31
+ color_mode RGB, 1
32
+ smooth 8
33
+ draw_it
34
+ save_frame("y.png")
35
+ end
36
+
37
+
38
+ def draw
39
+ # Do nothing.
40
+ end
41
+
42
+ def draw_it
43
+ background 225, 225, 0
44
+ @triangle.render :start, size: height, stop_size: 0.5,
45
+ start_x: width/2, start_y: height * 0.6
46
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../lib/cf3.rb'
2
+
3
+ def setup
4
+ size 200, 200
5
+ @triangle = ContextFree.define do
6
+ shape :tri do
7
+ circle
8
+ triangle brightness: 0
9
+ circle brightness: 10, size: 0.02
10
+ end
11
+ end
12
+ color_mode HSB, 1.0
13
+ end
14
+
15
+ def draw_it
16
+ background 1.0
17
+ @triangle.render :tri, size: height/2
18
+ end
19
+
20
+ def draw
21
+ # Do nothing.
22
+ end
23
+
24
+ def mouse_clicked
25
+ draw_it
26
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cf3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Ashkenas
8
+ - Martin Prout
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby-processing
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.11
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.11
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.3'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: " A library for ruby-processing, that allows the writing of context
57
+ free \n sketches (like context free art) in a ruby DSL. It is a bit of a toy\n
58
+ \ compared to the c++ version. However you can get quite a bit of \n satisfaction
59
+ creating an interesting graphic, and you can't always\n predict what you are
60
+ going to get.\n"
61
+ email:
62
+ - martin_p@lineone.net
63
+ executables:
64
+ - cf3samples
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - .yardopts
70
+ - CHANGELOG
71
+ - CONTRIBUTING.md
72
+ - Gemfile
73
+ - LICENSE.md
74
+ - README.md
75
+ - Rakefile
76
+ - bin/cf3samples
77
+ - cf3ruby.gemspec
78
+ - lib/cf3.rb
79
+ - lib/cf3/version.rb
80
+ - samples/accident.rb
81
+ - samples/alhambra.rb
82
+ - samples/bar_code.rb
83
+ - samples/city.rb
84
+ - samples/creature.rb
85
+ - samples/dark_star.rb
86
+ - samples/data/java_args.txt
87
+ - samples/dragon.rb
88
+ - samples/escher.rb
89
+ - samples/fern.rb
90
+ - samples/grapher.rb
91
+ - samples/hex_tube.rb
92
+ - samples/isosceles.rb
93
+ - samples/levy.rb
94
+ - samples/pcr.rb
95
+ - samples/sierpinski.rb
96
+ - samples/spiral.rb
97
+ - samples/tree.rb
98
+ - samples/tree4.rb
99
+ - samples/vine.rb
100
+ - samples/y.rb
101
+ - test/test_cf3.rb
102
+ homepage: http://learning-ruby-processing.blogspot.co.uk/
103
+ licenses:
104
+ - GPL3
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.5
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A ruby-DSL library for CF3 sketches
126
+ test_files:
127
+ - test/test_cf3.rb
128
+ has_rdoc: