rubyonacid 0.1.2 → 0.2.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/examples/test3.rb DELETED
@@ -1,108 +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 = 320
19
- HEIGHT = 320
20
-
21
- def on_init
22
-
23
- random_factory = RubyOnAcid::RandomFactory.new
24
-
25
- (1..1000).each do |file_number|
26
-
27
- file_name = sprintf("%05d_random.png", file_number)
28
-
29
- #The MetaFactory assigns factories to requested value types.
30
- @f = RubyOnAcid::MetaFactory.new
31
- @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
32
- @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
33
- @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
34
- @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
35
- @f.factory_pool << RubyOnAcid::ConstantFactory.new(random_factory.within(:constant, 0.0, 1.0))
36
- @f.factory_pool << RubyOnAcid::FlashFactory.new(random_factory.within(:interval, 2, 100))
37
- @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
38
- @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
39
- @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
40
- @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
41
- @f.factory_pool << RubyOnAcid::RepeatFactory.new(
42
- RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
43
- random_factory.within(:interval, 2, 100)
44
- )
45
- @f.factory_pool << RubyOnAcid::RepeatFactory.new(
46
- RubyOnAcid::RandomFactory.new,
47
- random_factory.within(:interval, 2, 1000)
48
- )
49
- @f.factory_pool << RubyOnAcid::RepeatFactory.new(
50
- RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
51
- random_factory.within(:interval, 2, 100)
52
- )
53
- @f.factory_pool << RubyOnAcid::ModuloFactory.new(RubyOnAcid::LoopFactory.new(0.00001))
54
-
55
- frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
56
-
57
- bitmap = Wx::Bitmap.new(WIDTH, HEIGHT)
58
- bitmap.draw do |surface|
59
- # surface.pen = black_pen
60
- surface.brush = Wx::BLACK_BRUSH
61
- surface.draw_rectangle(0, 0, WIDTH, HEIGHT)
62
- end
63
- random_factory.within(:iterations, 10, 10000).to_i.times do
64
- bitmap.draw {|surface| render(surface)}
65
- end
66
- bitmap.draw do |surface|
67
- surface.text_foreground = Wx::Colour.new(255, 255, 255, 255)
68
- y = 0
69
- @f.to_yaml.split("\n").each do |line|
70
- surface.draw_text(line, 0, y)
71
- y += 10
72
- end
73
- end
74
-
75
- File.open(file_name + ".yml", "w") do |file|
76
- YAML.dump(@f, file)
77
- end
78
-
79
- bitmap.save_file(file_name, Wx::BITMAP_TYPE_PNG)
80
-
81
- end
82
-
83
- exit
84
-
85
- end
86
-
87
- def render(surface)
88
- surface.pen = Wx::Pen.new(
89
- Wx::Colour.new(
90
- @f.within(:red, 0, 255).to_i,
91
- @f.within(:green, 0, 255).to_i,
92
- @f.within(:blue, 0, 255).to_i,
93
- @f.within(:alpha, 50, 255).to_i
94
- ),
95
- @f.within(:width, 1, 5).to_i
96
- )
97
- surface.draw_line(
98
- @f.within(:x, 0, WIDTH).to_i,
99
- @f.within(:y, 0, HEIGHT).to_i,
100
- @f.within(:x2, 0, WIDTH).to_i,
101
- @f.within(:y2, 0, HEIGHT).to_i
102
- )
103
- end
104
-
105
- end
106
-
107
- app = MyApp.new
108
- app.main_loop
@@ -1,25 +0,0 @@
1
- require 'rubyonacid/factory'
2
-
3
- module RubyOnAcid
4
-
5
- #Gets values from a source factory and returns the same value the given number of times before getting a fresh value.
6
- class ModuloFactory < Factory
7
-
8
- #Factory to get values from.
9
- attr_accessor :source_factory
10
-
11
- def initialize(source_factory = nil)
12
- super
13
- @source_factory = source_factory
14
- @prior_values = {}
15
- end
16
-
17
- #Returns the value of get_unit on the source factory the assigned number of times.
18
- def get_unit(key)
19
- @prior_values[key] ||= 0
20
- @prior_values[key] = (@prior_values[key] + @source_factory.get_unit(key)) % 1
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,33 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
- require 'rubyonacid/factories/modulo'
3
-
4
- include RubyOnAcid
5
-
6
- describe ModuloFactory do
7
-
8
- MARGIN = 0.01
9
-
10
- before :each do
11
- @it = ModuloFactory.new
12
- end
13
-
14
- it "accumulates values and returns remainder of dividing by 1" do
15
- source_factory = mock('Factory')
16
- source_factory.should_receive(:get_unit).exactly(3).times.and_return(0.1, 0.35, 0.75)
17
- @it.source_factory = source_factory
18
- @it.get_unit(:x).should be_close(0.1, MARGIN)
19
- @it.get_unit(:x).should be_close(0.45, MARGIN)
20
- @it.get_unit(:x).should be_close(0.2, MARGIN) #0.45 + 0.75 == 1.2, 1.2 modulo 1 == 0.2
21
- end
22
-
23
- it "Tracks modulos on a per-key basis" do
24
- source_factory = mock('Factory')
25
- source_factory.should_receive(:get_unit).exactly(4).times.and_return(0.25, 0.9, 0.33, 0.8)
26
- @it.source_factory = source_factory
27
- @it.get_unit(:x).should be_close(0.25, MARGIN)#== 0.25
28
- @it.get_unit(:x).should be_close(0.15, MARGIN)#== 0.15
29
- @it.get_unit(:y).should be_close(0.33, MARGIN)#== 0.33
30
- @it.get_unit(:x).should be_close(0.95, MARGIN)#== 0.95
31
- end
32
-
33
- end