texplay 0.2.4-x86-mswin32-60 → 0.2.5-x86-mswin32-60

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.
Files changed (44) hide show
  1. data/CHANGELOG +94 -88
  2. data/README.markdown +35 -35
  3. data/Rakefile +66 -87
  4. data/examples/example_bezier.rb +1 -1
  5. data/examples/example_dup.rb +24 -1
  6. data/examples/example_lsystem.rb +59 -51
  7. data/examples/example_scale.rb +29 -0
  8. data/{src → ext/texplay}/actions.c +2 -2
  9. data/{src → ext/texplay}/actions.h +0 -0
  10. data/{src → ext/texplay}/bindings.c +0 -0
  11. data/{src → ext/texplay}/bindings.h +0 -0
  12. data/{src → ext/texplay}/cache.c +5 -2
  13. data/{src → ext/texplay}/cache.h +0 -0
  14. data/{src → ext/texplay}/compat.h +0 -0
  15. data/{src → ext/texplay}/extconf.rb +2 -2
  16. data/{src → ext/texplay}/gen_eval.c +0 -0
  17. data/{src → ext/texplay}/gen_eval.h +0 -0
  18. data/{src → ext/texplay}/object2module.c +0 -0
  19. data/{src → ext/texplay}/object2module.h +0 -0
  20. data/{src → ext/texplay}/texplay.c +1 -1
  21. data/{src → ext/texplay}/texplay.h +0 -0
  22. data/{src → ext/texplay}/utils.c +10 -7
  23. data/{src → ext/texplay}/utils.h +0 -0
  24. data/lib/{ctexplay.18.so → 1.8/texplay.so} +0 -0
  25. data/lib/{ctexplay.19.so → 1.9/texplay.so} +0 -0
  26. data/lib/texplay-contrib.rb +171 -149
  27. data/lib/texplay.rb +134 -134
  28. metadata +21 -36
  29. data/src/Makefile +0 -212
  30. data/src/TAGS +0 -286
  31. data/src/actions.obj +0 -0
  32. data/src/bindings.obj +0 -0
  33. data/src/cache.obj +0 -0
  34. data/src/ctexplay-i386-mswin32.def +0 -2
  35. data/src/ctexplay-i386-mswin32.exp +0 -0
  36. data/src/ctexplay-i386-mswin32.lib +0 -0
  37. data/src/ctexplay-i386-mswin32.pdb +0 -0
  38. data/src/ctexplay.so +0 -0
  39. data/src/gen_eval.obj +0 -0
  40. data/src/mkmf.log +0 -33
  41. data/src/object2module.obj +0 -0
  42. data/src/texplay.obj +0 -0
  43. data/src/utils.obj +0 -0
  44. data/src/vc60.pdb +0 -0
@@ -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
- Bush1 = TexPlay::LSystem.new do
14
- rule "F" => "F[-F]F[+F][F]"
15
-
16
- angle 20
17
- atom "F"
18
- end
19
-
20
- Bush2 = TexPlay::LSystem.new do
21
- rule "F" => "FF"
22
- rule "X" => "F[+X]F[-X]+X"
23
-
24
- angle 20
25
- atom "X"
26
- end
27
-
28
- Bush3 = TexPlay::LSystem.new do
29
- rule "F" => "FF"
30
- rule "X" => "F-[[X]+X]+F[+FX]-X"
31
-
32
- angle 22.5
33
- atom "X"
34
- end
35
-
36
-
37
-
38
- class W < Gosu::Window
39
- def initialize
40
- super(1024, 768, false, 20)
41
- @img = TexPlay::create_blank_image(self, 500, 500)
42
- @img.lsystem(0, 250, Bush2, :order => 5, :line_length => 5)
43
- end
44
-
45
- def draw
46
- @img.draw(100,0,1)
47
- end
48
- end
49
-
50
- w = W.new
51
- w.show
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 > 13)
791
- rb_raise(rb_eArgError, "too many points for bezier curve. 13 points is current maximum. got %d\n",
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
@@ -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
  }
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('ctexplay')
21
+ create_makefile('texplay')
File without changes
File without changes
File without changes
File without changes
@@ -19,7 +19,7 @@
19
19
  static VALUE m_init_TPPoint(int argc, VALUE * argv, VALUE self);
20
20
 
21
21
  void
22
- Init_ctexplay() {
22
+ Init_texplay() {
23
23
 
24
24
  VALUE jm_Module = rb_define_module("TexPlay");
25
25
  VALUE TPPoint = rb_define_class_under(jm_Module, "TPPoint", rb_cObject);
File without changes
@@ -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
- /* if(r > (n / 2))
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 = n;
966
+ int val = 1;
964
967
  int i;
965
- for(i = n - 1; i > (n - r); i--)
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) * power(1 - u, n - k);
977
+ double temp = comb(n, k) * pow(u, k) * pow(1 - u, n - k);
975
978
  return temp;
976
979
  }
File without changes
@@ -1,149 +1,171 @@
1
- begin
2
- require 'rubygems'
3
- rescue LoadError
4
- end
5
-
6
- require 'texplay'
7
-
8
- if RUBY_VERSION =~ /1.8/
9
- require 'jcode'
10
- end
11
-
12
- # setup will be executed straight after Gosu::Image instantiation
13
- TexPlay::on_setup do
14
- @turtle_pos = TexPlay::TPPoint.new(width / 2, height / 2 )
15
- @turtle_angle = 0
16
- end
17
-
18
-
19
- TexPlay::create_macro(:move_to) do |x, y|
20
- capture {
21
- @turtle_pos.x = x
22
- @turtle_pos.y = y
23
- }
24
- end
25
-
26
- TexPlay::create_macro(:move_rel) do |dx, dy|
27
- capture {
28
- @turtle_pos.x += dx
29
- @turtle_pos.y += dy
30
- }
31
- end
32
-
33
- TexPlay::create_macro(:line_to) do |x, y, *other|
34
- capture {
35
- line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
36
-
37
- @turtle_pos.x, @turtle_pos.y = x, y
38
- }
39
- end
40
-
41
- TexPlay::create_macro(:line_rel) do |dx, dy, *other|
42
- capture {
43
- x = @turtle_pos.x + dx
44
- y = @turtle_pos.y + dy
45
-
46
- line(@turtle_pos.x, @turtle_pos.y, x, y, *other)
47
-
48
- @turtle_pos.x, @turtle_pos.y = x, y
49
- }
50
- end
51
-
52
- TexPlay::create_macro(:turn_to) do |a|
53
- capture {
54
- @turtle_angle = a
55
- }
56
- end
57
-
58
- TexPlay::create_macro(:turn) do |da|
59
- capture {
60
- @turtle_angle += da
61
- }
62
- end
63
-
64
- TexPlay::create_macro(:forward) do |dist, *other|
65
- capture {
66
- visible = other.shift
67
-
68
- radians_per_degree = 0.0174532925199433
69
-
70
- x = @turtle_pos.x + dist * Math::cos(radians_per_degree * @turtle_angle)
71
- y = @turtle_pos.y + dist * Math::sin(radians_per_degree * @turtle_angle)
72
-
73
- if(visible) then
74
- line_to(x, y, *other)
75
- else
76
- move_to(x, y)
77
- end
78
- }
79
- end
80
-
81
- ## L-System code
82
-
83
- # monkeypatches to TexPlay class
84
- module TexPlay
85
- class LSystem
86
- def initialize(&block)
87
- @rules = {}
88
-
89
- instance_eval(&block) if block
90
- end
91
-
92
- def rule(new_rule)
93
- @rules.merge!(new_rule)
94
- end
95
-
96
- def atom(new_atom)
97
- @atom = new_atom
98
- end
99
-
100
- def angle(new_angle=nil)
101
- return @angle if !new_angle
102
- @angle = new_angle
103
- end
104
-
105
- def produce_string(order)
106
- order = order[:order]
107
- string = @atom.dup
108
-
109
- order.times do
110
- i = 0
111
- while(i < string.length)
112
- sub = @rules[string[i, 1]]
113
-
114
- string[i] = sub if sub
115
-
116
- i += sub ? sub.length : 1
117
- end
118
- end
119
-
120
- string
121
- end
122
- end
123
- end
124
-
125
- # L-System macro
126
- TexPlay::create_macro(:lsystem) do |x, y, system, options|
127
- capture {
128
- theta = system.angle
129
- turtle_stack = []
130
- move_to(x, y)
131
- line_length = options[:line_length] || 1
132
-
133
- system.produce_string(options).each_char do |v|
134
-
135
- case v
136
- when "F"
137
- forward(line_length, true)
138
- when "+"
139
- turn(theta)
140
- when "-"
141
- turn(-theta)
142
- when "["
143
- turtle_stack.push([@turtle_pos.dup, @turtle_angle])
144
- when "]"
145
- @turtle_pos, @turtle_angle = turtle_stack.pop
146
- end
147
- end
148
- }
149
- 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