rubyonacid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +6 -0
  2. data/LICENSE +20 -0
  3. data/README.textile +21 -0
  4. data/Rakefile +63 -0
  5. data/VERSION +1 -0
  6. data/examples/midi.rb +57 -0
  7. data/examples/permutations.rb +40 -0
  8. data/examples/raw_audio.rb +54 -0
  9. data/examples/rinda_agent.rb +81 -0
  10. data/examples/rmagick.rb +59 -0
  11. data/examples/test.rb +95 -0
  12. data/examples/test2.rb +85 -0
  13. data/examples/test3.rb +108 -0
  14. data/features/rubyonacid.feature +9 -0
  15. data/features/step_definitions/rubyonacid_steps.rb +0 -0
  16. data/features/support/env.rb +4 -0
  17. data/lib/rubyonacid/factories/constant.rb +25 -0
  18. data/lib/rubyonacid/factories/flash.rb +32 -0
  19. data/lib/rubyonacid/factories/increment.rb +32 -0
  20. data/lib/rubyonacid/factories/loop.rb +30 -0
  21. data/lib/rubyonacid/factories/meta.rb +31 -0
  22. data/lib/rubyonacid/factories/modulo.rb +25 -0
  23. data/lib/rubyonacid/factories/random.rb +15 -0
  24. data/lib/rubyonacid/factories/repeat.rb +35 -0
  25. data/lib/rubyonacid/factories/rinda.rb +40 -0
  26. data/lib/rubyonacid/factories/sine.rb +24 -0
  27. data/lib/rubyonacid/factories/skip.rb +23 -0
  28. data/lib/rubyonacid/factory.rb +29 -0
  29. data/lib/rubyonacid.rb +0 -0
  30. data/spec/generators/constant_spec.rb +24 -0
  31. data/spec/generators/flash_spec.rb +49 -0
  32. data/spec/generators/increment_spec.rb +43 -0
  33. data/spec/generators/loop_spec.rb +43 -0
  34. data/spec/generators/meta_spec.rb +20 -0
  35. data/spec/generators/modulo_spec.rb +33 -0
  36. data/spec/generators/random_spec.rb +20 -0
  37. data/spec/generators/repeat_spec.rb +37 -0
  38. data/spec/generators/rinda_spec.rb +32 -0
  39. data/spec/generators/sine_spec.rb +43 -0
  40. data/spec/generators/skip_spec.rb +25 -0
  41. data/spec/shared_factory_specs.rb +79 -0
  42. data/spec/spec_helper.rb +9 -0
  43. metadata +122 -0
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ log
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jay McGavren
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,21 @@
1
+ !http://github.com/jaymcgavren/rubyonacid/raw/master/generators.png!
2
+
3
+ h1. Ruby On Acid
4
+
5
+ A Ruby library for making trippy visuals.
6
+
7
+
8
+ h1. Factories
9
+
10
+ The factory is the core concept of Ruby On Acid. You create a factory of a particular type, and then anywhere in your code that you need a value within a certain range, you get it from the factory. For example, if you need x and y coordinates for drawing on a 800 x 600 window, you would tell a factory that you need a value for :x from 0 to 800, and a value for :y from 0 to 600. If you later wanted to change drawing patterns, you could simply swap out factories.
11
+
12
+
13
+ h1. Roadmap
14
+
15
+ * A factory that evaluates the last value for 2 keys and modifies a third based on them. (Example, change the size of rectangles based on their x and y coordinates.
16
+ * Skip Factory: Add probability matrix [0.5, 0.9, 0.1...] that causes get_unit() to return true every time rand() is > given value. Also add mask value (0.1, 0.9), etc, that is added to random value to increase likelihood of returning true.
17
+
18
+
19
+ h1. Copyright
20
+
21
+ Copyright (c) 2009 Jay McGavren. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rubyonacid"
8
+ gem.summary = %Q{A framework for creating trippy visuals}
9
+ gem.description = %Q{A framework for creating trippy visuals}
10
+ gem.email = "jay@mcgavren.com"
11
+ gem.homepage = "http://github.com/jaymcgavren/rubyonacid"
12
+ gem.authors = ["Jay McGavren"]
13
+ gem.rubyforge_project = "rubyonacid"
14
+ gem.add_development_dependency "rspec"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::RubyforgeTasks.new do |rubyforge|
18
+ rubyforge.doc_task = "rdoc"
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ begin
39
+ require 'cucumber/rake/task'
40
+ Cucumber::Rake::Task.new(:features)
41
+
42
+ task :features => :check_dependencies
43
+ rescue LoadError
44
+ task :features do
45
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
46
+ end
47
+ end
48
+
49
+ task :default => :spec
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ if File.exist?('VERSION')
54
+ version = File.read('VERSION')
55
+ else
56
+ version = ""
57
+ end
58
+
59
+ rdoc.rdoc_dir = 'rdoc'
60
+ rdoc.title = "rubyonacid #{version}"
61
+ rdoc.rdoc_files.include('README*')
62
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/examples/midi.rb ADDED
@@ -0,0 +1,57 @@
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/modulo'
7
+ require 'rubyonacid/factories/random'
8
+ require 'rubyonacid/factories/repeat'
9
+ require 'rubyonacid/factories/sine'
10
+ require 'rubyonacid/factories/skip'
11
+
12
+ random_factory = RubyOnAcid::RandomFactory.new
13
+
14
+ #The MetaFactory assigns factories to requested value types.
15
+ factory = RubyOnAcid::MetaFactory.new
16
+ #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
17
+ factory.factory_pool << RubyOnAcid::LoopFactory.new(0.01)
18
+ factory.factory_pool << RubyOnAcid::LoopFactory.new(-0.01)
19
+ factory.factory_pool << RubyOnAcid::LoopFactory.new(0.001)
20
+ factory.factory_pool << RubyOnAcid::LoopFactory.new(-0.001)
21
+ #Constant factories always return the same value,
22
+ factory.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
23
+ factory.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
24
+ factory.factory_pool << RubyOnAcid::FlashFactory.new(rand(100))
25
+ #Sine factories produce a "wave" pattern.
26
+ factory.factory_pool << RubyOnAcid::SineFactory.new(0.1)
27
+ factory.factory_pool << RubyOnAcid::SineFactory.new(-0.1)
28
+ factory.factory_pool << RubyOnAcid::SineFactory.new(0.01)
29
+ factory.factory_pool << RubyOnAcid::SineFactory.new(-0.01)
30
+ factory.factory_pool << RubyOnAcid::RepeatFactory.new(
31
+ RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
32
+ random_factory.within(:interval, 2, 100)
33
+ )
34
+ factory.factory_pool << RubyOnAcid::RepeatFactory.new(
35
+ RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
36
+ random_factory.within(:interval, 2, 100)
37
+ )
38
+ factory.factory_pool << RubyOnAcid::ModuloFactory.new(RubyOnAcid::LoopFactory.new(0.00001))
39
+
40
+ #A skip factory, in charge of randomly resetting the meta factory.
41
+ @resetter = RubyOnAcid::SkipFactory.new(0.999)
42
+
43
+
44
+ require 'midiator'
45
+
46
+ midi = MIDIator::Interface.new
47
+ midi.autodetect_driver
48
+
49
+ loop do
50
+ midi.play(
51
+ factory.within(:note, 10, 127).to_i,
52
+ factory.within(:duration, 0, 0.1),
53
+ factory.within(:channel, 0, 10).to_i,
54
+ factory.within(:velocity, 0, 127)
55
+ )
56
+ factory.reset_assignments if @resetter.boolean(:reset)
57
+ end
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,54 @@
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/modulo'
7
+ require 'rubyonacid/factories/random'
8
+ require 'rubyonacid/factories/repeat'
9
+ require 'rubyonacid/factories/sine'
10
+ require 'rubyonacid/factories/skip'
11
+
12
+ def generate_factories
13
+
14
+ random_factory = RubyOnAcid::RandomFactory.new
15
+
16
+ factory_pool = []
17
+
18
+ #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
19
+ factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.01, 0.01))
20
+ #Constant factories always return the same value,
21
+ factory_pool << RubyOnAcid::ConstantFactory.new(rand)
22
+ factory_pool << RubyOnAcid::ConstantFactory.new(rand)
23
+ factory_pool << RubyOnAcid::FlashFactory.new(rand(100))
24
+ #Sine factories produce a "wave" pattern.
25
+ factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.01, 0.01))
26
+ factory_pool << RubyOnAcid::RepeatFactory.new(
27
+ RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
28
+ random_factory.within(:interval, 2, 100)
29
+ )
30
+ factory_pool << RubyOnAcid::RepeatFactory.new(
31
+ RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
32
+ random_factory.within(:interval, 2, 100)
33
+ )
34
+ factory_pool << RubyOnAcid::ModuloFactory.new(RubyOnAcid::LoopFactory.new(0.00001))
35
+ factory_pool
36
+ end
37
+
38
+ #A skip factory, in charge of randomly resetting the meta factory.
39
+ @resetter = RubyOnAcid::SkipFactory.new(0.99995)
40
+
41
+ factory = RubyOnAcid::MetaFactory.new
42
+ factory.factory_pool = generate_factories
43
+ File.open("raw_audio.dat", "w") do |file|
44
+ loop do
45
+ channel_count = factory.within(:chanel_count, 0, 3).to_i
46
+ channel_count.times do |i|
47
+ file.putc factory.within(i, 0, 255).to_i
48
+ end
49
+ if @resetter.boolean(:reset)
50
+ factory.factory_pool = generate_factories
51
+ factory.reset_assignments
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,81 @@
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/increment'
7
+ require 'rubyonacid/factories/loop'
8
+ require 'rubyonacid/factories/random'
9
+ require 'rubyonacid/factories/rinda'
10
+ require 'rubyonacid/factories/sine'
11
+ require 'rubyonacid/factories/skip'
12
+
13
+
14
+
15
+ class MyApp < Wx::App
16
+
17
+ WIDTH = 480
18
+ HEIGHT = 480
19
+
20
+ def on_init
21
+
22
+ #The MetaFactory assigns factories to requested value types.
23
+ @f = RubyOnAcid::MetaFactory.new
24
+ #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
25
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(0.01)
26
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(-0.01)
27
+ #Random factories generate random values.
28
+ # @f.factory_pool << RubyOnAcid::RandomFactory.new
29
+ #Constant factories always return the same value,
30
+ @f.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
31
+ #Sine factories produce a "wave" pattern.
32
+ @f.factory_pool << RubyOnAcid::SineFactory.new(0.1)
33
+ @f.factory_pool << RubyOnAcid::SineFactory.new(-0.1)
34
+
35
+ rinda_factory = RubyOnAcid::RindaFactory.new(ARGV[0])
36
+ rinda_factory.start_service
37
+ @f.assign_factory(:x, rinda_factory)
38
+ @f.assign_factory(:y, rinda_factory)
39
+
40
+ #A skip factory, in charge of randomly resetting the meta factory.
41
+ @resetter = RubyOnAcid::SkipFactory.new(0.999)
42
+
43
+ #Containing frame.
44
+ frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
45
+ frame.show
46
+
47
+ #Displays drawing.
48
+ window = Wx::Window.new(frame, :size => [WIDTH, HEIGHT])
49
+
50
+ #Animate periodically.
51
+ t = Wx::Timer.new(self, 55)
52
+ evt_timer(55) {animate(window)}
53
+ t.start(33)
54
+
55
+ end
56
+
57
+ def animate(window)
58
+ window.paint do |surface|
59
+ surface.pen = Wx::Pen.new(
60
+ Wx::Colour.new(
61
+ @f.within(:red, 0, 255).to_i,
62
+ @f.within(:green, 0, 255).to_i,
63
+ @f.within(:blue, 0, 255).to_i,
64
+ @f.within(:alpha, 50, 255).to_i
65
+ ),
66
+ @f.within(:width, 1, 5).to_i
67
+ )
68
+ surface.draw_line(
69
+ @f.within(:x, 0, WIDTH).to_i,
70
+ @f.within(:y, 0, HEIGHT).to_i,
71
+ @f.within(:x2, 0, WIDTH).to_i,
72
+ @f.within(:y2, 0, HEIGHT).to_i
73
+ )
74
+ end
75
+ # @f.reset_assignments if @resetter.boolean(:reset)
76
+ end
77
+
78
+ end
79
+
80
+ app = MyApp.new
81
+ app.main_loop
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'RMagick'
5
+
6
+ require 'rubyonacid/factories/meta'
7
+ require 'rubyonacid/factories/flash'
8
+ require 'rubyonacid/factories/increment'
9
+ require 'rubyonacid/factories/loop'
10
+ require 'rubyonacid/factories/random'
11
+ require 'rubyonacid/factories/sine'
12
+ require 'rubyonacid/factories/skip'
13
+
14
+ @f = RubyOnAcid::MetaFactory.new
15
+ @f.factories << RubyOnAcid::LoopFactory.new
16
+ @f.factories << RubyOnAcid::FlashFactory.new
17
+ # @f.factories << RubyOnAcid::RandomFactory.new
18
+ @f.factories << RubyOnAcid::SineFactory.new
19
+ @f.factories << RubyOnAcid::SkipFactory.new
20
+
21
+ def get(key)
22
+ @f.within(key, 1, key.to_i)
23
+ end
24
+
25
+ canvas = Magick::Image.new(240, 300,
26
+ Magick::HatchFill.new('white','lightcyan2'))
27
+ gc = Magick::Draw.new
28
+
29
+ while RubyOnAcid::SkipFactory.new(0.001).boolean(:continue_loop)
30
+
31
+ # Draw ellipse
32
+ gc.stroke('red')
33
+ gc.stroke_width(get(10))
34
+ gc.fill_opacity(0)
35
+ gc.ellipse(get(120), get(150), get(80), get(120), 0, get(270))
36
+
37
+ # Draw endpoints
38
+ gc.stroke('gray50')
39
+ gc.stroke_width(get(1))
40
+ gc.circle(120, 150, 124, 150)
41
+ gc.circle(200, 150, 204, 150)
42
+ gc.circle(120, 30, 124, 30)
43
+
44
+ # Draw lines
45
+ gc.line(get(120), get(150), get(200), get(150))
46
+ gc.line(get(120), get(150), get(120), get(30))
47
+
48
+ # Annotate
49
+ gc.stroke('transparent')
50
+ gc.fill('black')
51
+ gc.text(130, 35, "End")
52
+ gc.text(188, 135, "Start")
53
+ gc.text(130, 95, "'Height=#{get(120)}'")
54
+ gc.text(55, 155, "'Width=#{get(80)}'")
55
+
56
+ end
57
+
58
+ gc.draw(canvas)
59
+ canvas.write('shapes2.gif')
data/examples/test.rb ADDED
@@ -0,0 +1,95 @@
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/modulo'
8
+ require 'rubyonacid/factories/random'
9
+ require 'rubyonacid/factories/repeat'
10
+ require 'rubyonacid/factories/sine'
11
+ require 'rubyonacid/factories/skip'
12
+
13
+
14
+
15
+ class MyApp < Wx::App
16
+
17
+ WIDTH = 480
18
+ HEIGHT = 480
19
+
20
+ def on_init
21
+
22
+ random_factory = RubyOnAcid::RandomFactory.new
23
+
24
+ #The MetaFactory assigns factories to requested value types.
25
+ @f = RubyOnAcid::MetaFactory.new
26
+ #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
27
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(0.01)
28
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(-0.01)
29
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(0.001)
30
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(-0.001)
31
+ #Constant factories always return the same value,
32
+ @f.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
33
+ @f.factory_pool << RubyOnAcid::ConstantFactory.new(rand)
34
+ @f.factory_pool << RubyOnAcid::FlashFactory.new(rand(100))
35
+ #Sine factories produce a "wave" pattern.
36
+ @f.factory_pool << RubyOnAcid::SineFactory.new(0.1)
37
+ @f.factory_pool << RubyOnAcid::SineFactory.new(-0.1)
38
+ @f.factory_pool << RubyOnAcid::SineFactory.new(0.01)
39
+ @f.factory_pool << RubyOnAcid::SineFactory.new(-0.01)
40
+ @f.factory_pool << RubyOnAcid::RepeatFactory.new(
41
+ RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
42
+ random_factory.within(:interval, 2, 100)
43
+ )
44
+ # @f.factory_pool << RubyOnAcid::RepeatFactory.new(
45
+ # RubyOnAcid::RandomFactory.new,
46
+ # random_factory.within(:interval, 2, 1000)
47
+ # )
48
+ @f.factory_pool << RubyOnAcid::RepeatFactory.new(
49
+ RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
50
+ random_factory.within(:interval, 2, 100)
51
+ )
52
+ @f.factory_pool << RubyOnAcid::ModuloFactory.new(RubyOnAcid::LoopFactory.new(0.00001))
53
+
54
+ #A skip factory, in charge of randomly resetting the meta factory.
55
+ @resetter = RubyOnAcid::SkipFactory.new(0.9999)
56
+
57
+ #Containing frame.
58
+ frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
59
+ frame.show
60
+
61
+ #Displays drawing.
62
+ window = Wx::Window.new(frame, :size => [WIDTH, HEIGHT])
63
+
64
+ #Animate periodically.
65
+ t = Wx::Timer.new(self, 55)
66
+ evt_timer(55) {animate(window)}
67
+ t.start(33)
68
+
69
+ end
70
+
71
+ def animate(window)
72
+ window.paint do |surface|
73
+ surface.pen = Wx::Pen.new(
74
+ Wx::Colour.new(
75
+ @f.within(:red, 0, 255).to_i,
76
+ @f.within(:green, 0, 255).to_i,
77
+ @f.within(:blue, 0, 255).to_i,
78
+ @f.within(:alpha, 50, 255).to_i
79
+ ),
80
+ @f.within(:width, 1, 5).to_i
81
+ )
82
+ surface.draw_line(
83
+ @f.within(:x, 0, WIDTH).to_i,
84
+ @f.within(:y, 0, HEIGHT).to_i,
85
+ @f.within(:x2, 0, WIDTH).to_i,
86
+ @f.within(:y2, 0, HEIGHT).to_i
87
+ )
88
+ end
89
+ @f.reset_assignments if @resetter.boolean(:reset)
90
+ end
91
+
92
+ end
93
+
94
+ app = MyApp.new
95
+ app.main_loop
data/examples/test2.rb ADDED
@@ -0,0 +1,85 @@
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/increment'
7
+ require 'rubyonacid/factories/loop'
8
+ require 'rubyonacid/factories/modulo'
9
+ require 'rubyonacid/factories/random'
10
+ require 'rubyonacid/factories/repeat'
11
+ require 'rubyonacid/factories/sine'
12
+ require 'rubyonacid/factories/skip'
13
+
14
+
15
+
16
+ class MyApp < Wx::App
17
+
18
+ WIDTH = 1920
19
+ HEIGHT = 1080
20
+
21
+ def on_init
22
+
23
+ ARGV.each do |file_name|
24
+
25
+ puts "Processing #{file_name}"
26
+
27
+ @f = YAML.load_file(file_name)
28
+
29
+ frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
30
+
31
+
32
+ #Displays drawing.
33
+ bitmap = Wx::Bitmap.new(WIDTH, HEIGHT)
34
+ bitmap.draw do |surface|
35
+ # surface.pen = black_pen
36
+ surface.brush = Wx::BLACK_BRUSH
37
+ surface.draw_rectangle(0, 0, WIDTH, HEIGHT)
38
+ end
39
+ 1000.times do
40
+ bitmap.draw {|surface| render(surface)}
41
+ end
42
+ # bitmap.draw do |surface|
43
+ # surface.text_foreground = Wx::Colour.new(255, 255, 255, 255)
44
+ # # surface.text_background = Wx::Colour.new(0, 0, 0)
45
+ # y = 0
46
+ # @f.to_yaml.split("\n").each do |line|
47
+ # surface.draw_text(line, 0, y)
48
+ # y += 10
49
+ # end
50
+ # end
51
+ bitmap.draw do |surface|
52
+ surface.text_foreground = Wx::Colour.new(255, 255, 255, 255)
53
+ 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)
54
+ end
55
+
56
+ bitmap.save_file(file_name + ".png", Wx::BITMAP_TYPE_PNG)
57
+
58
+ end
59
+
60
+ exit
61
+
62
+ end
63
+
64
+ def render(surface)
65
+ surface.pen = Wx::Pen.new(
66
+ Wx::Colour.new(
67
+ @f.within(:red, 0, 255).to_i,
68
+ @f.within(:green, 0, 255).to_i,
69
+ @f.within(:blue, 0, 255).to_i,
70
+ @f.within(:alpha, 50, 100).to_i
71
+ ),
72
+ @f.within(:width, 1, 5).to_i
73
+ )
74
+ surface.draw_line(
75
+ @f.within(:x, 0, WIDTH).to_i,
76
+ @f.within(:y, 0, HEIGHT).to_i,
77
+ @f.within(:x2, 0, WIDTH).to_i,
78
+ @f.within(:y2, 0, HEIGHT).to_i
79
+ )
80
+ end
81
+
82
+ end
83
+
84
+ app = MyApp.new
85
+ app.main_loop