texplay 0.2.800-i386-mswin32 → 0.2.900-i386-mswin32

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.
@@ -1,171 +1,171 @@
1
- begin
2
- require 'rubygems'
3
- rescue LoadError
4
- end
5
-
6
- require 'texplay'
7
-
8
- # to bring in String#each_char for 1.8
9
- if RUBY_VERSION =~ /1.8/
10
- require 'jcode'
11
- end
12
-
13
- # setup will be executed straight after Gosu::Image instantiation
14
- TexPlay::on_setup do
15
- @turtle_pos = TexPlay::TPPoint.new(width / 2, height / 2 )
16
- @turtle_angle = 0
17
- end
18
-
19
-
20
- TexPlay::create_macro(:move_to) do |x, y|
21
- capture {
22
- @turtle_pos.x = x
23
- @turtle_pos.y = y
24
- }
25
- end
26
-
27
- TexPlay::create_macro(:move_rel) do |dx, dy|
28
- capture {
29
- @turtle_pos.x += dx
30
- @turtle_pos.y += dy
31
- }
32
- end
33
-
34
- TexPlay::create_macro(:line_to) do |x, y, *other|
35
- capture {
36
- line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
37
-
38
- @turtle_pos.x, @turtle_pos.y = x, y
39
- }
40
- end
41
-
42
- TexPlay::create_macro(:line_rel) do |dx, dy, *other|
43
- capture {
44
- x = @turtle_pos.x + dx
45
- y = @turtle_pos.y + dy
46
-
47
- line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
48
-
49
- @turtle_pos.x, @turtle_pos.y = x, y
50
- }
51
- end
52
-
53
- TexPlay::create_macro(:turn_to) do |a|
54
- capture {
55
- @turtle_angle = a
56
- }
57
- end
58
-
59
- TexPlay::create_macro(:turn) do |da|
60
- capture {
61
- @turtle_angle += da
62
- }
63
- end
64
-
65
- TexPlay::create_macro(:forward) do |dist, *other|
66
- capture {
67
- visible = other.shift
68
-
69
- radians_per_degree = 0.0174532925199433
70
-
71
- x = @turtle_pos.x + dist * Math::cos(radians_per_degree * @turtle_angle)
72
- y = @turtle_pos.y + dist * Math::sin(radians_per_degree * @turtle_angle)
73
-
74
- if(visible) then
75
- line_to(x, y, *other)
76
- else
77
- move_to(x, y)
78
- end
79
- }
80
- end
81
-
82
- # L-System code
83
- # adding LSystem class to TexPlay module
84
- class TexPlay::LSystem
85
- def initialize(&block)
86
- @rules = {}
87
-
88
- instance_eval(&block) if block
89
- end
90
-
91
- def rule(new_rule)
92
- @rules.merge!(new_rule)
93
- end
94
-
95
- def atom(new_atom)
96
- @atom = new_atom
97
- end
98
-
99
- def angle(new_angle=nil)
100
- return @angle if !new_angle
101
- @angle = new_angle
102
- end
103
-
104
- def produce_string(order)
105
- order = order[:order]
106
- string = @atom.dup
107
-
108
- order.times do
109
- i = 0
110
- while(i < string.length)
111
- sub = @rules[string[i, 1]]
112
-
113
- string[i] = sub if sub
114
-
115
- i += sub ? sub.length : 1
116
- end
117
- end
118
-
119
- string
120
- end
121
- end
122
-
123
- # L-System macro
124
- TexPlay::create_macro(:lsystem) do |x, y, system, options|
125
- capture {
126
- theta = system.angle
127
- turtle_stack = []
128
- move_to(x, y)
129
- line_length = options[:line_length] || 1
130
-
131
- system.produce_string(options).each_char do |v|
132
-
133
- case v
134
- when "F"
135
- forward(line_length, true)
136
- when "+"
137
- turn(theta)
138
- when "-"
139
- turn(-theta)
140
- when "["
141
- turtle_stack.push([@turtle_pos.dup, @turtle_angle])
142
- when "]"
143
- @turtle_pos, @turtle_angle = turtle_stack.pop
144
- end
145
- end
146
- }
147
- end
148
-
149
- # Scaling
150
- # uses nearest-neighbour
151
- TexPlay::create_macro(:splice_and_scale) do |img, cx, cy, *options|
152
- options = options.first ? options.first : {}
153
-
154
- options = {
155
- :color_control => proc do |c1, c2, x, y|
156
- factor = options[:factor] || 1
157
- factor_x = options[:factor_x] || factor
158
- factor_y = options[:factor_y] || factor
159
-
160
- x = factor_x * (x - cx) + cx
161
- y = factor_y * (y - cy) + cy
162
-
163
- rect x, y, x + factor_x, y + factor_y, :color => c2, :fill => true
164
- :none
165
- end
166
- }.merge!(options)
167
-
168
- splice img, cx, cy, options
169
-
170
- self
171
- end
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError
4
+ end
5
+
6
+ require 'texplay'
7
+
8
+ # to bring in String#each_char for 1.8
9
+ if RUBY_VERSION =~ /1.8/
10
+ require 'jcode'
11
+ end
12
+
13
+ # setup will be executed straight after Gosu::Image instantiation
14
+ TexPlay::on_setup do
15
+ @turtle_pos = TexPlay::TPPoint.new(width / 2, height / 2 )
16
+ @turtle_angle = 0
17
+ end
18
+
19
+
20
+ TexPlay::create_macro(:move_to) do |x, y|
21
+ capture {
22
+ @turtle_pos.x = x
23
+ @turtle_pos.y = y
24
+ }
25
+ end
26
+
27
+ TexPlay::create_macro(:move_rel) do |dx, dy|
28
+ capture {
29
+ @turtle_pos.x += dx
30
+ @turtle_pos.y += dy
31
+ }
32
+ end
33
+
34
+ TexPlay::create_macro(:line_to) do |x, y, *other|
35
+ capture {
36
+ line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
37
+
38
+ @turtle_pos.x, @turtle_pos.y = x, y
39
+ }
40
+ end
41
+
42
+ TexPlay::create_macro(:line_rel) do |dx, dy, *other|
43
+ capture {
44
+ x = @turtle_pos.x + dx
45
+ y = @turtle_pos.y + dy
46
+
47
+ line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
48
+
49
+ @turtle_pos.x, @turtle_pos.y = x, y
50
+ }
51
+ end
52
+
53
+ TexPlay::create_macro(:turn_to) do |a|
54
+ capture {
55
+ @turtle_angle = a
56
+ }
57
+ end
58
+
59
+ TexPlay::create_macro(:turn) do |da|
60
+ capture {
61
+ @turtle_angle += da
62
+ }
63
+ end
64
+
65
+ TexPlay::create_macro(:forward) do |dist, *other|
66
+ capture {
67
+ visible = other.shift
68
+
69
+ radians_per_degree = 0.0174532925199433
70
+
71
+ x = @turtle_pos.x + dist * Math::cos(radians_per_degree * @turtle_angle)
72
+ y = @turtle_pos.y + dist * Math::sin(radians_per_degree * @turtle_angle)
73
+
74
+ if(visible) then
75
+ line_to(x, y, *other)
76
+ else
77
+ move_to(x, y)
78
+ end
79
+ }
80
+ end
81
+
82
+ # L-System code
83
+ # adding LSystem class to TexPlay module
84
+ class TexPlay::LSystem
85
+ def initialize(&block)
86
+ @rules = {}
87
+
88
+ instance_eval(&block) if block
89
+ end
90
+
91
+ def rule(new_rule)
92
+ @rules.merge!(new_rule)
93
+ end
94
+
95
+ def atom(new_atom)
96
+ @atom = new_atom
97
+ end
98
+
99
+ def angle(new_angle=nil)
100
+ return @angle if !new_angle
101
+ @angle = new_angle
102
+ end
103
+
104
+ def produce_string(order)
105
+ order = order[:order]
106
+ string = @atom.dup
107
+
108
+ order.times do
109
+ i = 0
110
+ while(i < string.length)
111
+ sub = @rules[string[i, 1]]
112
+
113
+ string[i] = sub if sub
114
+
115
+ i += sub ? sub.length : 1
116
+ end
117
+ end
118
+
119
+ string
120
+ end
121
+ end
122
+
123
+ # L-System macro
124
+ TexPlay::create_macro(:lsystem) do |x, y, system, options|
125
+ capture {
126
+ theta = system.angle
127
+ turtle_stack = []
128
+ move_to(x, y)
129
+ line_length = options[:line_length] || 1
130
+
131
+ system.produce_string(options).each_char do |v|
132
+
133
+ case v
134
+ when "F"
135
+ forward(line_length, true)
136
+ when "+"
137
+ turn(theta)
138
+ when "-"
139
+ turn(-theta)
140
+ when "["
141
+ turtle_stack.push([@turtle_pos.dup, @turtle_angle])
142
+ when "]"
143
+ @turtle_pos, @turtle_angle = turtle_stack.pop
144
+ end
145
+ end
146
+ }
147
+ end
148
+
149
+ # Scaling
150
+ # uses nearest-neighbour
151
+ TexPlay::create_macro(:splice_and_scale) do |img, cx, cy, *options|
152
+ options = options.first ? options.first : {}
153
+
154
+ options = {
155
+ :color_control => proc do |c1, c2, x, y|
156
+ factor = options[:factor] || 1
157
+ factor_x = options[:factor_x] || factor
158
+ factor_y = options[:factor_y] || factor
159
+
160
+ x = factor_x * (x - cx) + cx
161
+ y = factor_y * (y - cy) + cy
162
+
163
+ rect x, y, x + factor_x, y + factor_y, :color => c2, :fill => true
164
+ :none
165
+ end
166
+ }.merge!(options)
167
+
168
+ splice img, cx, cy, options
169
+
170
+ self
171
+ end
data/lib/texplay.rb CHANGED
@@ -1,137 +1,162 @@
1
- # (C) John Mair 2009, under the MIT licence
2
-
3
- begin
4
- require 'rubygems'
5
- rescue LoadError
6
- end
7
-
8
- direc = File.dirname(__FILE__)
9
-
10
- # include gosu first
11
- require 'rbconfig'
12
- require 'gosu'
13
- require "#{direc}/texplay/version"
14
-
15
- module TexPlay
16
- class << self
17
- def on_setup(&block)
18
- raise "need a block" if !block
19
-
20
- @__init_procs__ ||= []
21
- @__init_procs__.push(block)
22
- end
23
-
24
- def setup(receiver)
25
- if @__init_procs__ then
26
- @__init_procs__.each do |init_proc|
27
- receiver.instance_eval(&init_proc)
28
- end
29
- end
30
- end
31
-
32
- def create_blank_image(window, width, height)
33
- Gosu::Image.new(window, EmptyImageStub.new(width, height))
34
- end
35
-
36
- alias_method :create_image, :create_blank_image
37
- end
38
-
39
- module Colors
40
- Red = [1, 0, 0, 1]
41
- Green = [0, 1, 0, 1]
42
- Blue = [0, 0, 1, 1]
43
- Black = [0, 0, 0, 1]
44
- White = [1, 1, 1, 1]
45
- Grey = [0.5, 0.5, 0.5, 1]
46
- Alpha = [0, 0, 0, 0]
47
- Purple = [1, 0, 1, 1]
48
- Yellow = [1, 1, 0, 1]
49
- Cyan = [0, 1, 1, 1]
50
- Orange = [1, 0.5, 0, 1]
51
- Brown = [0.39, 0.26, 0.13, 1]
52
- Turquoise = [1, 0.6, 0.8, 1]
53
- Tyrian = [0.4, 0.007, 0.235, 1]
54
- end
55
- include Colors
56
- end
57
-
58
- # credit to philomory for this class
59
- class EmptyImageStub
60
- def initialize(w, h)
61
- @w, @h = w, h
62
- end
63
-
64
- def to_blob
65
- "\0" * @w * @h * 4
66
- end
67
-
68
- def rows
69
- @h
70
- end
71
-
72
- def columns
73
- @w
74
- end
75
- end
76
-
77
- # bring in user-defined extensions to TexPlay
78
- direc = File.dirname(__FILE__)
79
- dlext = Config::CONFIG['DLEXT']
80
- begin
81
- if RUBY_VERSION && RUBY_VERSION =~ /1.9/
82
- require "#{direc}/1.9/texplay.#{dlext}"
83
- else
84
- require "#{direc}/1.8/texplay.#{dlext}"
85
- end
86
- rescue LoadError => e
87
- require "#{direc}/texplay.#{dlext}"
88
- end
89
-
90
- require "#{direc}/texplay-contrib"
91
-
92
- # monkey patching the Gosu::Image class to add image manipulation functionality
93
- module Gosu
94
- class Image
95
-
96
- # bring in the TexPlay image manipulation methods
97
- include TexPlay
98
-
99
- attr_reader :__window__
100
-
101
- class << self
102
- alias_method :original_new, :new
103
-
104
- def new(*args, &block)
105
-
106
- # invoke old behaviour
107
- obj = original_new(*args, &block)
108
-
109
- # refresh the TexPlay image cache
110
- if obj.width <= (TexPlay::TP_MAX_QUAD_SIZE) &&
111
- obj.height <= (TexPlay::TP_MAX_QUAD_SIZE) && obj.quad_cached? then
112
-
113
- obj.refresh_cache
114
- end
115
-
116
- # run custom setup
117
- TexPlay::setup(obj)
118
-
119
- obj.instance_variable_set(:@__window__, args.first)
120
-
121
- # return the new image
122
- obj
123
- end
124
- end
125
- end
126
- end
127
-
128
- # a bug in ruby 1.8.6 rb_eval_string() means i must define this here (rather than in texplay.c)
129
- class Proc
130
- def __context__
131
- eval('self', self.binding)
132
- end
133
- end
134
-
135
-
136
-
137
-
1
+
2
+ # (C) John Mair 2009, under the MIT licence
3
+
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+
9
+ direc = File.dirname(__FILE__)
10
+
11
+ # include gosu first
12
+ require 'rbconfig'
13
+ require 'gosu'
14
+ require "#{direc}/texplay/version"
15
+
16
+ module TexPlay
17
+ class << self
18
+ def on_setup(&block)
19
+ raise "need a block" if !block
20
+
21
+ @__init_procs__ ||= []
22
+ @__init_procs__.push(block)
23
+ end
24
+
25
+ def setup(receiver)
26
+ if @__init_procs__ then
27
+ @__init_procs__.each do |init_proc|
28
+ receiver.instance_eval(&init_proc)
29
+ end
30
+ end
31
+ end
32
+
33
+ def create_blank_image(window, width, height, options={})
34
+ options = { :color => [0, 0, 0, 0] }.merge!(options)
35
+
36
+ img = Gosu::Image.new(window, EmptyImageStub.new(width, height))
37
+ img.rect 0, 0, img.width - 1, img.height - 1, :color => options[:color], :fill => true
38
+
39
+ img
40
+ end
41
+
42
+ alias_method :create_image, :create_blank_image
43
+ end
44
+
45
+ module Colors
46
+ Red = [1, 0, 0, 1]
47
+ Green = [0, 1, 0, 1]
48
+ Blue = [0, 0, 1, 1]
49
+ Black = [0, 0, 0, 1]
50
+ White = [1, 1, 1, 1]
51
+ Grey = [0.5, 0.5, 0.5, 1]
52
+ Alpha = [0, 0, 0, 0]
53
+ Purple = [1, 0, 1, 1]
54
+ Yellow = [1, 1, 0, 1]
55
+ Cyan = [0, 1, 1, 1]
56
+ Orange = [1, 0.5, 0, 1]
57
+ Brown = [0.39, 0.26, 0.13, 1]
58
+ Turquoise = [1, 0.6, 0.8, 1]
59
+ Tyrian = [0.4, 0.007, 0.235, 1]
60
+ end
61
+ include Colors
62
+ end
63
+
64
+ # credit to philomory for this class
65
+ class EmptyImageStub
66
+ def initialize(w, h)
67
+ @w, @h = w, h
68
+ end
69
+
70
+ def to_blob
71
+ "\0" * @w * @h * 4
72
+ end
73
+
74
+ def rows
75
+ @h
76
+ end
77
+
78
+ def columns
79
+ @w
80
+ end
81
+ end
82
+
83
+ # bring in user-defined extensions to TexPlay
84
+ direc = File.dirname(__FILE__)
85
+ dlext = Config::CONFIG['DLEXT']
86
+ begin
87
+ if RUBY_VERSION && RUBY_VERSION =~ /1.9/
88
+ require "#{direc}/1.9/texplay.#{dlext}"
89
+ else
90
+ require "#{direc}/1.8/texplay.#{dlext}"
91
+ end
92
+ rescue LoadError => e
93
+ require "#{direc}/texplay.#{dlext}"
94
+ end
95
+
96
+ require "#{direc}/texplay-contrib"
97
+
98
+ # monkey patching the Gosu::Image class to add image manipulation functionality
99
+ module Gosu
100
+ class Image
101
+
102
+ # bring in the TexPlay image manipulation methods
103
+ include TexPlay
104
+
105
+ attr_reader :__window__
106
+
107
+ class << self
108
+ alias_method :original_new, :new
109
+
110
+ def new(*args, &block)
111
+
112
+ # invoke old behaviour
113
+ obj = original_new(*args, &block)
114
+
115
+ prepare_image(*args, obj)
116
+ end
117
+
118
+ alias_method :original_from_text, :from_text
119
+
120
+ def from_text(*args, &block)
121
+
122
+ # invoke old behaviour
123
+ obj = original_from_text(*args, &block)
124
+
125
+ prepare_image(*args, obj)
126
+ end
127
+
128
+ def prepare_image(*args, obj)
129
+
130
+ # refresh the TexPlay image cache
131
+ if obj.width <= (TexPlay::TP_MAX_QUAD_SIZE) &&
132
+ obj.height <= (TexPlay::TP_MAX_QUAD_SIZE) && obj.quad_cached? then
133
+
134
+ obj.refresh_cache
135
+ end
136
+
137
+ # run custom setup
138
+ TexPlay.setup(obj)
139
+
140
+ obj.instance_variable_set(:@__window__, args.first)
141
+
142
+ obj
143
+ end
144
+
145
+ private :prepare_image
146
+ end
147
+
148
+ alias_method :rows, :height
149
+ alias_method :columns, :width
150
+ end
151
+ end
152
+
153
+ # a bug in ruby 1.8.6 rb_eval_string() means i must define this here (rather than in texplay.c)
154
+ class Proc
155
+ def __context__
156
+ eval('self', self.binding)
157
+ end
158
+ end
159
+
160
+
161
+
162
+