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.
- data/CHANGELOG +138 -119
- data/README.markdown +43 -41
- data/Rakefile +68 -68
- data/examples/common.rb +8 -8
- data/examples/example_alpha_blend.rb +31 -31
- data/examples/example_bezier.rb +42 -42
- data/examples/example_color_control.rb +69 -69
- data/examples/example_color_transform.rb +64 -67
- data/examples/example_color_transform_circle.rb +65 -0
- data/examples/example_dup.rb +75 -75
- data/examples/example_each.rb +42 -42
- data/examples/example_effect.rb +35 -35
- data/examples/example_fill.rb +44 -44
- data/examples/example_fill_old.rb +49 -49
- data/examples/example_fluent.rb +31 -31
- data/examples/example_gen_eval.rb +34 -34
- data/examples/example_hash_arguments.rb +47 -47
- data/examples/example_light.rb +77 -0
- data/examples/example_lsystem.rb +61 -61
- data/examples/example_melt.rb +27 -27
- data/examples/example_meyet.rb +64 -0
- data/examples/example_polyline.rb +43 -43
- data/examples/example_scale.rb +29 -29
- data/examples/example_simple.rb +48 -38
- data/examples/example_sync.rb +60 -60
- data/examples/example_trace.rb +1 -1
- data/examples/example_turtle.rb +40 -40
- data/examples/example_weird.rb +3 -1
- data/examples/media/Thumbs.db +0 -0
- data/lib/1.8/texplay.so +0 -0
- data/lib/1.9/texplay.so +0 -0
- data/lib/texplay/version.rb +1 -1
- data/lib/texplay-contrib.rb +171 -171
- data/lib/texplay.rb +162 -137
- metadata +9 -5
data/lib/texplay-contrib.rb
CHANGED
@@ -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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
require '
|
13
|
-
require
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@__init_procs__
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
require "#{direc}/texplay
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
+
|