rubyonacid 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +74 -6
- data/VERSION +1 -1
- data/examples/ascii.rb +45 -0
- data/examples/midi.rb +0 -2
- data/examples/quality_render.rb +46 -0
- data/examples/random_yaml.rb +51 -0
- data/examples/raw_audio.rb +0 -2
- data/examples/rinda_agent.rb +101 -38
- data/examples/wxruby.rb +158 -0
- data/generators.png +0 -0
- data/lib/rubyonacid/factories/combination.rb +66 -0
- data/lib/rubyonacid/factories/increment.rb +3 -2
- data/lib/rubyonacid/factories/loop.rb +1 -0
- data/lib/rubyonacid/factories/rinda.rb +9 -2
- data/lib/rubyonacid/factory.rb +9 -0
- data/spec/factories/combination_spec.rb +101 -0
- data/spec/{generators → factories}/constant_spec.rb +0 -1
- data/spec/{generators → factories}/flash_spec.rb +0 -0
- data/spec/{generators → factories}/increment_spec.rb +0 -1
- data/spec/{generators → factories}/loop_spec.rb +0 -1
- data/spec/{generators → factories}/meta_spec.rb +0 -0
- data/spec/{generators → factories}/random_spec.rb +0 -0
- data/spec/{generators → factories}/repeat_spec.rb +0 -0
- data/spec/{generators → factories}/rinda_spec.rb +8 -1
- data/spec/{generators → factories}/sine_spec.rb +0 -1
- data/spec/{generators → factories}/skip_spec.rb +0 -1
- data/spec/factory_spec.rb +59 -0
- data/spec/spec_helper.rb +3 -0
- metadata +35 -31
- data/examples/rmagick.rb +0 -59
- data/examples/test.rb +0 -95
- data/examples/test2.rb +0 -85
- data/examples/test3.rb +0 -108
- data/lib/rubyonacid/factories/modulo.rb +0 -25
- data/spec/generators/modulo_spec.rb +0 -33
@@ -5,9 +5,11 @@ module RubyOnAcid
|
|
5
5
|
|
6
6
|
class RindaFactory < Factory
|
7
7
|
|
8
|
-
#Time in seconds to wait for a value before giving up and returning
|
8
|
+
#Time in seconds to wait for a value before giving up and returning a default value for the given key.
|
9
9
|
#Default is 0, which will return immediately.
|
10
10
|
attr_accessor :timeout
|
11
|
+
#A factory to pull requests from if retrieval of values via Rinda times out.
|
12
|
+
attr_accessor :default_factory
|
11
13
|
#The URI to connect to. Default is "druby://127.0.0.1:7632" (7632 == RNDA).
|
12
14
|
attr_accessor :uri
|
13
15
|
|
@@ -15,6 +17,7 @@ class RindaFactory < Factory
|
|
15
17
|
super
|
16
18
|
@uri = uri
|
17
19
|
@timeout = timeout
|
20
|
+
@default_factory = nil
|
18
21
|
@prior_values = {}
|
19
22
|
end
|
20
23
|
|
@@ -30,7 +33,11 @@ class RindaFactory < Factory
|
|
30
33
|
key, value = @space.take([key, Float], @timeout)
|
31
34
|
@prior_values[key] = value
|
32
35
|
rescue Rinda::RequestExpiredError => exception
|
33
|
-
|
36
|
+
if @default_factory
|
37
|
+
value = @default_factory.get_unit(key)
|
38
|
+
else
|
39
|
+
value = @prior_values[key]
|
40
|
+
end
|
34
41
|
end
|
35
42
|
value
|
36
43
|
end
|
data/lib/rubyonacid/factory.rb
CHANGED
@@ -24,6 +24,15 @@ class Factory
|
|
24
24
|
get_unit(key) >= 0.5
|
25
25
|
end
|
26
26
|
|
27
|
+
#Calls get_unit with key to get value between 0.0 and 1.0, then converts that value to an index within the given list of choices.
|
28
|
+
#choices can be an array or an argument list of arbitrary size.
|
29
|
+
def choose(key, *choices)
|
30
|
+
all_choices = choices.flatten
|
31
|
+
index = (get_unit(key) * all_choices.length).floor
|
32
|
+
index = all_choices.length - 1 if index > all_choices.length - 1
|
33
|
+
all_choices[index]
|
34
|
+
end
|
35
|
+
|
27
36
|
end
|
28
37
|
|
29
38
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
require "rubyonacid/factories/combination"
|
3
|
+
require "shared_factory_specs"
|
4
|
+
|
5
|
+
include RubyOnAcid
|
6
|
+
|
7
|
+
describe CombinationFactory do
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@it = CombinationFactory.new
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "general behavior" do
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
@it.source_factories << mock('Factory', :get_unit => 0.2)
|
17
|
+
@it.source_factories << mock('Factory', :get_unit => 0.3)
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_behave_like "a factory"
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#get_unit" do
|
25
|
+
|
26
|
+
it "retrieves values from source factories and adds them together" do
|
27
|
+
@it.source_factories << mock('Factory', :get_unit => 0.2)
|
28
|
+
@it.source_factories << mock('Factory', :get_unit => 0.3)
|
29
|
+
@it.get_unit(:x).should be_close(0.5, MARGIN)
|
30
|
+
@it.source_factories << mock('Factory', :get_unit => 0.1)
|
31
|
+
@it.get_unit(:x).should be_close(0.6, MARGIN)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can constrain sum to 0.0 through 1.0" do
|
35
|
+
@it.constrain_mode = CombinationFactory::CONSTRAIN
|
36
|
+
@it.source_factories << mock('Factory', :get_unit => 0.2)
|
37
|
+
@it.source_factories << mock('Factory', :get_unit => 0.3)
|
38
|
+
@it.source_factories << mock('Factory', :get_unit => 0.7)
|
39
|
+
@it.get_unit(:x).should be_close(1.0, MARGIN)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "uses wrap mode by default" do
|
43
|
+
@it.source_factories << mock('Factory', :get_unit => 0.4)
|
44
|
+
@it.source_factories << mock('Factory', :get_unit => 0.7)
|
45
|
+
@it.get_unit(:x).should be_close(0.1, MARGIN)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can wrap > 1.0 value around" do
|
49
|
+
@it.constrain_mode = CombinationFactory::WRAP
|
50
|
+
@it.source_factories << mock('Factory', :get_unit => 0.2)
|
51
|
+
@it.source_factories << mock('Factory', :get_unit => 0.3)
|
52
|
+
@it.source_factories << mock('Factory', :get_unit => 0.7)
|
53
|
+
@it.get_unit(:x).should be_close(0.2, MARGIN)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "subtraction" do
|
59
|
+
|
60
|
+
it "can subtract values from source factories" do
|
61
|
+
@it.operation = CombinationFactory::SUBTRACT
|
62
|
+
@it.source_factories << mock('Factory', :get_unit => 0.7)
|
63
|
+
@it.source_factories << mock('Factory', :get_unit => 0.3)
|
64
|
+
@it.get_unit(:x).should be_close(0.4, MARGIN)
|
65
|
+
@it.source_factories << mock('Factory', :get_unit => 0.1)
|
66
|
+
@it.get_unit(:x).should be_close(0.3, MARGIN)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "can wrap < 0.0 value around" do
|
70
|
+
@it.operation = CombinationFactory::SUBTRACT
|
71
|
+
@it.constrain_mode = CombinationFactory::WRAP
|
72
|
+
@it.source_factories << mock('Factory', :get_unit => 0.5)
|
73
|
+
@it.source_factories << mock('Factory', :get_unit => 0.7)
|
74
|
+
@it.get_unit(:x).should be_close(0.8, MARGIN)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "multiplication" do
|
80
|
+
it "can get product of values from source factories" do
|
81
|
+
@it.operation = CombinationFactory::MULTIPLY
|
82
|
+
@it.source_factories << mock('Factory', :get_unit => 0.7)
|
83
|
+
@it.source_factories << mock('Factory', :get_unit => 0.5)
|
84
|
+
@it.get_unit(:x).should be_close(0.35, MARGIN)
|
85
|
+
@it.source_factories << mock('Factory', :get_unit => 0.1)
|
86
|
+
@it.get_unit(:x).should be_close(0.035, MARGIN)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "division" do
|
91
|
+
it "can divide values from source factories" do
|
92
|
+
@it.operation = CombinationFactory::DIVIDE
|
93
|
+
@it.source_factories << mock('Factory', :get_unit => 0.1)
|
94
|
+
@it.source_factories << mock('Factory', :get_unit => 0.2)
|
95
|
+
@it.get_unit(:x).should be_close(0.5, MARGIN) #0.1 / 0.2 = 0.5
|
96
|
+
@it.source_factories << mock('Factory', :get_unit => 0.9)
|
97
|
+
@it.get_unit(:x).should be_close(0.555, MARGIN) #0.5 / 0.9 = 0.5555...
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -6,7 +6,6 @@ include RubyOnAcid
|
|
6
6
|
|
7
7
|
describe RindaFactory do
|
8
8
|
|
9
|
-
MARGIN = 0.01
|
10
9
|
|
11
10
|
before :each do
|
12
11
|
@it = RindaFactory.new
|
@@ -29,4 +28,12 @@ describe RindaFactory do
|
|
29
28
|
@it.get_unit(:x).should == 0.6
|
30
29
|
end
|
31
30
|
|
31
|
+
it "gets keys from a backup factory when it cannot retrieve values via Rinda" do
|
32
|
+
@it.start_service
|
33
|
+
default_factory = mock('Factory')
|
34
|
+
default_factory.stub!(:get_unit).and_return(0.74)
|
35
|
+
@it.default_factory = default_factory
|
36
|
+
@it.get_unit(:a).should == 0.74
|
37
|
+
end
|
38
|
+
|
32
39
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require "shared_factory_specs"
|
3
|
+
require 'rubyonacid/factories/constant'
|
4
|
+
|
5
|
+
include RubyOnAcid
|
6
|
+
|
7
|
+
describe Factory do
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@it = ConstantFactory.new
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#choose" do
|
14
|
+
|
15
|
+
it "chooses an item from a list" do
|
16
|
+
@it.stub!(:get_unit).and_return(0.0)
|
17
|
+
@it.choose(:color, :red, :green, :blue).should == :red
|
18
|
+
@it.stub!(:get_unit).and_return(1.0)
|
19
|
+
@it.choose(:color, :red, :green, :blue).should == :blue
|
20
|
+
@it.stub!(:get_unit).and_return(0.5)
|
21
|
+
@it.choose(:color, :red, :green, :blue).should == :green
|
22
|
+
end
|
23
|
+
|
24
|
+
it "matches a range of values for each list item" do
|
25
|
+
@it.stub!(:get_unit).and_return(0.0)
|
26
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :a
|
27
|
+
@it.stub!(:get_unit).and_return(0.24)
|
28
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :a
|
29
|
+
@it.stub!(:get_unit).and_return(0.25)
|
30
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :b
|
31
|
+
@it.stub!(:get_unit).and_return(0.49)
|
32
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :b
|
33
|
+
@it.stub!(:get_unit).and_return(0.5)
|
34
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :c
|
35
|
+
@it.stub!(:get_unit).and_return(0.74)
|
36
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :c
|
37
|
+
@it.stub!(:get_unit).and_return(0.75)
|
38
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :d
|
39
|
+
@it.stub!(:get_unit).and_return(1.0)
|
40
|
+
@it.choose(:foo, :a, :b, :c, :d).should == :d
|
41
|
+
end
|
42
|
+
|
43
|
+
it "accepts multiple arguments" do
|
44
|
+
@it.stub!(:get_unit).and_return(1.0)
|
45
|
+
@it.choose(:color, :red, :green, :blue).should == :blue
|
46
|
+
end
|
47
|
+
|
48
|
+
it "accepts arrays" do
|
49
|
+
@it.stub!(:get_unit).and_return(1.0)
|
50
|
+
@it.choose(:color, [:red, :green, :blue]).should == :blue
|
51
|
+
@it.stub!(:get_unit).and_return(1.0)
|
52
|
+
@it.choose(:color, [:red, :green, :blue], [:yellow, :orange]).should == :orange
|
53
|
+
@it.stub!(:get_unit).and_return(0.0)
|
54
|
+
@it.choose(:color, [:red, :green, :blue], [:yellow, :orange]).should == :red
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.2.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
|
+
date: 2009-12-03 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,37 +37,40 @@ files:
|
|
37
37
|
- README.textile
|
38
38
|
- Rakefile
|
39
39
|
- VERSION
|
40
|
+
- examples/ascii.rb
|
40
41
|
- examples/midi.rb
|
41
42
|
- examples/raw_audio.rb
|
42
|
-
- examples/
|
43
|
-
- examples/
|
43
|
+
- examples/rinda_agent.rb
|
44
|
+
- examples/wxruby.rb
|
44
45
|
- features/rubyonacid.feature
|
45
46
|
- features/step_definitions/rubyonacid_steps.rb
|
46
47
|
- features/support/env.rb
|
48
|
+
- generators.png
|
47
49
|
- lib/rubyonacid.rb
|
50
|
+
- lib/rubyonacid/factories/combination.rb
|
48
51
|
- lib/rubyonacid/factories/constant.rb
|
49
52
|
- lib/rubyonacid/factories/flash.rb
|
50
53
|
- lib/rubyonacid/factories/increment.rb
|
51
54
|
- lib/rubyonacid/factories/loop.rb
|
52
55
|
- lib/rubyonacid/factories/meta.rb
|
53
|
-
- lib/rubyonacid/factories/modulo.rb
|
54
56
|
- lib/rubyonacid/factories/random.rb
|
55
57
|
- lib/rubyonacid/factories/repeat.rb
|
56
58
|
- lib/rubyonacid/factories/rinda.rb
|
57
59
|
- lib/rubyonacid/factories/sine.rb
|
58
60
|
- lib/rubyonacid/factories/skip.rb
|
59
61
|
- lib/rubyonacid/factory.rb
|
60
|
-
- spec/
|
61
|
-
- spec/
|
62
|
-
- spec/
|
63
|
-
- spec/
|
64
|
-
- spec/
|
65
|
-
- spec/
|
66
|
-
- spec/
|
67
|
-
- spec/
|
68
|
-
- spec/
|
69
|
-
- spec/
|
70
|
-
- spec/
|
62
|
+
- spec/factories/combination_spec.rb
|
63
|
+
- spec/factories/constant_spec.rb
|
64
|
+
- spec/factories/flash_spec.rb
|
65
|
+
- spec/factories/increment_spec.rb
|
66
|
+
- spec/factories/loop_spec.rb
|
67
|
+
- spec/factories/meta_spec.rb
|
68
|
+
- spec/factories/random_spec.rb
|
69
|
+
- spec/factories/repeat_spec.rb
|
70
|
+
- spec/factories/rinda_spec.rb
|
71
|
+
- spec/factories/sine_spec.rb
|
72
|
+
- spec/factories/skip_spec.rb
|
73
|
+
- spec/factory_spec.rb
|
71
74
|
- spec/shared_factory_specs.rb
|
72
75
|
- spec/spec_helper.rb
|
73
76
|
has_rdoc: true
|
@@ -99,24 +102,25 @@ signing_key:
|
|
99
102
|
specification_version: 3
|
100
103
|
summary: A framework for creating trippy visuals
|
101
104
|
test_files:
|
102
|
-
- spec/
|
103
|
-
- spec/
|
104
|
-
- spec/
|
105
|
-
- spec/
|
106
|
-
- spec/
|
107
|
-
- spec/
|
108
|
-
- spec/
|
109
|
-
- spec/
|
110
|
-
- spec/
|
111
|
-
- spec/
|
112
|
-
- spec/
|
105
|
+
- spec/factories/combination_spec.rb
|
106
|
+
- spec/factories/constant_spec.rb
|
107
|
+
- spec/factories/flash_spec.rb
|
108
|
+
- spec/factories/increment_spec.rb
|
109
|
+
- spec/factories/loop_spec.rb
|
110
|
+
- spec/factories/meta_spec.rb
|
111
|
+
- spec/factories/random_spec.rb
|
112
|
+
- spec/factories/repeat_spec.rb
|
113
|
+
- spec/factories/rinda_spec.rb
|
114
|
+
- spec/factories/sine_spec.rb
|
115
|
+
- spec/factories/skip_spec.rb
|
116
|
+
- spec/factory_spec.rb
|
113
117
|
- spec/shared_factory_specs.rb
|
114
118
|
- spec/spec_helper.rb
|
119
|
+
- examples/ascii.rb
|
115
120
|
- examples/midi.rb
|
116
121
|
- examples/permutations.rb
|
122
|
+
- examples/quality_render.rb
|
123
|
+
- examples/random_yaml.rb
|
117
124
|
- examples/raw_audio.rb
|
118
125
|
- examples/rinda_agent.rb
|
119
|
-
- examples/
|
120
|
-
- examples/test.rb
|
121
|
-
- examples/test2.rb
|
122
|
-
- examples/test3.rb
|
126
|
+
- examples/wxruby.rb
|
data/examples/rmagick.rb
DELETED
@@ -1,59 +0,0 @@
|
|
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
DELETED
@@ -1,95 +0,0 @@
|
|
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.get(:x, :max => WIDTH).to_i,
|
84
|
-
@f.get(:y, :max => HEIGHT).to_i,
|
85
|
-
@f.get(:x2, :max => WIDTH).to_i,
|
86
|
-
@f.get(:y2, :max => 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
DELETED
@@ -1,85 +0,0 @@
|
|
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
|