texplay 0.2.4-x86-mswin32-60 → 0.2.5-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +94 -88
- data/README.markdown +35 -35
- data/Rakefile +66 -87
- data/examples/example_bezier.rb +1 -1
- data/examples/example_dup.rb +24 -1
- data/examples/example_lsystem.rb +59 -51
- data/examples/example_scale.rb +29 -0
- data/{src → ext/texplay}/actions.c +2 -2
- data/{src → ext/texplay}/actions.h +0 -0
- data/{src → ext/texplay}/bindings.c +0 -0
- data/{src → ext/texplay}/bindings.h +0 -0
- data/{src → ext/texplay}/cache.c +5 -2
- data/{src → ext/texplay}/cache.h +0 -0
- data/{src → ext/texplay}/compat.h +0 -0
- data/{src → ext/texplay}/extconf.rb +2 -2
- data/{src → ext/texplay}/gen_eval.c +0 -0
- data/{src → ext/texplay}/gen_eval.h +0 -0
- data/{src → ext/texplay}/object2module.c +0 -0
- data/{src → ext/texplay}/object2module.h +0 -0
- data/{src → ext/texplay}/texplay.c +1 -1
- data/{src → ext/texplay}/texplay.h +0 -0
- data/{src → ext/texplay}/utils.c +10 -7
- data/{src → ext/texplay}/utils.h +0 -0
- data/lib/{ctexplay.18.so → 1.8/texplay.so} +0 -0
- data/lib/{ctexplay.19.so → 1.9/texplay.so} +0 -0
- data/lib/texplay-contrib.rb +171 -149
- data/lib/texplay.rb +134 -134
- metadata +21 -36
- data/src/Makefile +0 -212
- data/src/TAGS +0 -286
- data/src/actions.obj +0 -0
- data/src/bindings.obj +0 -0
- data/src/cache.obj +0 -0
- data/src/ctexplay-i386-mswin32.def +0 -2
- data/src/ctexplay-i386-mswin32.exp +0 -0
- data/src/ctexplay-i386-mswin32.lib +0 -0
- data/src/ctexplay-i386-mswin32.pdb +0 -0
- data/src/ctexplay.so +0 -0
- data/src/gen_eval.obj +0 -0
- data/src/mkmf.log +0 -33
- data/src/object2module.obj +0 -0
- data/src/texplay.obj +0 -0
- data/src/utils.obj +0 -0
- data/src/vc60.pdb +0 -0
data/examples/example_lsystem.rb
CHANGED
@@ -1,51 +1,59 @@
|
|
1
|
-
require 'common'
|
2
|
-
require 'texplay'
|
3
|
-
|
4
|
-
Dragon = TexPlay::LSystem.new do
|
5
|
-
rule "F" => "F"
|
6
|
-
rule "X" => "X+YF+"
|
7
|
-
rule "Y" => "-FX-Y"
|
8
|
-
angle 90
|
9
|
-
|
10
|
-
atom "FX"
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
rule "F" => "F
|
15
|
-
|
16
|
-
angle
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rule "
|
23
|
-
|
24
|
-
angle 20
|
25
|
-
atom "
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
rule "F" => "FF"
|
30
|
-
rule "X" => "F
|
31
|
-
|
32
|
-
angle
|
33
|
-
atom "X"
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
1
|
+
require 'common'
|
2
|
+
require 'texplay'
|
3
|
+
|
4
|
+
Dragon = TexPlay::LSystem.new do
|
5
|
+
rule "F" => "F"
|
6
|
+
rule "X" => "X+YF+"
|
7
|
+
rule "Y" => "-FX-Y"
|
8
|
+
angle 90
|
9
|
+
|
10
|
+
atom "FX"
|
11
|
+
end
|
12
|
+
|
13
|
+
Koch = TexPlay::LSystem.new do
|
14
|
+
rule "F" => "F-F++F-F"
|
15
|
+
|
16
|
+
angle 60
|
17
|
+
|
18
|
+
atom "F"
|
19
|
+
end
|
20
|
+
|
21
|
+
Bush1 = TexPlay::LSystem.new do
|
22
|
+
rule "F" => "F[-F]F[+F][F]"
|
23
|
+
|
24
|
+
angle 20
|
25
|
+
atom "F"
|
26
|
+
end
|
27
|
+
|
28
|
+
Bush2 = TexPlay::LSystem.new do
|
29
|
+
rule "F" => "FF"
|
30
|
+
rule "X" => "F[+X]F[-X]+X"
|
31
|
+
|
32
|
+
angle 20
|
33
|
+
atom "X"
|
34
|
+
end
|
35
|
+
|
36
|
+
Bush3 = TexPlay::LSystem.new do
|
37
|
+
rule "F" => "FF"
|
38
|
+
rule "X" => "F-[[X]+X]+F[+FX]-X"
|
39
|
+
|
40
|
+
angle 22.5
|
41
|
+
atom "X"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
class W < Gosu::Window
|
47
|
+
def initialize
|
48
|
+
super(1024, 768, false, 20)
|
49
|
+
@img = TexPlay::create_blank_image(self, 500, 500)
|
50
|
+
@img.lsystem(250, 250, Koch, :order => 8, :line_length => 10)
|
51
|
+
end
|
52
|
+
|
53
|
+
def draw
|
54
|
+
@img.draw(100,0,1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
w = W.new
|
59
|
+
w.show
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'gosu'
|
4
|
+
require 'texplay'
|
5
|
+
|
6
|
+
|
7
|
+
class W < Gosu::Window
|
8
|
+
def initialize
|
9
|
+
super(1024, 768, false, 20)
|
10
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/logo.png")
|
11
|
+
@img2 = TexPlay::create_blank_image(self, 500, 500)
|
12
|
+
|
13
|
+
@img2.splice_and_scale @img, 0, 50, :factor => 2
|
14
|
+
@img2.splice @img, 0, 200
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
x = @img.width * rand
|
19
|
+
y = @img.height * rand
|
20
|
+
|
21
|
+
@img2.draw 100, 100,1
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
w = W.new
|
28
|
+
w.show
|
29
|
+
|
@@ -787,8 +787,8 @@ bezier_do_action(VALUE points, texture_info * tex, VALUE hash_arg, sync sync_mod
|
|
787
787
|
num_point_pairs = RARRAY_LEN(points) / 2;
|
788
788
|
}
|
789
789
|
|
790
|
-
if(num_point_pairs >
|
791
|
-
rb_raise(rb_eArgError, "too many points for bezier curve.
|
790
|
+
if(num_point_pairs > 17)
|
791
|
+
rb_raise(rb_eArgError, "too many points for bezier curve. 17 points is current maximum. got %d\n",
|
792
792
|
num_point_pairs);
|
793
793
|
|
794
794
|
/* get the first point */
|
File without changes
|
File without changes
|
File without changes
|
data/{src → ext/texplay}/cache.c
RENAMED
@@ -30,7 +30,7 @@ cache_create_entry(int tname) {
|
|
30
30
|
if(cache.len >= CACHE_SIZE) { rb_raise(rb_eRuntimeError, "cache is full! increase CACHE_SIZE"); }
|
31
31
|
|
32
32
|
/* save current texture binding */
|
33
|
-
glGetIntegerv(GL_TEXTURE_BINDING_2D, &saved_tname);
|
33
|
+
/* glGetIntegerv(GL_TEXTURE_BINDING_2D, &saved_tname); */
|
34
34
|
|
35
35
|
/* opengl initialization code */
|
36
36
|
glEnable(GL_TEXTURE_2D);
|
@@ -54,7 +54,10 @@ cache_create_entry(int tname) {
|
|
54
54
|
cache.len++;
|
55
55
|
|
56
56
|
/* restore saved texture binding */
|
57
|
-
glBindTexture(GL_TEXTURE_2D, saved_tname);
|
57
|
+
/* glBindTexture(GL_TEXTURE_2D, saved_tname); */
|
58
|
+
|
59
|
+
glDisable(GL_TEXTURE_2D);
|
60
|
+
|
58
61
|
|
59
62
|
return &cache.entry[new_element];
|
60
63
|
}
|
data/{src → ext/texplay}/cache.h
RENAMED
File without changes
|
File without changes
|
@@ -11,11 +11,11 @@ elsif RUBY_PLATFORM =~ /darwin/
|
|
11
11
|
$CPPFLAGS += " -I/System/Library/Frameworks/GLUT.framework/Headers"
|
12
12
|
|
13
13
|
# windows
|
14
|
-
else
|
14
|
+
else
|
15
15
|
exit unless have_library("glut32")
|
16
16
|
end
|
17
17
|
|
18
18
|
# 1.9 compatibility
|
19
19
|
$CPPFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/
|
20
20
|
|
21
|
-
create_makefile('
|
21
|
+
create_makefile('texplay')
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/{src → ext/texplay}/utils.c
RENAMED
@@ -793,6 +793,8 @@ sync_to_gl(int tex_name, int x_offset, int y_offset, int width, int height, void
|
|
793
793
|
/* sync subtexture */
|
794
794
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x_offset, y_offset, width, height,
|
795
795
|
GL_RGBA, GL_FLOAT, sub);
|
796
|
+
|
797
|
+
glDisable(GL_TEXTURE_2D);
|
796
798
|
}
|
797
799
|
|
798
800
|
void
|
@@ -948,21 +950,22 @@ fact(int n)
|
|
948
950
|
unsigned
|
949
951
|
comb(int n, int r)
|
950
952
|
{
|
951
|
-
double temp = fact(n) / (fact(r) * fact(n - r));
|
952
|
-
return temp;
|
953
|
-
|
953
|
+
/* double temp = fact(n) / (fact(r) * fact(n - r)); */
|
954
|
+
/* return temp; */
|
955
|
+
|
956
|
+
/* nCr is symmetrical about n / 2 */
|
957
|
+
if(r > (n / 2))
|
954
958
|
r = n - r;
|
955
959
|
|
956
960
|
return perm(n, r) / fact(r);
|
957
|
-
*/
|
958
961
|
}
|
959
962
|
|
960
963
|
unsigned
|
961
964
|
perm(int n, int r)
|
962
965
|
{
|
963
|
-
int val =
|
966
|
+
int val = 1;
|
964
967
|
int i;
|
965
|
-
for(i = n
|
968
|
+
for(i = n; i > (n - r); i--)
|
966
969
|
val *= i;
|
967
970
|
|
968
971
|
return val;
|
@@ -971,6 +974,6 @@ perm(int n, int r)
|
|
971
974
|
double
|
972
975
|
bernstein(int n, int k, float u)
|
973
976
|
{
|
974
|
-
double temp = comb(n, k) * pow(u, k) *
|
977
|
+
double temp = comb(n, k) * pow(u, k) * pow(1 - u, n - k);
|
975
978
|
return temp;
|
976
979
|
}
|
data/{src → ext/texplay}/utils.h
RENAMED
File without changes
|
Binary file
|
Binary file
|
data/lib/texplay-contrib.rb
CHANGED
@@ -1,149 +1,171 @@
|
|
1
|
-
begin
|
2
|
-
require 'rubygems'
|
3
|
-
rescue LoadError
|
4
|
-
end
|
5
|
-
|
6
|
-
require 'texplay'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@turtle_pos.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@turtle_pos.
|
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
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
when "
|
137
|
-
|
138
|
-
when "
|
139
|
-
turn(theta)
|
140
|
-
when "
|
141
|
-
|
142
|
-
when "
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|