rubyonacid 0.2.0 → 0.3.0

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.
data/README.textile CHANGED
@@ -75,6 +75,10 @@ Start by looking at the code for the bundled factories in the lib/rubyonacid/fac
75
75
 
76
76
  h1. Resources
77
77
 
78
+ API documentation is hosted on RDoc.info.
79
+
80
+ "RDoc documentation":http://rdoc.info/projects/jaymcgavren/rubyonacid
81
+
78
82
  The project page on GitHub lets you browse the latest code, or clone or fork the source repo for yourself.
79
83
 
80
84
  "GitHub project":http://www.github.com/jaymcgavren/rubyonacid
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/examples/ascii.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'rubyonacid/factories/all'
2
+
1
3
  #This method takes any Factory and uses it to determine the length of lines to print.
2
4
  def make_lines(factory)
3
5
  #Show what factory we're working with.
@@ -11,33 +13,29 @@ def make_lines(factory)
11
13
  end
12
14
 
13
15
  #Random factories generate a random number between 0 and 1.
14
- require 'rubyonacid/factories/random'
15
16
  make_lines RubyOnAcid::RandomFactory.new
16
17
 
18
+ #Random walk factories increase or decrease the prior return value within a given amount.
19
+ make_lines RubyOnAcid::RandomWalkFactory.new(0.1)
20
+
17
21
  #Loop factories loop from 0 to 1 (or 1 to 0 if the increment value is negative).
18
- require 'rubyonacid/factories/loop'
19
22
  make_lines RubyOnAcid::LoopFactory.new(0.2)
20
23
  make_lines RubyOnAcid::LoopFactory.new(-0.2)
21
24
 
22
25
  #Constant factories always return the same value,
23
- require 'rubyonacid/factories/constant'
24
26
  make_lines RubyOnAcid::ConstantFactory.new(0.5)
25
27
 
26
28
  #This flash factory returns 0 twice, then 1 twice, then 0 twice, etc.
27
- require 'rubyonacid/factories/flash'
28
29
  make_lines RubyOnAcid::FlashFactory.new(2)
29
30
 
30
31
  #Sine factories produce a "wave" pattern.
31
- require 'rubyonacid/factories/sine'
32
32
  make_lines RubyOnAcid::SineFactory.new(0.3)
33
33
 
34
34
  #A RepeatFactory wraps another factory, queries it, and repeats the same value a certain number of times.
35
- require 'rubyonacid/factories/repeat'
36
35
  factory_to_repeat = RubyOnAcid::LoopFactory.new(0.3)
37
36
  make_lines RubyOnAcid::RepeatFactory.new(factory_to_repeat, 2)
38
37
 
39
38
  #A CombinationFactory combines the values of two or more other factories.
40
- require 'rubyonacid/factories/combination'
41
39
  factories_to_combine = [
42
40
  RubyOnAcid::SineFactory.new(0.1),
43
41
  RubyOnAcid::SineFactory.new(-0.2)
data/examples/midi.rb CHANGED
@@ -1,55 +1,27 @@
1
1
  require 'rubygems'
2
- require 'rubyonacid/factories/meta'
3
- require 'rubyonacid/factories/constant'
4
- require 'rubyonacid/factories/flash'
5
- require 'rubyonacid/factories/loop'
6
- require 'rubyonacid/factories/random'
7
- require 'rubyonacid/factories/repeat'
8
- require 'rubyonacid/factories/sine'
9
- require 'rubyonacid/factories/skip'
2
+ require 'rubyonacid/factories/example'
10
3
 
11
- random_factory = RubyOnAcid::RandomFactory.new
12
-
13
- #The MetaFactory assigns factories to requested value types.
14
- factory = RubyOnAcid::MetaFactory.new
15
- #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
16
- factory.factory_pool << RubyOnAcid::LoopFactory.new(0.01)
17
- factory.factory_pool << RubyOnAcid::LoopFactory.new(-0.01)
18
- factory.factory_pool << RubyOnAcid::LoopFactory.new(0.001)
19
- factory.factory_pool << RubyOnAcid::LoopFactory.new(-0.001)
20
- #Constant factories always return the same value,
21
- factory.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
22
- factory.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
23
- factory.factory_pool << RubyOnAcid::FlashFactory.new(rand(100))
24
- #Sine factories produce a "wave" pattern.
25
- factory.factory_pool << RubyOnAcid::SineFactory.new(0.1)
26
- factory.factory_pool << RubyOnAcid::SineFactory.new(-0.1)
27
- factory.factory_pool << RubyOnAcid::SineFactory.new(0.01)
28
- factory.factory_pool << RubyOnAcid::SineFactory.new(-0.01)
29
- factory.factory_pool << RubyOnAcid::RepeatFactory.new(
30
- RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
31
- random_factory.within(:interval, 2, 100)
32
- )
33
- factory.factory_pool << RubyOnAcid::RepeatFactory.new(
34
- RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
35
- random_factory.within(:interval, 2, 100)
36
- )
37
-
38
- #A skip factory, in charge of randomly resetting the meta factory.
4
+ #This factory chooses notes, play durations, etc.
5
+ factory = RubyOnAcid::ExampleFactory.new
6
+
7
+ #This factory randomly resets the meta factory.
39
8
  @resetter = RubyOnAcid::SkipFactory.new(0.999)
40
9
 
41
-
42
- require 'midiator'
10
+ begin
11
+ require 'midiator'
12
+ rescue LoadError
13
+ raise "It appears that MIDIator is not installed. 'sudo gem install midiator' to install it."
14
+ end
43
15
 
44
16
  midi = MIDIator::Interface.new
45
17
  midi.autodetect_driver
46
18
 
47
19
  loop do
48
20
  midi.play(
49
- factory.within(:note, 10, 127).to_i,
50
- factory.within(:duration, 0, 0.1),
51
- factory.within(:channel, 0, 10).to_i,
52
- factory.within(:velocity, 0, 127)
21
+ factory.get(:note, :min => 10, :max => 127).to_i,
22
+ factory.get(:duration, :max => 0.1),
23
+ factory.get(:channel, :max => 10).to_i,
24
+ factory.get(:velocity, :max => 127)
53
25
  )
54
26
  factory.reset_assignments if @resetter.boolean(:reset)
55
27
  end
@@ -1,51 +1,21 @@
1
- require 'rubygems'
2
- require 'rubyonacid/factories/meta'
3
- require 'rubyonacid/factories/constant'
4
- require 'rubyonacid/factories/flash'
5
- require 'rubyonacid/factories/loop'
6
- require 'rubyonacid/factories/random'
7
- require 'rubyonacid/factories/repeat'
8
- require 'rubyonacid/factories/sine'
9
- require 'rubyonacid/factories/skip'
10
-
11
- def generate_factories
12
-
13
- random_factory = RubyOnAcid::RandomFactory.new
1
+ puts "This demo writes raw 8-bit PCM data to a file. Ctrl-C to stop. Import the file to Audacity (or a similar audio editing program) to hear the results."
14
2
 
15
- factory_pool = []
16
-
17
- #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
18
- factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.01, 0.01))
19
- #Constant factories always return the same value,
20
- factory_pool << RubyOnAcid::ConstantFactory.new(rand)
21
- factory_pool << RubyOnAcid::ConstantFactory.new(rand)
22
- factory_pool << RubyOnAcid::FlashFactory.new(rand(100))
23
- #Sine factories produce a "wave" pattern.
24
- factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.01, 0.01))
25
- factory_pool << RubyOnAcid::RepeatFactory.new(
26
- RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
27
- random_factory.within(:interval, 2, 100)
28
- )
29
- factory_pool << RubyOnAcid::RepeatFactory.new(
30
- RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
31
- random_factory.within(:interval, 2, 100)
32
- )
33
- factory_pool
34
- end
3
+ require 'rubygems'
4
+ require 'rubyonacid/factories/example'
35
5
 
36
- #A skip factory, in charge of randomly resetting the meta factory.
37
- @resetter = RubyOnAcid::SkipFactory.new(0.99995)
6
+ #This factory chooses notes, play durations, etc.
7
+ factory = RubyOnAcid::ExampleFactory.new
8
+
9
+ #This factory randomly resets the meta factory.
10
+ @resetter = RubyOnAcid::SkipFactory.new(0.999)
38
11
 
39
- factory = RubyOnAcid::MetaFactory.new
40
- factory.factory_pool = generate_factories
41
12
  File.open("raw_audio.dat", "w") do |file|
42
13
  loop do
43
- channel_count = factory.within(:chanel_count, 0, 3).to_i
14
+ channel_count = factory.get(:channel_count, :max => 3).to_i
44
15
  channel_count.times do |i|
45
- file.putc factory.within(i, 0, 255).to_i
16
+ file.putc factory.get(i, :max => 255).to_i
46
17
  end
47
18
  if @resetter.boolean(:reset)
48
- factory.factory_pool = generate_factories
49
19
  factory.reset_assignments
50
20
  end
51
21
  end
@@ -1,16 +1,10 @@
1
1
  require 'rubygems'
2
- require 'wx'
3
- require 'rubyonacid/factories/meta'
4
- require 'rubyonacid/factories/constant'
5
- require 'rubyonacid/factories/flash'
6
- require 'rubyonacid/factories/loop'
7
- require 'rubyonacid/factories/random'
8
- require 'rubyonacid/factories/repeat'
9
- require 'rubyonacid/factories/rinda'
10
- require 'rubyonacid/factories/sine'
11
- require 'rubyonacid/factories/skip'
12
-
13
-
2
+ begin
3
+ require 'wx'
4
+ rescue LoadError
5
+ raise "It appears that wxruby is not installed. 'sudo gem install wxruby' to install it."
6
+ end
7
+ require 'rubyonacid/factories/example'
14
8
 
15
9
  class MyApp < Wx::App
16
10
 
@@ -19,18 +13,16 @@ class MyApp < Wx::App
19
13
 
20
14
  def on_init
21
15
 
22
- @f = RubyOnAcid::RindaFactory.new(ARGV[0])
23
- @f.default_factory = create_factory
16
+ @f = RubyOnAcid::RindaFactory.new(ARGV[0] || "druby://127.0.0.1:7632")
17
+ @f.default_factory = RubyOnAcid::ExampleFactory.new
24
18
  @f.start_service
25
19
 
26
20
  #A skip factory, in charge of randomly resetting the meta factory.
27
21
  @resetter = RubyOnAcid::SkipFactory.new(0.999)
28
22
 
29
- #Containing frame.
23
+ #Set up window.
30
24
  frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
31
25
  frame.show
32
-
33
- #Displays drawing.
34
26
  window = Wx::Window.new(frame, :size => [WIDTH, HEIGHT])
35
27
 
36
28
  #Animate periodically.
@@ -40,38 +32,7 @@ class MyApp < Wx::App
40
32
  @f.default_factory.reset_assignments if @resetter.boolean(:reset)
41
33
  end
42
34
  t.start(33)
43
-
44
- end
45
-
46
- def create_factory
47
- random_factory = RubyOnAcid::RandomFactory.new
48
-
49
- #The MetaFactory assigns factories to requested value types.
50
- meta_factory = RubyOnAcid::MetaFactory.new
51
- #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
52
- meta_factory.factory_pool << RubyOnAcid::LoopFactory.new(0.01)
53
- meta_factory.factory_pool << RubyOnAcid::LoopFactory.new(-0.01)
54
- meta_factory.factory_pool << RubyOnAcid::LoopFactory.new(0.001)
55
- meta_factory.factory_pool << RubyOnAcid::LoopFactory.new(-0.001)
56
- #Constant factories always return the same value,
57
- meta_factory.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
58
- meta_factory.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
59
- meta_factory.factory_pool << RubyOnAcid::FlashFactory.new(rand(100))
60
- #Sine factories produce a "wave" pattern.
61
- meta_factory.factory_pool << RubyOnAcid::SineFactory.new(0.1)
62
- meta_factory.factory_pool << RubyOnAcid::SineFactory.new(-0.1)
63
- meta_factory.factory_pool << RubyOnAcid::SineFactory.new(0.01)
64
- meta_factory.factory_pool << RubyOnAcid::SineFactory.new(-0.01)
65
- meta_factory.factory_pool << RubyOnAcid::RepeatFactory.new(
66
- RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
67
- random_factory.within(:interval, 2, 100)
68
- )
69
- meta_factory.factory_pool << RubyOnAcid::RepeatFactory.new(
70
- RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
71
- random_factory.within(:interval, 2, 100)
72
- )
73
-
74
- meta_factory
35
+
75
36
  end
76
37
 
77
38
  def render(surface)
@@ -81,7 +42,7 @@ class MyApp < Wx::App
81
42
  @f.get(:blue, :max => 255).to_i,
82
43
  @f.get(:alpha, :min => 50, :max => 200).to_i
83
44
  )
84
- surface.pen = Wx::Pen.new(color, @f.within(:width, 1, 5).to_i)
45
+ surface.pen = Wx::Pen.new(color, @f.get(:width, :min => 1, :max => 5).to_i)
85
46
  surface.brush = Wx::Brush.new(color, Wx::SOLID)
86
47
  case @f.choose(:shape,
87
48
  :arc,
data/examples/svg.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'rubygems'
2
+ require 'rubyonacid/factories/example'
3
+
4
+ def svg(factory)
5
+ return <<-EOD.strip
6
+ <?xml version="1.0" standalone="no"?>
7
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
8
+ <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" version="1.1">
9
+ #{shapes(factory).join("\n")}
10
+ </svg>
11
+ EOD
12
+ end
13
+
14
+ def shapes(factory)
15
+ shapes = []
16
+ 1000.times do
17
+ shapes << case factory.choose(:shape, :rectangle, :ellipse, :line)
18
+ when :rectangle : rectangle(factory)
19
+ when :ellipse : ellipse(factory)
20
+ when :line : line(factory)
21
+ end
22
+ end
23
+ shapes
24
+ end
25
+
26
+ def rectangle(factory)
27
+ return <<-EOD
28
+ <rect
29
+ x='#{factory.get(:x, :max => 100)}%'
30
+ y='#{factory.get(:y, :max => 100)}%'
31
+ width='#{factory.get(:width, :max => 300)}'
32
+ height='#{factory.get(:height, :max => 300)}'
33
+ style='#{style(factory)}'
34
+ transform='#{transform(factory)}'
35
+ />
36
+ EOD
37
+ end
38
+
39
+ def ellipse(factory)
40
+ return <<-EOD
41
+ <ellipse
42
+ cx='#{factory.get(:x, :max => 100)}%'
43
+ cy='#{factory.get(:y, :max => 100)}%'
44
+ rx='#{factory.get(:width, :max => 300)}'
45
+ ry='#{factory.get(:height, :max => 300)}'
46
+ style='#{style(factory)}'
47
+ transform='#{transform(factory)}'
48
+ />
49
+ EOD
50
+ end
51
+
52
+ def line(factory)
53
+ return <<-EOD
54
+ <line
55
+ x1='#{factory.get(:x, :max => 100)}%'
56
+ y1='#{factory.get(:y, :max => 100)}%'
57
+ x2='#{factory.get(:x2, :max => 100)}%'
58
+ y2='#{factory.get(:y2, :max => 100)}%'
59
+ stroke='#{color(factory)}'
60
+ stroke-width='#{factory.get(:width, :max => 20)}'
61
+ stroke-opacity='#{factory.get(:opacity)}'
62
+ />
63
+ EOD
64
+ end
65
+
66
+ def style(factory)
67
+ "fill:#{color(factory)};fill-opacity:#{factory.get(:opacity)};"
68
+ end
69
+
70
+ def color(factory)
71
+ "rgb(#{factory.get(:red, :max => 255).to_i},#{factory.get(:green, :max => 255).to_i},#{factory.get(:blue, :max => 255).to_i})"
72
+ end
73
+
74
+ def transform(factory)
75
+ return <<-EOD
76
+ rotate(#{factory.get(:rotation, :max => 360)})
77
+ translate(#{factory.get(:x_translate, :max => 100)}, #{factory.get(:y_translate, :max => 100)})
78
+ scale(#{factory.get(:scale, :max => 2)})
79
+ skewX(#{factory.get(:x_skew, :max => 360)})
80
+ skewY(#{factory.get(:y_skew, :max => 360)})
81
+ EOD
82
+ end
83
+
84
+ factory = RubyOnAcid::ExampleFactory.new
85
+ puts svg(factory)
data/examples/wxruby.rb CHANGED
@@ -1,15 +1,10 @@
1
1
  require 'rubygems'
2
- require 'wx'
3
- require 'rubyonacid/factories/meta'
4
- require 'rubyonacid/factories/combination'
5
- require 'rubyonacid/factories/constant'
6
- require 'rubyonacid/factories/flash'
7
- require 'rubyonacid/factories/loop'
8
- require 'rubyonacid/factories/random'
9
- require 'rubyonacid/factories/repeat'
10
- require 'rubyonacid/factories/sine'
11
- require 'rubyonacid/factories/skip'
12
-
2
+ begin
3
+ require 'wx'
4
+ rescue LoadError
5
+ raise "It appears that wxruby is not installed. 'sudo gem install wxruby' to install it."
6
+ end
7
+ require 'rubyonacid/factories/example'
13
8
 
14
9
 
15
10
  class MyApp < Wx::App
@@ -19,16 +14,15 @@ class MyApp < Wx::App
19
14
 
20
15
  def on_init
21
16
 
22
- @f = create_factory
17
+ #This factory will be in charge of all drawing coordinates, colors, etc.
18
+ @f = RubyOnAcid::ExampleFactory.new
23
19
 
24
20
  #A skip factory, in charge of randomly resetting the meta factory.
25
21
  @resetter = RubyOnAcid::SkipFactory.new(0.999)
26
22
 
27
- #Containing frame.
23
+ #Set up window.
28
24
  frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
29
25
  frame.show
30
-
31
- #Displays drawing.
32
26
  window = Wx::Window.new(frame, :size => [WIDTH, HEIGHT])
33
27
 
34
28
  #Animate periodically.
@@ -41,51 +35,7 @@ class MyApp < Wx::App
41
35
 
42
36
  end
43
37
 
44
-
45
- def create_factory
46
-
47
- random_factory = RubyOnAcid::RandomFactory.new
48
-
49
- source_factories = []
50
- #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
51
- source_factories << RubyOnAcid::LoopFactory.new(0.01)
52
- source_factories << RubyOnAcid::LoopFactory.new(-0.01)
53
- source_factories << RubyOnAcid::LoopFactory.new(0.001)
54
- source_factories << RubyOnAcid::LoopFactory.new(-0.001)
55
- #Constant factories always return the same value,
56
- source_factories << RubyOnAcid::ConstantFactory.new(rand)
57
- source_factories << RubyOnAcid::ConstantFactory.new(rand)
58
- source_factories << RubyOnAcid::FlashFactory.new(rand(100))
59
- #Sine factories produce a "wave" pattern.
60
- source_factories << RubyOnAcid::SineFactory.new(0.1)
61
- source_factories << RubyOnAcid::SineFactory.new(-0.1)
62
- source_factories << RubyOnAcid::SineFactory.new(0.01)
63
- source_factories << RubyOnAcid::SineFactory.new(-0.01)
64
- #A RepeatFactory wraps another factory, queries it, and repeats the same value a certain number of times.
65
- source_factories << RubyOnAcid::RepeatFactory.new(
66
- RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
67
- random_factory.get(:interval, :min => 2, :max => 100)
68
- )
69
- source_factories << RubyOnAcid::RepeatFactory.new(
70
- RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
71
- random_factory.get(:interval, :min => 2, :max => 100)
72
- )
73
- #A CombinationFactory combines the values of two or more other factories.
74
- combination_factory = RubyOnAcid::CombinationFactory.new
75
- 2.times do
76
- combination_factory.source_factories << source_factories[rand(source_factories.length)]
77
- end
78
- source_factories << combination_factory
79
-
80
- #The MetaFactory pulls requested value types from the other factories.
81
- meta_factory = RubyOnAcid::MetaFactory.new
82
- meta_factory.factory_pool = source_factories
83
-
84
- meta_factory
85
-
86
- end
87
-
88
-
38
+ #Choose a shape and color and draw it to the given surface.
89
39
  def render(surface)
90
40
  color = Wx::Colour.new(
91
41
  @f.get(:red, :max => 255).to_i,
@@ -93,7 +43,7 @@ class MyApp < Wx::App
93
43
  @f.get(:blue, :max => 255).to_i,
94
44
  @f.get(:alpha, :min => 50, :max => 200).to_i
95
45
  )
96
- surface.pen = Wx::Pen.new(color, @f.within(:width, 1, 5).to_i)
46
+ surface.pen = Wx::Pen.new(color, @f.get(:width, :min => 1, :max => 5).to_i)
97
47
  surface.brush = Wx::Brush.new(color, Wx::SOLID)
98
48
  case @f.choose(:shape,
99
49
  :arc,
@@ -139,7 +89,7 @@ class MyApp < Wx::App
139
89
  end
140
90
  end
141
91
 
142
-
92
+ #Create an array of points for drawing complex shapes.
143
93
  def make_point_array
144
94
  points = []
145
95
  3.times do |i|
@@ -0,0 +1,13 @@
1
+ require 'rubyonacid/factories/combination'
2
+ require 'rubyonacid/factories/constant'
3
+ require 'rubyonacid/factories/flash'
4
+ require 'rubyonacid/factories/increment'
5
+ require 'rubyonacid/factories/input'
6
+ require 'rubyonacid/factories/loop'
7
+ require 'rubyonacid/factories/meta'
8
+ require 'rubyonacid/factories/random'
9
+ require 'rubyonacid/factories/random_walk'
10
+ require 'rubyonacid/factories/repeat'
11
+ require 'rubyonacid/factories/rinda'
12
+ require 'rubyonacid/factories/sine'
13
+ require 'rubyonacid/factories/skip'
@@ -4,15 +4,24 @@ module RubyOnAcid
4
4
 
5
5
  class CombinationFactory < Factory
6
6
 
7
+ #Causes get_unit value of all source_factories to be added together.
7
8
  ADD = :add
9
+ #Takes the get_unit value of the first of the source_factories and subtracts the get_unit value of all subsequent ones.
8
10
  SUBTRACT = :subtract
11
+ #Causes get_unit value of all source_factories to be multiplied.
9
12
  MULTIPLY = :multiply
13
+ #Takes the get_unit value of the first of the source_factories and divides the result by the get_unit value of all subsequent ones.
10
14
  DIVIDE = :divide
15
+ #Causes get_unit values above 1 to be truncated at 1 and values below 0 to be truncated at 0.
11
16
  CONSTRAIN = :constrain
17
+ #Causes get_unit values above 1 to wrap to 0 and values below 0 to wrap to 1.
12
18
  WRAP = :wrap
13
19
 
20
+ #An array of factories to be queried by get_unit.
14
21
  attr_accessor :source_factories
22
+ #The operation get_unit will perform.
15
23
  attr_accessor :operation
24
+ #The method get_unit will use to constrain values between 0 and 1.
16
25
  attr_accessor :constrain_mode
17
26
 
18
27
  def initialize(options = {})
@@ -22,6 +31,8 @@ class CombinationFactory < Factory
22
31
  @constrain_mode = options[:constrain_mode] || WRAP
23
32
  end
24
33
 
34
+ #Queries all source_factories with given key and combines their return values with the set operation.
35
+ #Values will be constrained between 0 and 1 with the set constrain_mode.
25
36
  def get_unit(key)
26
37
  combined_value = combine(key)
27
38
  constrain(combined_value)
@@ -2,8 +2,10 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #A factory that returns a preset value for all keys.
5
6
  class ConstantFactory < Factory
6
7
 
8
+ #A value between 0 and 1 that get_unit will return.
7
9
  attr_accessor :value
8
10
  def value=(value)
9
11
  raise "assigned #{value} to value, must be between -1 and 1" if value < -1 or value > 1
@@ -15,7 +17,7 @@ class ConstantFactory < Factory
15
17
  @value = value
16
18
  end
17
19
 
18
- #Increment counter for key, looping it around to opposite side if it exits boundary.
20
+ #Returns assigned value.
19
21
  def get_unit(key)
20
22
  @value
21
23
  end
@@ -0,0 +1,63 @@
1
+ require 'rubyonacid/factories/all'
2
+
3
+ module RubyOnAcid
4
+
5
+ #A preconfigured factory with all the bells and whistles.
6
+ #Use this if you want to get up and running quickly and don't need to tweak the settings.
7
+ class ExampleFactory < MetaFactory
8
+
9
+
10
+ def initialize
11
+ super
12
+ @factory_pool = create_factories
13
+ end
14
+
15
+
16
+ private
17
+
18
+
19
+ def create_factories
20
+
21
+ random_factory = RubyOnAcid::RandomFactory.new
22
+
23
+ source_factories = []
24
+
25
+ 5.times do
26
+ factory = RubyOnAcid::LoopFactory.new
27
+ factory.interval = random_factory.get(:increment, :min => -0.1, :max => 0.1)
28
+ source_factories << factory
29
+ end
30
+ 3.times do
31
+ factory = RubyOnAcid::ConstantFactory.new
32
+ factory.value = random_factory.get(:constant)
33
+ source_factories << factory
34
+ end
35
+ source_factories << RubyOnAcid::FlashFactory.new(
36
+ random_factory.get(:interval, :max => 100)
37
+ )
38
+ 4.times do
39
+ factory = RubyOnAcid::SineFactory.new
40
+ factory.interval = random_factory.get(:increment, :min => -0.1, :max => 0.1)
41
+ source_factories << factory
42
+ end
43
+ 2.times do
44
+ factory = RubyOnAcid::RepeatFactory.new
45
+ factory.repeat_count = random_factory.get(:interval, :min => 2, :max => 100)
46
+ factory.source_factory = source_factories[rand(source_factories.length)]
47
+ source_factories << factory
48
+ end
49
+ combination_factory = RubyOnAcid::CombinationFactory.new
50
+ 2.times do
51
+ combination_factory.source_factories << source_factories[rand(source_factories.length)]
52
+ end
53
+ source_factories << combination_factory
54
+ source_factories << RubyOnAcid::RandomWalkFactory.new(0.1)
55
+
56
+ source_factories
57
+
58
+ end
59
+
60
+
61
+ end
62
+
63
+ end
@@ -2,6 +2,7 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #Returns 0.0 for a given number of queries, then 1.0 for the same number of queries, then goes back to 0.0 and repeats.
5
6
  class FlashFactory < Factory
6
7
 
7
8
  attr_accessor :interval
@@ -2,6 +2,7 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #Increments from the minimum value, stopping at the maximum, or decrements from the maximum value, stopping at the minimum.
5
6
  class IncrementFactory < Factory
6
7
 
7
8
  #The amount to increment counters by.
@@ -0,0 +1,67 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class InputFactory < Factory
6
+
7
+ attr_accessor :default_factory
8
+
9
+ def initialize
10
+ super
11
+ @input_values = {}
12
+ @key_assignments = {}
13
+ @largest_seen_values = {}
14
+ @smallest_seen_values = {}
15
+ end
16
+
17
+ def get_unit(key)
18
+ current_key = assigned_key(key)
19
+ if @input_values[current_key] and @input_values[current_key].length > 0
20
+ return scale(current_key, @input_values[current_key].shift) || default_value(key)
21
+ else
22
+ return default_value(key)
23
+ end
24
+ end
25
+
26
+ def default_value(key)
27
+ @default_factory ? @default_factory.get_unit(key) : 0.0
28
+ end
29
+
30
+ def put(key, value)
31
+ value = value.to_f
32
+ @input_values[key] ||= []
33
+ @input_values[key] << value
34
+ @smallest_seen_values[key] ||= 0.0
35
+ if @largest_seen_values[key] == nil or @smallest_seen_values[key] > @largest_seen_values[key]
36
+ @largest_seen_values[key] = @smallest_seen_values[key] + 1.0
37
+ end
38
+ @smallest_seen_values[key] = value if value < @smallest_seen_values[key]
39
+ @largest_seen_values[key] = value if value > @largest_seen_values[key]
40
+ end
41
+
42
+ def clear_input_values
43
+ @input_values = {}
44
+ end
45
+
46
+ def clear_assigned_keys
47
+ @assigned_keys = {}
48
+ end
49
+
50
+ private
51
+
52
+ def assigned_key(key)
53
+ return @key_assignments[key] if @key_assignments[key]
54
+ key_pool = @input_values.keys - @key_assignments.values
55
+ @key_assignments[key] = key_pool[rand(key_pool.length)]
56
+ @key_assignments[key]
57
+ end
58
+
59
+ #Scales a value between the largest and smallest values seen for a key.
60
+ #Returns a value in the range 0 to 1.
61
+ def scale(key, value)
62
+ (value - @smallest_seen_values[key]) / (@largest_seen_values[key] - @smallest_seen_values[key])
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -2,9 +2,10 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #Loops from the minimum value to the maximum and around again.
5
6
  class LoopFactory < Factory
6
7
 
7
- #The amount to increment counters by.
8
+ #An amount between 0 and 1 to increment counters by.
8
9
  attr_accessor :interval
9
10
  def interval=(value)
10
11
  raise "assigned #{value} to interval, must be between -1 and 1" if value < -1 or value > 1
@@ -2,10 +2,11 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #The MetaFactory assigns factories to requested value types.
5
6
  class MetaFactory < Factory
6
7
 
8
+ #An array of Factory objects to assign to keys.
7
9
  attr_accessor :factory_pool
8
- attr_accessor :assigned_factories
9
10
 
10
11
  def initialize(factory_pool = [])
11
12
  super
@@ -13,15 +14,19 @@ class MetaFactory < Factory
13
14
  @assigned_factories = {}
14
15
  end
15
16
 
17
+ #Assign a factory for subsequent get_unit requests for the given key.
16
18
  def assign_factory(key, factory)
17
19
  @assigned_factories[key] = factory
18
20
  end
19
21
 
22
+ #Returns the value of get_unit from the Factory assigned to the given key.
23
+ #When a key is needed that a Factory is not already assigned to, one will be assigned at random from the factory_pool.
20
24
  def get_unit(key)
21
25
  @assigned_factories[key] ||= @factory_pool[rand(@factory_pool.length)]
22
26
  @assigned_factories[key].get_unit(key)
23
27
  end
24
28
 
29
+ #Clear all factory assignments.
25
30
  def reset_assignments
26
31
  @assigned_factories.clear
27
32
  end
@@ -2,6 +2,7 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #Returns random numbers between the minimum and the maximum.
5
6
  class RandomFactory < Factory
6
7
 
7
8
  #Returns a random value between 0 and 1.
@@ -0,0 +1,29 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ #Increments from the minimum value, stopping at the maximum, or decrements from the maximum value, stopping at the minimum.
6
+ class RandomWalkFactory < Factory
7
+
8
+ #The maximum amount to change counters by.
9
+ attr_accessor :interval
10
+
11
+ def initialize(interval = 0.001)
12
+ super
13
+ @start_value = 0.0
14
+ @values = {}
15
+ @interval = interval
16
+ end
17
+
18
+ #Increment counter for given key and return it. Constrain between 0 and 1.
19
+ def get_unit(key)
20
+ @values[key] ||= rand
21
+ @values[key] += (rand * (2 * @interval)) - @interval
22
+ @values[key] = 1.0 if @values[key] > 1.0
23
+ @values[key] = 0.0 if @values[key] < 0.0
24
+ @values[key]
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -3,6 +3,7 @@ require 'rubyonacid/factory'
3
3
 
4
4
  module RubyOnAcid
5
5
 
6
+ #Allows values to be sent over the network. For more information, see the Ruby standard library documentation for Rinda.
6
7
  class RindaFactory < Factory
7
8
 
8
9
  #Time in seconds to wait for a value before giving up and returning a default value for the given key.
@@ -21,6 +22,7 @@ class RindaFactory < Factory
21
22
  @prior_values = {}
22
23
  end
23
24
 
25
+ #Create the Rinda TupleSpace for clients to write to.
24
26
  def start_service
25
27
  DRb.start_service
26
28
  @space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, @uri))
@@ -2,8 +2,10 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #Produces a "wave" pattern.
5
6
  class SineFactory < Factory
6
7
 
8
+ #Counters used to calculate sine values will be incremented by this amount with each query.
7
9
  attr_accessor :interval
8
10
 
9
11
  def initialize(interval = 0.1)
@@ -2,6 +2,7 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #Returns the minimum or the maximum at random (influenced by the given odds).
5
6
  class SkipFactory < Factory
6
7
 
7
8
  #The percentage odds that the factory will return 0 instead of 1.
@@ -1,5 +1,7 @@
1
1
  module RubyOnAcid
2
2
 
3
+ #The parent class for all other Factories.
4
+ #Should not normally be instantiated directly.
3
5
  class Factory
4
6
 
5
7
  def initialize(*args)
@@ -16,7 +18,7 @@ class Factory
16
18
  def get(key, options = {})
17
19
  @minimums[key] = (options[:min] || @minimums[key] || 0.0)
18
20
  @maximums[key] = (options[:max] || @maximums[key] || (@minimums[key] > 1.0 ? @minimums[key] + 1.0 : 1.0))
19
- get_unit(key) * (@maximums[key] - @minimums[key]) + @minimums[key]
21
+ (get_unit(key) * (@maximums[key] - @minimums[key])) + @minimums[key]
20
22
  end
21
23
 
22
24
  #Returns true if get_unit(key) returns greater than 0.5.
@@ -33,6 +35,7 @@ class Factory
33
35
  all_choices[index]
34
36
  end
35
37
 
38
+
36
39
  end
37
40
 
38
41
  end
@@ -0,0 +1,96 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require "rubyonacid/factories/input"
3
+ require "shared_factory_specs"
4
+
5
+ include RubyOnAcid
6
+
7
+ describe InputFactory do
8
+
9
+ before :each do
10
+ @it = InputFactory.new
11
+ end
12
+
13
+ describe "general behavior" do
14
+
15
+ before :each do
16
+ @it.put(:foo, 0.0)
17
+ @it.put(:foo, 1.0)
18
+ end
19
+
20
+ it_should_behave_like "a factory"
21
+
22
+ end
23
+
24
+ describe "#get_unit" do
25
+
26
+ it "retrieves values assigned to a key" do
27
+ @it.put(:x, 0.1)
28
+ @it.get(:x).should == 0.1
29
+ end
30
+
31
+ it "retrieves multiple input values in order" do
32
+ @it.put(:x, 0.1)
33
+ @it.put(:x, 0.2)
34
+ @it.get(:x).should == 0.1
35
+ @it.get(:x).should == 0.2
36
+ end
37
+
38
+ it "maps to a different key if the requested one isn't present" do
39
+ @it.put(:x, 0.1)
40
+ @it.get(:y).should == 0.1
41
+ end
42
+
43
+ it "returns 0 if a key is assigned but has no values" do
44
+ @it.put(:x, 0.1)
45
+ @it.put(:x, 0.2)
46
+ @it.get(:y).should == 0.1
47
+ @it.get(:y).should == 0.2
48
+ @it.put(:z, 0.3)
49
+ @it.get(:y).should == 0.0
50
+ end
51
+
52
+ end
53
+
54
+ describe "scaling" do
55
+
56
+ it "scales highest seen values for a key to 0 to 1 range" do
57
+ @it.put(:x, 0.0)
58
+ @it.put(:x, 1.0)
59
+ @it.get(:x).should be_close(0.0, MARGIN)
60
+ @it.get(:x).should be_close(1.0, MARGIN)
61
+ @it.put(:x, 0.0)
62
+ @it.put(:x, 1.0)
63
+ @it.put(:x, 2.0)
64
+ @it.get(:x).should be_close(0.0, MARGIN)
65
+ @it.get(:x).should be_close(0.5, MARGIN)
66
+ @it.get(:x).should be_close(1.0, MARGIN)
67
+ @it.put(:x, 0.0)
68
+ @it.put(:x, 3.0)
69
+ @it.put(:x, 4.0)
70
+ @it.get(:x).should be_close(0.0, MARGIN)
71
+ @it.get(:x).should be_close(0.75, MARGIN)
72
+ @it.get(:x).should be_close(1.0, MARGIN)
73
+ end
74
+
75
+ it "scales lowest seen values for a key to 0 to 1 range" do
76
+ @it.put(:x, 0.0)
77
+ @it.put(:x, 1.0)
78
+ @it.get(:x).should be_close(0.0, MARGIN)
79
+ @it.get(:x).should be_close(1.0, MARGIN)
80
+ @it.put(:x, 0.0)
81
+ @it.put(:x, 1.0)
82
+ @it.put(:x, -2.0)
83
+ @it.get(:x).should be_close(0.666, MARGIN)
84
+ @it.get(:x).should be_close(1.0, MARGIN)
85
+ @it.get(:x).should be_close(0.0, MARGIN)
86
+ @it.put(:x, -2.0)
87
+ @it.put(:x, 2.0)
88
+ @it.put(:x, 1.0)
89
+ @it.get(:x).should be_close(0.0, MARGIN)
90
+ @it.get(:x).should be_close(1.0, MARGIN)
91
+ @it.get(:x).should be_close(0.75, MARGIN)
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require "shared_factory_specs"
3
+ require 'rubyonacid/factories/random_walk'
4
+
5
+ include RubyOnAcid
6
+
7
+ describe RandomWalkFactory do
8
+
9
+
10
+ before :each do
11
+ @it = RandomWalkFactory.new
12
+ end
13
+
14
+ it_should_behave_like "a factory"
15
+
16
+ it "increases or decreases prior key value by random amount within given interval" do
17
+ values = []
18
+ values << @it.get_unit(:x)
19
+ @it.interval = 0.3
20
+ values << @it.get_unit(:x)
21
+ values[1].should be_close(values[0], 0.3)
22
+ @it.interval = 0.01
23
+ values << @it.get_unit(:x)
24
+ values[2].should be_close(values[1], 0.01)
25
+ end
26
+
27
+ end
@@ -4,28 +4,35 @@ require 'rubyonacid/factories/rinda'
4
4
 
5
5
  include RubyOnAcid
6
6
 
7
+ require 'rinda/rinda'
8
+ require 'rinda/tuplespace'
9
+ DRb.start_service
10
+ DRb.start_service("druby://127.0.0.1:7632", Rinda::TupleSpace.new)
11
+
7
12
  describe RindaFactory do
8
13
 
9
-
10
14
  before :each do
11
15
  @it = RindaFactory.new
12
- uri = "druby://127.0.0.1:9999"
13
- @it.uri = uri
14
- require 'rinda/rinda'
15
- require 'rinda/tuplespace'
16
- DRb.start_service
17
- DRb.start_service(uri, Rinda::TupleSpace.new)
16
+ @it.uri = "druby://127.0.0.1:7632"
18
17
  @space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, @it.uri))
19
18
  end
20
19
 
21
- it_should_behave_like "a factory"
20
+ describe "general behavior" do
21
+
22
+ before :each do
23
+ @it.start_service
24
+ end
25
+
26
+ it_should_behave_like "a factory"
27
+
28
+ end
22
29
 
23
30
  it "gets keys from Rinda server" do
24
31
  @it.start_service
25
32
  @space.write([:x, 0.5])
26
33
  @it.get_unit(:x).should == 0.5
27
34
  @space.write([:y, 0.6])
28
- @it.get_unit(:x).should == 0.6
35
+ @it.get_unit(:y).should == 0.6
29
36
  end
30
37
 
31
38
  it "gets keys from a backup factory when it cannot retrieve values via Rinda" do
@@ -36,4 +43,4 @@ describe RindaFactory do
36
43
  @it.get_unit(:a).should == 0.74
37
44
  end
38
45
 
39
- end
46
+ end
@@ -15,7 +15,6 @@ describe SineFactory do
15
15
 
16
16
  it "loops between 0 and 1" do
17
17
  @it.interval = 1.0
18
- # @it.get_unit(:x).should be_close(0.500, MARGIN)
19
18
  @it.get_unit(:x).should be_close(0.920, MARGIN)
20
19
  @it.get_unit(:x).should be_close(0.954, MARGIN)
21
20
  @it.get_unit(:x).should be_close(0.570, MARGIN)
@@ -26,7 +25,6 @@ describe SineFactory do
26
25
 
27
26
  it "can take a different interval" do
28
27
  @it.interval = 0.5
29
- # @it.get_unit(:x).should be_close(0.500, MARGIN)
30
28
  @it.get_unit(:x).should be_close(0.740, MARGIN)
31
29
  @it.get_unit(:x).should be_close(0.920, MARGIN)
32
30
  end
@@ -73,6 +73,5 @@ shared_examples_for "a factory" do
73
73
  end
74
74
  end
75
75
  end
76
-
77
-
76
+
78
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyonacid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay McGavren
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-03 00:00:00 -07:00
12
+ date: 2009-12-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,19 +41,24 @@ files:
41
41
  - examples/midi.rb
42
42
  - examples/raw_audio.rb
43
43
  - examples/rinda_agent.rb
44
+ - examples/svg.rb
44
45
  - examples/wxruby.rb
45
46
  - features/rubyonacid.feature
46
47
  - features/step_definitions/rubyonacid_steps.rb
47
48
  - features/support/env.rb
48
49
  - generators.png
49
50
  - lib/rubyonacid.rb
51
+ - lib/rubyonacid/factories/all.rb
50
52
  - lib/rubyonacid/factories/combination.rb
51
53
  - lib/rubyonacid/factories/constant.rb
54
+ - lib/rubyonacid/factories/example.rb
52
55
  - lib/rubyonacid/factories/flash.rb
53
56
  - lib/rubyonacid/factories/increment.rb
57
+ - lib/rubyonacid/factories/input.rb
54
58
  - lib/rubyonacid/factories/loop.rb
55
59
  - lib/rubyonacid/factories/meta.rb
56
60
  - lib/rubyonacid/factories/random.rb
61
+ - lib/rubyonacid/factories/random_walk.rb
57
62
  - lib/rubyonacid/factories/repeat.rb
58
63
  - lib/rubyonacid/factories/rinda.rb
59
64
  - lib/rubyonacid/factories/sine.rb
@@ -63,9 +68,11 @@ files:
63
68
  - spec/factories/constant_spec.rb
64
69
  - spec/factories/flash_spec.rb
65
70
  - spec/factories/increment_spec.rb
71
+ - spec/factories/input_spec.rb
66
72
  - spec/factories/loop_spec.rb
67
73
  - spec/factories/meta_spec.rb
68
74
  - spec/factories/random_spec.rb
75
+ - spec/factories/random_walk_spec.rb
69
76
  - spec/factories/repeat_spec.rb
70
77
  - spec/factories/rinda_spec.rb
71
78
  - spec/factories/sine_spec.rb
@@ -106,9 +113,11 @@ test_files:
106
113
  - spec/factories/constant_spec.rb
107
114
  - spec/factories/flash_spec.rb
108
115
  - spec/factories/increment_spec.rb
116
+ - spec/factories/input_spec.rb
109
117
  - spec/factories/loop_spec.rb
110
118
  - spec/factories/meta_spec.rb
111
119
  - spec/factories/random_spec.rb
120
+ - spec/factories/random_walk_spec.rb
112
121
  - spec/factories/repeat_spec.rb
113
122
  - spec/factories/rinda_spec.rb
114
123
  - spec/factories/sine_spec.rb
@@ -118,9 +127,7 @@ test_files:
118
127
  - spec/spec_helper.rb
119
128
  - examples/ascii.rb
120
129
  - examples/midi.rb
121
- - examples/permutations.rb
122
- - examples/quality_render.rb
123
- - examples/random_yaml.rb
124
130
  - examples/raw_audio.rb
125
131
  - examples/rinda_agent.rb
132
+ - examples/svg.rb
126
133
  - examples/wxruby.rb
@@ -1,40 +0,0 @@
1
- require 'rubygems'
2
- require 'rubyonacid/factories/meta'
3
- require 'rubyonacid/factories/flash'
4
- require 'rubyonacid/factories/increment'
5
- require 'rubyonacid/factories/loop'
6
- require 'rubyonacid/factories/random'
7
- require 'rubyonacid/factories/sine'
8
- require 'rubyonacid/factories/skip'
9
-
10
- factories = []
11
- factories << RubyOnAcid::LoopFactory.new(0.001)
12
- factories << RubyOnAcid::LoopFactory.new(-0.001)
13
- factories << RubyOnAcid::LoopFactory.new(0.01)
14
- factories << RubyOnAcid::LoopFactory.new(-0.01)
15
- factories << RubyOnAcid::LoopFactory.new(0.1)
16
- factories << RubyOnAcid::LoopFactory.new(-0.1)
17
- factories << RubyOnAcid::IncrementFactory.new(0.001)
18
- factories << RubyOnAcid::RandomFactory.new
19
- factories << RubyOnAcid::FlashFactory.new(1)
20
- factories << RubyOnAcid::FlashFactory.new(3)
21
- factories << RubyOnAcid::FlashFactory.new(50)
22
- factories << RubyOnAcid::FlashFactory.new(100)
23
- factories << RubyOnAcid::SineFactory.new(0.1)
24
- factories << RubyOnAcid::SineFactory.new(-0.1)
25
- factories << RubyOnAcid::SineFactory.new(0.01)
26
- factories << RubyOnAcid::SineFactory.new(-0.01)
27
- factories << RubyOnAcid::SineFactory.new(0.001)
28
- factories << RubyOnAcid::SineFactory.new(-0.001)
29
-
30
- keys = [:red, :green, :blue, :alpha, :width, :x, :y, :x2, :y2]
31
-
32
- factories.permutation(keys.length).each_with_index do |permutation, i|
33
- meta_factory = RubyOnAcid::MetaFactory.new
34
- keys.each do |key|
35
- meta_factory.assign_factory(key, permutation.shift)
36
- end
37
- File.open(sprintf('%05d.yml', i), "w") do |file|
38
- YAML.dump(meta_factory, file)
39
- end
40
- end
@@ -1,46 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'wxruby.rb')
2
-
3
-
4
-
5
- class MyApp
6
-
7
- WIDTH = 1920
8
- HEIGHT = 1080
9
-
10
- def on_init
11
-
12
- ARGV.each do |file_name|
13
-
14
- puts "Processing #{file_name}"
15
-
16
- @f = YAML.load_file(file_name)
17
-
18
- frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
19
-
20
-
21
- #Displays drawing.
22
- bitmap = Wx::Bitmap.new(WIDTH, HEIGHT)
23
- bitmap.draw do |surface|
24
- surface.brush = Wx::BLACK_BRUSH
25
- surface.draw_rectangle(0, 0, WIDTH, HEIGHT)
26
- end
27
- 10000.times do
28
- bitmap.draw {|surface| render(surface)}
29
- end
30
- bitmap.draw do |surface|
31
- surface.text_foreground = Wx::Colour.new(255, 255, 255, 255)
32
- surface.draw_text("©2009 Jay McGavren. Licensed under a Creative Commons Attribution-Share Alike 3.0 United States License: http://creativecommons.org/licenses/by-sa/3.0/us/", 10, HEIGHT - 20)
33
- end
34
-
35
- bitmap.save_file(file_name + ".png", Wx::BITMAP_TYPE_PNG)
36
-
37
- end
38
-
39
- exit
40
-
41
- end
42
-
43
- end
44
-
45
- app = MyApp.new
46
- app.main_loop
@@ -1,51 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'wxruby.rb')
2
-
3
-
4
- class MyApp
5
-
6
- WIDTH = 320
7
- HEIGHT = 320
8
-
9
- def on_init
10
-
11
- (1..1000).each do |file_number|
12
-
13
- file_name = sprintf("%05d_random.jpg", file_number)
14
-
15
- @f = create_factory
16
-
17
- frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
18
-
19
- bitmap = Wx::Bitmap.new(WIDTH, HEIGHT)
20
- bitmap.draw do |surface|
21
- surface.brush = Wx::BLACK_BRUSH
22
- surface.draw_rectangle(0, 0, WIDTH, HEIGHT)
23
- end
24
- 10000.times do
25
- bitmap.draw {|surface| render(surface)}
26
- end
27
- bitmap.draw do |surface|
28
- surface.text_foreground = Wx::Colour.new(255, 255, 255, 255)
29
- y = 0
30
- @f.to_yaml.split("\n").each do |line|
31
- surface.draw_text(line, 0, y)
32
- y += 10
33
- end
34
- end
35
-
36
- File.open(file_name + ".yml", "w") do |file|
37
- YAML.dump(@f, file)
38
- end
39
-
40
- bitmap.save_file(file_name, Wx::BITMAP_TYPE_JPEG)
41
-
42
- end
43
-
44
- exit
45
-
46
- end
47
-
48
- end
49
-
50
- app = MyApp.new
51
- app.main_loop