rubyonacid 0.3.0 → 0.3.1

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/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
- log
6
+ log
7
+ rubyonacid.gemspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/examples/ascii.rb CHANGED
@@ -41,3 +41,7 @@ factories_to_combine = [
41
41
  RubyOnAcid::SineFactory.new(-0.2)
42
42
  ]
43
43
  make_lines RubyOnAcid::CombinationFactory.new(:source_factories => factories_to_combine)
44
+
45
+ #A RoundingFactory rounds values from a source factory to a multiple of a given number.
46
+ factory_to_round = RubyOnAcid::LoopFactory.new(0.1)
47
+ make_lines RubyOnAcid::RoundingFactory.new(factory_to_round, 0.25)
@@ -0,0 +1,23 @@
1
+ require 'rubyonacid/factories/all'
2
+
3
+ #This method takes any Factory and uses it to determine the length of lines to print.
4
+ def make_lines(factory)
5
+ #Show what factory we're working with.
6
+ puts factory.class.name
7
+ 1000.times do
8
+ #Get the length of the line.
9
+ #The :max option scales the returned length to be between 0 and 79.
10
+ line_length = factory.get(:length, :max => 79)
11
+ puts "|" * line_length
12
+ end
13
+ end
14
+
15
+ #A CombinationFactory combines the values of two or more other factories.
16
+ factories_to_combine = [
17
+ RubyOnAcid::SineFactory.new(0.2),
18
+ RubyOnAcid::SineFactory.new(-0.5)
19
+ ]
20
+ make_lines RubyOnAcid::CombinationFactory.new(
21
+ :source_factories => factories_to_combine,
22
+ :constrain_mode => RubyOnAcid::CombinationFactory::CONSTRAIN
23
+ )
@@ -54,28 +54,28 @@ class MyApp < Wx::App
54
54
  )
55
55
  when :line
56
56
  surface.draw_line(
57
- @f.get(:x0, :max => WIDTH).to_i,
58
- @f.get(:y0, :max => HEIGHT).to_i,
57
+ @f.get(:x, :max => WIDTH).to_i,
58
+ @f.get(:y, :max => HEIGHT).to_i,
59
59
  @f.get(:x1, :max => WIDTH).to_i,
60
60
  @f.get(:y1, :max => HEIGHT).to_i
61
61
  )
62
62
  when :rectangle
63
63
  surface.draw_rectangle(
64
- @f.get(:x0, :max => WIDTH).to_i,
65
- @f.get(:y0, :max => HEIGHT).to_i,
64
+ @f.get(:x, :max => WIDTH).to_i,
65
+ @f.get(:y, :max => HEIGHT).to_i,
66
66
  @f.get(:x1, :max => WIDTH).to_i,
67
67
  @f.get(:y1, :max => HEIGHT).to_i
68
68
  )
69
69
  when :circle
70
70
  surface.draw_circle(
71
- @f.get(:x0, :max => WIDTH).to_i,
72
- @f.get(:y0, :max => HEIGHT).to_i,
71
+ @f.get(:x, :max => WIDTH).to_i,
72
+ @f.get(:y, :max => HEIGHT).to_i,
73
73
  @f.get(:width, :max => WIDTH).to_i
74
74
  )
75
75
  when :arc
76
76
  surface.draw_elliptic_arc(
77
- @f.get(:x0, :max => WIDTH).to_i,
78
- @f.get(:y0, :max => HEIGHT).to_i,
77
+ @f.get(:x, :max => WIDTH).to_i,
78
+ @f.get(:y, :max => HEIGHT).to_i,
79
79
  @f.get(:width, :max => WIDTH).to_i,
80
80
  @f.get(:height, :max => HEIGHT).to_i,
81
81
  @f.get(:arc_start, :max => 360).to_i,
data/examples/tk.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubyonacid/factories/example'
2
+ require 'tk'
3
+
4
+ #This factory will be in charge of all drawing coordinates, colors, etc.
5
+ f = RubyOnAcid::ExampleFactory.new
6
+
7
+ #A skip factory, in charge of randomly resetting the meta factory.
8
+ resetter = RubyOnAcid::SkipFactory.new(0.999)
9
+
10
+ #The window to draw to.
11
+ canvas = TkCanvas.new(:width => 400, :height => 400)
12
+ canvas.pack
13
+
14
+ #The line objects we create will be stored here.
15
+ lines = []
16
+
17
+ #Create a thread to update the window while it's displayed.
18
+ Thread.new do
19
+ loop do
20
+
21
+ #Get red, green, and blue values for a color from the factory.
22
+ #Format is #RRGGBB in hexadecimal (like HTML).
23
+ color = sprintf("#%02x%02x%02x",
24
+ f.get(:red, :max => 254).to_i,
25
+ f.get(:green, :max => 254).to_i,
26
+ f.get(:blue, :max => 254).to_i
27
+ )
28
+
29
+ #Create and store a line of the chosen color.
30
+ #Get width and locations of the endpoints from the factory.
31
+ lines << TkcLine.new(
32
+ canvas,
33
+ f.get(:x1, :max => 400),
34
+ f.get(:y1, :max => 400),
35
+ f.get(:x2, :max => 400),
36
+ f.get(:y2, :max => 400),
37
+ :width => f.get(:width, :min => 5, :max => 30),
38
+ :fill => color
39
+ )
40
+
41
+ #If the resetter returns true, tell the ExampleFactory to reassign
42
+ #its source factories to different keys.
43
+ f.reset_assignments if resetter.boolean(:reset)
44
+
45
+ #Delete the oldest line if we have accumulated too many.
46
+ lines.shift.delete if lines.length > 1000
47
+
48
+ end
49
+ end
50
+
51
+ #Display the window.
52
+ canvas.mainloop
@@ -9,5 +9,6 @@ require 'rubyonacid/factories/random'
9
9
  require 'rubyonacid/factories/random_walk'
10
10
  require 'rubyonacid/factories/repeat'
11
11
  require 'rubyonacid/factories/rinda'
12
+ require 'rubyonacid/factories/rounding'
12
13
  require 'rubyonacid/factories/sine'
13
14
  require 'rubyonacid/factories/skip'
@@ -0,0 +1,40 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class AttractionFactory < Factory
6
+
7
+ SQUARE_ROOT_OF_TWO = Math.sqrt(2.0)
8
+
9
+ #Factory to get values from.
10
+ attr_accessor :source_factory
11
+
12
+ #Values from source_factory will be "pulled" toward values from this factory.
13
+ attr_accessor :attractor_factory
14
+
15
+ def initialize(source_factory = nil, attractor_factory = nil)
16
+ super
17
+ @source_factory = source_factory
18
+ @attractor_factory = attractor_factory
19
+ end
20
+
21
+ #Get a value from the source_factory and a value from the attractor_factory.
22
+ #The source_factory value will be adjusted to be closer to the attractor_factory value.
23
+ #The closer the values are, the greater the adjustment.
24
+ def get_unit(key)
25
+ # force = delta * @magnetism / (distance * Jemini::Math::SQUARE_ROOT_OF_TWO)
26
+ value = @source_factory.get_unit(key)
27
+ attractor_value = @attractor_factory.get_unit(key)
28
+ distance = value - attractor_value
29
+ return_value = value - (0.1 / (distance * SQUARE_ROOT_OF_TWO))
30
+ if value > attractor_value and return_value < attractor_value
31
+ return_value = attractor_value
32
+ elsif value < attractor_value and return_value > attractor_value
33
+ return_value = attractor_value
34
+ end
35
+ return_value
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -69,6 +69,8 @@ class CombinationFactory < Factory
69
69
  end
70
70
  when WRAP
71
71
  return value % 1.0
72
+ else
73
+ raise "invalid constrain mode - must be CONSTRAIN or WRAP"
72
74
  end
73
75
  end
74
76
 
@@ -35,6 +35,9 @@ class ExampleFactory < MetaFactory
35
35
  source_factories << RubyOnAcid::FlashFactory.new(
36
36
  random_factory.get(:interval, :max => 100)
37
37
  )
38
+ source_factories << RubyOnAcid::RandomWalkFactory.new(
39
+ random_factory.get(:interval, :max => 0.1)
40
+ )
38
41
  4.times do
39
42
  factory = RubyOnAcid::SineFactory.new
40
43
  factory.interval = random_factory.get(:increment, :min => -0.1, :max => 0.1)
@@ -43,19 +46,28 @@ class ExampleFactory < MetaFactory
43
46
  2.times do
44
47
  factory = RubyOnAcid::RepeatFactory.new
45
48
  factory.repeat_count = random_factory.get(:interval, :min => 2, :max => 100)
46
- factory.source_factory = source_factories[rand(source_factories.length)]
49
+ factory.source_factory = random_element(source_factories)
47
50
  source_factories << factory
48
51
  end
52
+ 2.times do
53
+ source_factories << RubyOnAcid::RoundingFactory.new(
54
+ random_element(source_factories),
55
+ random_factory.get(:interval, :min => 0.1, :max => 0.5)
56
+ )
57
+ end
49
58
  combination_factory = RubyOnAcid::CombinationFactory.new
50
59
  2.times do
51
- combination_factory.source_factories << source_factories[rand(source_factories.length)]
60
+ combination_factory.source_factories << random_element(source_factories)
52
61
  end
53
62
  source_factories << combination_factory
54
- source_factories << RubyOnAcid::RandomWalkFactory.new(0.1)
55
63
 
56
64
  source_factories
57
65
 
58
66
  end
67
+
68
+ def random_element(array)
69
+ array[rand(array.length)]
70
+ end
59
71
 
60
72
 
61
73
  end
@@ -5,6 +5,7 @@ module RubyOnAcid
5
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.
6
6
  class FlashFactory < Factory
7
7
 
8
+ #The number of times to return a value before switching.
8
9
  attr_accessor :interval
9
10
 
10
11
  def initialize(interval = 3)
@@ -2,8 +2,10 @@ require 'rubyonacid/factory'
2
2
 
3
3
  module RubyOnAcid
4
4
 
5
+ #Allows values to be assigned from an external source.
5
6
  class InputFactory < Factory
6
7
 
8
+ #A factory to pull values from in the event no values are stored for a given key.
7
9
  attr_accessor :default_factory
8
10
 
9
11
  def initialize
@@ -14,6 +16,8 @@ class InputFactory < Factory
14
16
  @smallest_seen_values = {}
15
17
  end
16
18
 
19
+ #Retrieves the next stored value for the given key.
20
+ #The key that values are pulled from will not necessarily be the same as that passed to put() - value queue keys are assigned to get_unit() keys at random.
17
21
  def get_unit(key)
18
22
  current_key = assigned_key(key)
19
23
  if @input_values[current_key] and @input_values[current_key].length > 0
@@ -22,11 +26,9 @@ class InputFactory < Factory
22
26
  return default_value(key)
23
27
  end
24
28
  end
25
-
26
- def default_value(key)
27
- @default_factory ? @default_factory.get_unit(key) : 0.0
28
- end
29
-
29
+
30
+ #Store a value for the given key.
31
+ #Values will be scaled to the range 0 to 1 - the largest value yet seen will be scaled to 1.0, the smallest yet seen to 0.0.
30
32
  def put(key, value)
31
33
  value = value.to_f
32
34
  @input_values[key] ||= []
@@ -39,16 +41,22 @@ class InputFactory < Factory
39
41
  @largest_seen_values[key] = value if value > @largest_seen_values[key]
40
42
  end
41
43
 
44
+ #Clears all stored input values for all keys.
42
45
  def clear_input_values
43
46
  @input_values = {}
44
47
  end
45
48
 
49
+ #Clear all value queue key assignments.
46
50
  def clear_assigned_keys
47
51
  @assigned_keys = {}
48
52
  end
49
53
 
50
54
  private
51
55
 
56
+ def default_value(key)
57
+ @default_factory ? @default_factory.get_unit(key) : 0.0
58
+ end
59
+
52
60
  def assigned_key(key)
53
61
  return @key_assignments[key] if @key_assignments[key]
54
62
  key_pool = @input_values.keys - @key_assignments.values
@@ -12,5 +12,4 @@ class RandomFactory < Factory
12
12
 
13
13
  end
14
14
 
15
-
16
15
  end
@@ -0,0 +1,36 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ #Rounds values from a source factory, useful for clustering values into groups.
6
+ class RoundingFactory < Factory
7
+
8
+ #Factory to get values from.
9
+ attr_accessor :source_factory
10
+ #Source values will be rounded to the nearest multiple of this value.
11
+ attr_accessor :nearest
12
+
13
+ def initialize(source_factory = nil, nearest = 0.1)
14
+ super
15
+ @source_factory = source_factory
16
+ @nearest = nearest
17
+ end
18
+
19
+ def get_unit(key)
20
+ round_to(@source_factory.get_unit(key), @nearest)
21
+ end
22
+
23
+ private
24
+
25
+ def round_to(value, multiple_of)
26
+ quotient, modulus = value.divmod(multiple_of)
27
+ if modulus / multiple_of < 0.5
28
+ return multiple_of * quotient
29
+ else
30
+ return multiple_of * (quotient + 1)
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require "rubyonacid/factories/attraction"
3
+ require "shared_factory_specs"
4
+
5
+ include RubyOnAcid
6
+
7
+ describe AttractionFactory do
8
+
9
+ before :each do
10
+ @it = AttractionFactory.new
11
+ end
12
+
13
+ describe "general behavior" do
14
+
15
+ before :each do
16
+ @it.source_factory = mock('Factory', :get_unit => 0.2)
17
+ @it.attractor_factory = 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 factory and attracts them toward values from the attractor factory" do
27
+ @it.source_factory = mock('Factory', :get_unit => 0.0)
28
+ @it.attractor_factory = mock('Factory', :get_unit => 1.0)
29
+ @it.get_unit(:x).should > 0.0
30
+ end
31
+
32
+ it "exerts greater attraction if values are closer" do
33
+ @it.source_factory = mock('Factory', :get_unit => 0.0)
34
+ @it.attractor_factory = mock('Factory')
35
+ @it.attractor_factory.should_receive(:get_unit).and_return(1.0)
36
+ distant_value = @it.get_unit(:x)
37
+ @it.attractor_factory.should_receive(:get_unit).and_return(0.5)
38
+ close_value = @it.get_unit(:x)
39
+ close_value.should > distant_value
40
+ end
41
+
42
+ it "reduces source value if attractor's value is lower" do
43
+ @it.source_factory = mock('Factory', :get_unit => 0.9)
44
+ @it.attractor_factory = mock('Factory', :get_unit => 0.1)
45
+ @it.get_unit(:x).should < 0.9
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,67 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require 'rubyonacid/factories/rounding'
3
+ require "shared_factory_specs"
4
+
5
+ include RubyOnAcid
6
+
7
+ describe RoundingFactory do
8
+
9
+ before :each do
10
+ @it = RoundingFactory.new
11
+ end
12
+
13
+ describe "general behavior" do
14
+
15
+ before :each do
16
+ @it.source_factory = mock('Factory', :get_unit => 0.2)
17
+ end
18
+
19
+ it_should_behave_like "a factory"
20
+
21
+ end
22
+
23
+ it "Requests a value from the source factory and rounds it to a multiple of the requested number" do
24
+ source_factory = mock('Factory')
25
+ @it.source_factory = source_factory
26
+ @it.nearest = 0.3
27
+ source_factory.should_receive(:get_unit).and_return(0.7)
28
+ @it.get_unit(:x).should be_close(0.6, MARGIN)
29
+ source_factory.should_receive(:get_unit).and_return(0.8)
30
+ @it.get_unit(:x).should be_close(0.9, MARGIN)
31
+ source_factory.should_receive(:get_unit).and_return(0.9)
32
+ @it.get_unit(:x).should be_close(0.9, MARGIN)
33
+ source_factory.should_receive(:get_unit).and_return(1.0)
34
+ @it.get_unit(:x).should be_close(0.9, MARGIN)
35
+ end
36
+
37
+ it "can round to multiples of 0.2" do
38
+ @it.source_factory = mock('Factory')
39
+ @it.nearest = 0.2
40
+ @it.source_factory.should_receive(:get_unit).and_return(0.0)
41
+ @it.get_unit(:x).should be_close(0.0, MARGIN)
42
+ @it.source_factory.should_receive(:get_unit).and_return(0.11)
43
+ @it.get_unit(:x).should be_close(0.2, MARGIN)
44
+ @it.source_factory.should_receive(:get_unit).and_return(0.2)
45
+ @it.get_unit(:x).should be_close(0.2, MARGIN)
46
+ @it.source_factory.should_receive(:get_unit).and_return(0.31)
47
+ @it.get_unit(:x).should be_close(0.4, MARGIN)
48
+ @it.source_factory.should_receive(:get_unit).and_return(0.4)
49
+ @it.get_unit(:x).should be_close(0.4, MARGIN)
50
+ end
51
+
52
+ it "can round to multiples of 1.0" do
53
+ @it.source_factory = mock('Factory')
54
+ @it.nearest = 1.0
55
+ @it.source_factory.should_receive(:get_unit).and_return(0.0)
56
+ @it.get_unit(:x).should be_close(0.0, MARGIN)
57
+ @it.source_factory.should_receive(:get_unit).and_return(0.4)
58
+ @it.get_unit(:x).should be_close(0.0, MARGIN)
59
+ @it.source_factory.should_receive(:get_unit).and_return(0.51)
60
+ @it.get_unit(:x).should be_close(1.0, MARGIN)
61
+ @it.source_factory.should_receive(:get_unit).and_return(0.9)
62
+ @it.get_unit(:x).should be_close(1.0, MARGIN)
63
+ @it.source_factory.should_receive(:get_unit).and_return(1.0)
64
+ @it.get_unit(:x).should be_close(1.0, MARGIN)
65
+ end
66
+
67
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyonacid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 1
9
+ version: 0.3.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Jay McGavren
@@ -9,19 +14,21 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-11 00:00:00 -07:00
17
+ date: 2010-04-18 00:00:00 -07:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  description: A framework for creating trippy visuals
26
33
  email: jay@mcgavren.com
27
34
  executables: []
@@ -42,13 +49,14 @@ files:
42
49
  - examples/raw_audio.rb
43
50
  - examples/rinda_agent.rb
44
51
  - examples/svg.rb
45
- - examples/wxruby.rb
52
+ - examples/tk.rb
46
53
  - features/rubyonacid.feature
47
54
  - features/step_definitions/rubyonacid_steps.rb
48
55
  - features/support/env.rb
49
56
  - generators.png
50
57
  - lib/rubyonacid.rb
51
58
  - lib/rubyonacid/factories/all.rb
59
+ - lib/rubyonacid/factories/attraction.rb
52
60
  - lib/rubyonacid/factories/combination.rb
53
61
  - lib/rubyonacid/factories/constant.rb
54
62
  - lib/rubyonacid/factories/example.rb
@@ -61,9 +69,11 @@ files:
61
69
  - lib/rubyonacid/factories/random_walk.rb
62
70
  - lib/rubyonacid/factories/repeat.rb
63
71
  - lib/rubyonacid/factories/rinda.rb
72
+ - lib/rubyonacid/factories/rounding.rb
64
73
  - lib/rubyonacid/factories/sine.rb
65
74
  - lib/rubyonacid/factories/skip.rb
66
75
  - lib/rubyonacid/factory.rb
76
+ - spec/factories/attraction_spec.rb
67
77
  - spec/factories/combination_spec.rb
68
78
  - spec/factories/constant_spec.rb
69
79
  - spec/factories/flash_spec.rb
@@ -75,6 +85,7 @@ files:
75
85
  - spec/factories/random_walk_spec.rb
76
86
  - spec/factories/repeat_spec.rb
77
87
  - spec/factories/rinda_spec.rb
88
+ - spec/factories/rounding_spec.rb
78
89
  - spec/factories/sine_spec.rb
79
90
  - spec/factories/skip_spec.rb
80
91
  - spec/factory_spec.rb
@@ -93,22 +104,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
104
  requirements:
94
105
  - - ">="
95
106
  - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
96
109
  version: "0"
97
- version:
98
110
  required_rubygems_version: !ruby/object:Gem::Requirement
99
111
  requirements:
100
112
  - - ">="
101
113
  - !ruby/object:Gem::Version
114
+ segments:
115
+ - 0
102
116
  version: "0"
103
- version:
104
117
  requirements: []
105
118
 
106
119
  rubyforge_project: rubyonacid
107
- rubygems_version: 1.3.5
120
+ rubygems_version: 1.3.6
108
121
  signing_key:
109
122
  specification_version: 3
110
123
  summary: A framework for creating trippy visuals
111
124
  test_files:
125
+ - spec/factories/attraction_spec.rb
112
126
  - spec/factories/combination_spec.rb
113
127
  - spec/factories/constant_spec.rb
114
128
  - spec/factories/flash_spec.rb
@@ -120,14 +134,16 @@ test_files:
120
134
  - spec/factories/random_walk_spec.rb
121
135
  - spec/factories/repeat_spec.rb
122
136
  - spec/factories/rinda_spec.rb
137
+ - spec/factories/rounding_spec.rb
123
138
  - spec/factories/sine_spec.rb
124
139
  - spec/factories/skip_spec.rb
125
140
  - spec/factory_spec.rb
126
141
  - spec/shared_factory_specs.rb
127
142
  - spec/spec_helper.rb
128
143
  - examples/ascii.rb
144
+ - examples/ascii2.rb
129
145
  - examples/midi.rb
130
146
  - examples/raw_audio.rb
131
147
  - examples/rinda_agent.rb
132
148
  - examples/svg.rb
133
- - examples/wxruby.rb
149
+ - examples/tk.rb
data/examples/wxruby.rb DELETED
@@ -1,108 +0,0 @@
1
- require 'rubygems'
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'
8
-
9
-
10
- class MyApp < Wx::App
11
-
12
- WIDTH = 480
13
- HEIGHT = 480
14
-
15
- def on_init
16
-
17
- #This factory will be in charge of all drawing coordinates, colors, etc.
18
- @f = RubyOnAcid::ExampleFactory.new
19
-
20
- #A skip factory, in charge of randomly resetting the meta factory.
21
- @resetter = RubyOnAcid::SkipFactory.new(0.999)
22
-
23
- #Set up window.
24
- frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
25
- frame.show
26
- window = Wx::Window.new(frame, :size => [WIDTH, HEIGHT])
27
-
28
- #Animate periodically.
29
- t = Wx::Timer.new(self, 55)
30
- evt_timer(55) do
31
- window.paint{|surface| render(surface)}
32
- @f.reset_assignments if @resetter.boolean(:reset)
33
- end
34
- t.start(33)
35
-
36
- end
37
-
38
- #Choose a shape and color and draw it to the given surface.
39
- def render(surface)
40
- color = Wx::Colour.new(
41
- @f.get(:red, :max => 255).to_i,
42
- @f.get(:green, :max => 255).to_i,
43
- @f.get(:blue, :max => 255).to_i,
44
- @f.get(:alpha, :min => 50, :max => 200).to_i
45
- )
46
- surface.pen = Wx::Pen.new(color, @f.get(:width, :min => 1, :max => 5).to_i)
47
- surface.brush = Wx::Brush.new(color, Wx::SOLID)
48
- case @f.choose(:shape,
49
- :arc,
50
- :polygon,
51
- :line,
52
- :rectangle,
53
- :circle,
54
- :spline
55
- )
56
- when :line
57
- surface.draw_line(
58
- @f.get(:x0, :max => WIDTH).to_i,
59
- @f.get(:y0, :max => HEIGHT).to_i,
60
- @f.get(:x1, :max => WIDTH).to_i,
61
- @f.get(:y1, :max => HEIGHT).to_i
62
- )
63
- when :rectangle
64
- surface.draw_rectangle(
65
- @f.get(:x0, :max => WIDTH).to_i,
66
- @f.get(:y0, :max => HEIGHT).to_i,
67
- @f.get(:x1, :max => WIDTH).to_i,
68
- @f.get(:y1, :max => HEIGHT).to_i
69
- )
70
- when :circle
71
- surface.draw_circle(
72
- @f.get(:x0, :max => WIDTH).to_i,
73
- @f.get(:y0, :max => HEIGHT).to_i,
74
- @f.get(:width, :max => 100).to_i
75
- )
76
- when :arc
77
- surface.draw_elliptic_arc(
78
- @f.get(:x0, :max => WIDTH).to_i,
79
- @f.get(:y0, :max => HEIGHT).to_i,
80
- @f.get(:width, :max => 100).to_i,
81
- @f.get(:height, :max => 100).to_i,
82
- @f.get(:arc_start, :max => 360).to_i,
83
- @f.get(:arc_end, :max => 360).to_i
84
- )
85
- when :polygon
86
- surface.draw_polygon(make_point_array)
87
- when :spline
88
- surface.draw_spline(make_point_array)
89
- end
90
- end
91
-
92
- #Create an array of points for drawing complex shapes.
93
- def make_point_array
94
- points = []
95
- 3.times do |i|
96
- points << Wx::Point.new(
97
- @f.get("x#{i}".to_sym, :max => WIDTH).to_i,
98
- @f.get("y#{i}".to_sym, :max => HEIGHT).to_i
99
- )
100
- end
101
- points
102
- end
103
-
104
-
105
- end
106
-
107
- app = MyApp.new
108
- app.main_loop