texplay 0.2.1 → 0.2.2
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 +10 -0
- data/README.markdown +35 -0
- data/README1st +1 -1
- data/Rakefile +6 -6
- data/examples/example_alpha_blend.rb +1 -1
- data/examples/example_bezier.rb +4 -13
- data/examples/example_color_control.rb +3 -2
- data/examples/example_color_transform.rb +3 -3
- data/examples/example_dup.rb +1 -1
- data/examples/example_each.rb +1 -1
- data/examples/example_effect.rb +1 -1
- data/examples/example_fill.rb +4 -9
- data/examples/example_fill_old.rb +1 -1
- data/examples/example_fluent.rb +1 -1
- data/examples/example_gen_eval.rb +1 -1
- data/examples/example_hash_arguments.rb +1 -1
- data/examples/example_melt.rb +1 -1
- data/examples/example_polyline.rb +1 -1
- data/examples/example_simple.rb +4 -1
- data/examples/example_splice.rb +9 -13
- data/examples/example_sync.rb +1 -1
- data/examples/example_turtle.rb +2 -2
- data/lib/texplay-contrib.rb +8 -8
- data/lib/texplay.rb +9 -9
- data/src/actions.c +80 -55
- data/src/bindings.c +2 -2
- data/src/texplay.c +1 -1
- data/src/utils.c +6 -5
- metadata +3 -9
- data/README +0 -21
- data/examples/basic.rb +0 -48
- data/examples/basic2.rb +0 -37
- data/examples/benchmark.rb +0 -299
- data/examples/specs.rb +0 -240
- data/examples/test.rb +0 -70
- data/examples/test2.rb +0 -72
data/src/actions.c
CHANGED
@@ -23,7 +23,6 @@ static void draw_epilogue(action_struct * cur, texture_info * tex, bool primary)
|
|
23
23
|
|
24
24
|
static void prepare_fill_texture(action_struct * cur);
|
25
25
|
static void prepare_color_control(action_struct * cur);
|
26
|
-
static rgba exec_color_control_proc(action_struct * cur, texture_info * tex, int x, int y);
|
27
26
|
static void set_pixel_color_with_style(action_struct * payload, texture_info * tex,
|
28
27
|
int x, int y);
|
29
28
|
/* end helpers */
|
@@ -225,12 +224,13 @@ ngon_do_action(int x, int y, int r, int num_sides, texture_info * tex, VALUE has
|
|
225
224
|
int x1, y1, x2, y2, x0, y0;
|
226
225
|
int n;
|
227
226
|
int thickness;
|
227
|
+
float angle = 0;
|
228
228
|
|
229
229
|
draw_prologue(&cur, tex, x - r, y - r,
|
230
230
|
x + r, y + r, &hash_arg, sync_mode, primary, &payload);
|
231
231
|
|
232
232
|
|
233
|
-
if(is_a_hash(hash_arg))
|
233
|
+
if(is_a_hash(hash_arg)) {
|
234
234
|
if(RTEST(get_from_hash(hash_arg, "thickness"))) {
|
235
235
|
thickness = NUM2INT(get_from_hash(hash_arg, "thickness"));
|
236
236
|
|
@@ -241,13 +241,18 @@ ngon_do_action(int x, int y, int r, int num_sides, texture_info * tex, VALUE has
|
|
241
241
|
cur.ymax = y + r + thickness / 2;
|
242
242
|
}
|
243
243
|
|
244
|
+
if(RTEST(get_from_hash(hash_arg, "start_angle"))) {
|
245
|
+
angle = NUM2INT(get_from_hash(hash_arg, "start_angle")) / 360.0 * 2 * PI;
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
244
249
|
/* calculate first point */
|
245
|
-
x0 = x1 = x + r;
|
246
|
-
y0 = y1 = y;
|
250
|
+
x0 = x1 = x + r * cos(angle);
|
251
|
+
y0 = y1 = y + r * sin(angle);
|
247
252
|
|
248
253
|
for(n = 0; n < num_sides; n++) {
|
249
|
-
x2 = x + r * cos((2 * PI / num_sides) * n);
|
250
|
-
y2 = y + r * sin((2 * PI / num_sides) * n);
|
254
|
+
x2 = x + r * cos((2 * PI / num_sides) * n + angle);
|
255
|
+
y2 = y + r * sin((2 * PI / num_sides) * n + angle);
|
251
256
|
|
252
257
|
line_do_action(x1, y1, x2, y2, tex, hash_arg, no_sync, false, payload);
|
253
258
|
|
@@ -919,10 +924,11 @@ splice_do_action(int x0, int y0, int cx1, int cy1, int cx2, int cy2, texture_inf
|
|
919
924
|
payload->color = get_pixel_color_from_chunk(image_buf, xbound, ybound, x, y);
|
920
925
|
|
921
926
|
if(has_chroma) {
|
922
|
-
bool
|
923
|
-
|
924
|
-
|
925
|
-
|
927
|
+
bool chroma_match = cmp_color(payload->color, chromakey);
|
928
|
+
|
929
|
+
/* look at released 0.2.0 code to see how USED to do this.
|
930
|
+
this is now a simplified boolean expression */
|
931
|
+
if(chroma_match == inverse_chroma)
|
926
932
|
set_pixel_color_with_style(payload, tex, x0 + x, y0 + y);
|
927
933
|
}
|
928
934
|
else
|
@@ -1175,18 +1181,23 @@ prepare_color_control(action_struct * cur)
|
|
1175
1181
|
}
|
1176
1182
|
|
1177
1183
|
static rgba
|
1178
|
-
exec_color_control_proc(action_struct * cur, texture_info * tex, int x, int y)
|
1184
|
+
exec_color_control_proc(action_struct * cur, texture_info * tex, int x, int y, rgba blended_pixel)
|
1179
1185
|
{
|
1180
1186
|
int arity = cur->pen.color_control_arity;
|
1181
1187
|
VALUE proc = cur->pen.color_control_proc;
|
1182
1188
|
rgba old_color = get_pixel_color(tex, x, y);
|
1183
|
-
rgba current_color =
|
1189
|
+
rgba current_color = blended_pixel;
|
1184
1190
|
rgba new_color;
|
1185
1191
|
|
1186
1192
|
if(!cur->pen.has_color_control_proc)
|
1187
1193
|
rb_raise(rb_eRuntimeError, "needs a proc");
|
1188
1194
|
|
1189
1195
|
switch(arity) {
|
1196
|
+
case -1:
|
1197
|
+
case 0:
|
1198
|
+
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), 0));
|
1199
|
+
break;
|
1200
|
+
|
1190
1201
|
case 1:
|
1191
1202
|
new_color = convert_rb_color_to_rgba(rb_funcall(proc, rb_intern("call"), arity,
|
1192
1203
|
convert_rgba_to_rb_color(&old_color)));
|
@@ -1231,20 +1242,57 @@ prepare_fill_texture(action_struct * payload)
|
|
1231
1242
|
}
|
1232
1243
|
}
|
1233
1244
|
|
1234
|
-
|
1245
|
+
|
1246
|
+
/* TODO: reimplement using SSE2 */
|
1247
|
+
static rgba
|
1235
1248
|
apply_color_control_transform(action_struct * payload, texture_info * tex, int x, int y)
|
1249
|
+
|
1236
1250
|
{
|
1237
|
-
|
1251
|
+
rgba transformed_color;
|
1252
|
+
|
1253
|
+
transformed_color = get_pixel_color(tex, x, y);
|
1238
1254
|
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1255
|
+
transformed_color.red += payload->pen.color_add.red;
|
1256
|
+
transformed_color.green += payload->pen.color_add.green;
|
1257
|
+
transformed_color.blue += payload->pen.color_add.blue;
|
1258
|
+
transformed_color.alpha += payload->pen.color_add.alpha;
|
1259
|
+
|
1260
|
+
transformed_color.red *= payload->pen.color_mult.red;
|
1261
|
+
transformed_color.green *= payload->pen.color_mult.green;
|
1262
|
+
transformed_color.blue *= payload->pen.color_mult.blue;
|
1263
|
+
transformed_color.alpha *= payload->pen.color_mult.alpha;
|
1264
|
+
|
1265
|
+
return transformed_color;
|
1266
|
+
}
|
1267
|
+
|
1268
|
+
static rgba
|
1269
|
+
apply_alpha_blend(action_struct * payload, texture_info * tex, int x, int y, rgba blended_pixel)
|
1270
|
+
{
|
1271
|
+
rgba dest_pixel = get_pixel_color(tex, x, y);
|
1272
|
+
rgba finished_pixel;
|
1273
|
+
|
1274
|
+
|
1275
|
+
if(not_a_color(blended_pixel))
|
1276
|
+
return blended_pixel;
|
1277
|
+
|
1278
|
+
/* alpha blending is nothing more than a weighted average of src and dest pixels
|
1279
|
+
based on source alpha value */
|
1280
|
+
/* NB: destination alpha value is ignored */
|
1281
|
+
|
1282
|
+
/** TO DO: rewrite this using sse2 instructions **/
|
1283
|
+
finished_pixel.red = blended_pixel.alpha * blended_pixel.red + (1 - blended_pixel.alpha)
|
1284
|
+
* dest_pixel.red;
|
1285
|
+
|
1286
|
+
finished_pixel.green = blended_pixel.alpha * blended_pixel.green + (1 - blended_pixel.alpha)
|
1287
|
+
* dest_pixel.green;
|
1288
|
+
|
1289
|
+
finished_pixel.blue = blended_pixel.alpha * blended_pixel.blue + (1 - blended_pixel.alpha)
|
1290
|
+
* dest_pixel.blue;
|
1291
|
+
|
1292
|
+
finished_pixel.alpha = blended_pixel.alpha;
|
1293
|
+
|
1294
|
+
|
1295
|
+
return finished_pixel;
|
1248
1296
|
}
|
1249
1297
|
|
1250
1298
|
static void
|
@@ -1253,53 +1301,30 @@ set_pixel_color_with_style(action_struct * payload, texture_info * tex, int x, i
|
|
1253
1301
|
|
1254
1302
|
rgba blended_pixel;
|
1255
1303
|
|
1304
|
+
blended_pixel = payload->color;
|
1305
|
+
|
1256
1306
|
/* for color_control transform */
|
1257
1307
|
if(payload->pen.has_color_control_transform)
|
1258
|
-
apply_color_control_transform(payload, tex, x, y);
|
1308
|
+
blended_pixel = apply_color_control_transform(payload, tex, x, y);
|
1259
1309
|
|
1260
1310
|
/* for texture fill */
|
1261
1311
|
if(payload->pen.has_source_texture)
|
1262
|
-
|
1312
|
+
blended_pixel = get_pixel_color(&payload->pen.source_tex,
|
1263
1313
|
x % payload->pen.source_tex.width,
|
1264
1314
|
y % payload->pen.source_tex.height);
|
1265
1315
|
|
1266
1316
|
/* for color_control block */
|
1267
1317
|
if(payload->pen.has_color_control_proc)
|
1268
|
-
|
1318
|
+
blended_pixel = exec_color_control_proc(payload, tex, x, y, blended_pixel);
|
1269
1319
|
|
1270
1320
|
|
1271
1321
|
/* TO DO: do bitwise pixel combinations here */
|
1272
1322
|
|
1273
|
-
/*
|
1274
|
-
code below i get an interesting blurring effect in images (with alpha_blend => true)
|
1275
|
-
*/
|
1276
|
-
blended_pixel = payload->color;
|
1277
|
-
|
1278
|
-
|
1279
|
-
/* alpha blending
|
1280
|
-
TO DO: refactor into its own helper function
|
1323
|
+
/* TO DO: refactor into its own helper function
|
1281
1324
|
& rewrite using sse2 */
|
1282
|
-
if(payload->pen.alpha_blend)
|
1283
|
-
|
1284
|
-
|
1285
|
-
/* alpha blending is nothing more than a weighted average of src and dest pixels
|
1286
|
-
based on source alpha value */
|
1287
|
-
/* NB: destination alpha value is ignored */
|
1288
|
-
if(is_a_color(payload->color) && is_a_color(dest_pixel)) {
|
1289
|
-
|
1290
|
-
/** TO DO: rewrite this using sse2 instructions **/
|
1291
|
-
blended_pixel.red = payload->color.alpha * payload->color.red + (1 - payload->color.alpha)
|
1292
|
-
* dest_pixel.red;
|
1293
|
-
|
1294
|
-
blended_pixel.green = payload->color.alpha * payload->color.green + (1 - payload->color.alpha)
|
1295
|
-
* dest_pixel.green;
|
1296
|
-
|
1297
|
-
blended_pixel.blue = payload->color.alpha * payload->color.blue + (1 - payload->color.alpha)
|
1298
|
-
* dest_pixel.blue;
|
1299
|
-
|
1300
|
-
blended_pixel.alpha = payload->color.alpha;
|
1301
|
-
}
|
1302
|
-
}
|
1325
|
+
if(payload->pen.alpha_blend)
|
1326
|
+
blended_pixel = apply_alpha_blend(payload, tex, x, y, blended_pixel);
|
1327
|
+
|
1303
1328
|
|
1304
1329
|
set_pixel_color(&blended_pixel, tex, x, y);
|
1305
1330
|
}
|
data/src/bindings.c
CHANGED
@@ -369,7 +369,7 @@ m_circle(int argc, VALUE * argv, VALUE self)
|
|
369
369
|
|
370
370
|
ADJUST_SELF(self);
|
371
371
|
|
372
|
-
if(argc <
|
372
|
+
if(argc < 2) rb_raise(rb_eArgError, "circle action needs at least 2 parameter");
|
373
373
|
|
374
374
|
process_x_y_pairs(self, 1, argv, &x1, &y1);
|
375
375
|
|
@@ -398,7 +398,7 @@ m_ngon(int argc, VALUE * argv, VALUE self)
|
|
398
398
|
|
399
399
|
ADJUST_SELF(self);
|
400
400
|
|
401
|
-
if(argc <
|
401
|
+
if(argc < 3) rb_raise(rb_eArgError, "ngon requires at least 3 parameters (x, y, radius, num_sides)");
|
402
402
|
|
403
403
|
process_x_y_pairs(self, 1, argv, &x1, &y1);
|
404
404
|
|
data/src/texplay.c
CHANGED
@@ -68,7 +68,7 @@ Init_ctexplay() {
|
|
68
68
|
rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0);
|
69
69
|
|
70
70
|
/* a constant containing the sidelength of largest allowable quad */
|
71
|
-
rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size()));
|
71
|
+
rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size() - 2));
|
72
72
|
|
73
73
|
/* singleton method for creating & removing macros */
|
74
74
|
rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1);
|
data/src/utils.c
CHANGED
@@ -585,9 +585,9 @@ ComputeOutCode (int x, int y, int xmin, int ymin, int xmax, int ymax)
|
|
585
585
|
return code;
|
586
586
|
}
|
587
587
|
|
588
|
-
|
589
|
-
|
590
|
-
|
588
|
+
/** Cohen-Sutherland clipping algorithm clips a line from
|
589
|
+
P0 = (x0, y0) to P1 = (x1, y1) against a rectangle with
|
590
|
+
diagonal from (xmin, ymin) to (xmax, ymax). **/
|
591
591
|
void
|
592
592
|
cohen_sutherland_clip (int * x0, int * y0,int * x1, int * y1, int xmin, int ymin,
|
593
593
|
int xmax, int ymax)
|
@@ -762,7 +762,7 @@ check_for_texture_info(VALUE image)
|
|
762
762
|
rb_raise(rb_eException, "Error: gl_tex_info returns nil for %s (%i x %i). Could be caused by "
|
763
763
|
"very large image or Gosu bug. Try updating Gosu or use a smaller image. Note: TexPlay should"
|
764
764
|
" be able to work with %i x %i images.",
|
765
|
-
StringValuePtr(image_name), width, height, max_quad_size(), max_quad_size());
|
765
|
+
StringValuePtr(image_name), width, height, max_quad_size() - 2, max_quad_size() - 2);
|
766
766
|
}
|
767
767
|
|
768
768
|
return info;
|
@@ -897,7 +897,8 @@ bool
|
|
897
897
|
is_a_point(VALUE try_point)
|
898
898
|
{
|
899
899
|
/* if it responds to 'x' it's near enough (technically must respond to x AND y) */
|
900
|
-
|
900
|
+
/* added the is_a_num() check due to WEIRD bug where FIXNUMS were responding to the 'x' method (wtf?) but returning nil when invoked */
|
901
|
+
if(rb_respond_to(try_point, rb_intern("x")) && !is_a_num(try_point))
|
901
902
|
return true;
|
902
903
|
|
903
904
|
return false;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texplay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mair (banisterfiend)
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-09 00:00:00 +12:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ extra_rdoc_files: []
|
|
32
32
|
|
33
33
|
files:
|
34
34
|
- Rakefile
|
35
|
-
- README
|
35
|
+
- README.markdown
|
36
36
|
- CHANGELOG
|
37
37
|
- README1st
|
38
38
|
- lib/texplay.rb
|
@@ -64,22 +64,16 @@ files:
|
|
64
64
|
- examples/example_hash_arguments.rb
|
65
65
|
- examples/example_gen_eval.rb
|
66
66
|
- examples/example_polyline.rb
|
67
|
-
- examples/basic.rb
|
68
|
-
- examples/test.rb
|
69
67
|
- examples/example_fill.rb
|
70
68
|
- examples/example_bezier.rb
|
71
69
|
- examples/example_simple.rb
|
72
70
|
- examples/example_fill_old.rb
|
73
71
|
- examples/example_each.rb
|
74
|
-
- examples/benchmark.rb
|
75
72
|
- examples/example_fluent.rb
|
76
73
|
- examples/example_sync.rb
|
77
74
|
- examples/example_splice.rb
|
78
75
|
- examples/example_alpha_blend.rb
|
79
|
-
- examples/basic2.rb
|
80
76
|
- examples/example_melt.rb
|
81
|
-
- examples/test2.rb
|
82
|
-
- examples/specs.rb
|
83
77
|
- examples/media/sand1.png
|
84
78
|
- examples/media/rose.bmp
|
85
79
|
- examples/media/maria.png
|
data/README
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
INSTRUCTIONS
|
2
|
-
|
3
|
-
TexPlay version 0.2.1
|
4
|
-
|
5
|
-
To compile TexPlay, ensure you are in the directory with the Rakefile and type:
|
6
|
-
=> rake
|
7
|
-
OR
|
8
|
-
=> rake19 (assuming this is the name of your 1.9.1 version of rake)
|
9
|
-
|
10
|
-
!!NB!! be sure to run the version of rake that corresponds to the ruby version you wish to use! on my system I use rake19 for ruby 1.9.1!!
|
11
|
-
|
12
|
-
If all goes well, run the example programs:
|
13
|
-
=> cd examples
|
14
|
-
=> ruby example_melt.rb
|
15
|
-
=> ruby example_simple.rb
|
16
|
-
=> ..etc
|
17
|
-
|
18
|
-
*like any gosu application, gosu.so must be in the current directory (or the gosu gem installed) when running the examples.
|
19
|
-
|
20
|
-
Enjoy!
|
21
|
-
(note that TexPlay has only been tested on 32 bit linux systems and WindowsXP using VS 6.0)
|
data/examples/basic.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'common'
|
4
|
-
|
5
|
-
require 'gosu'
|
6
|
-
require 'texplay'
|
7
|
-
|
8
|
-
class W < Gosu::Window
|
9
|
-
def initialize
|
10
|
-
super(1024, 769, false, 20)
|
11
|
-
@img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
|
12
|
-
@img.rect 0,0, @img.width - 1, @img.height - 1
|
13
|
-
|
14
|
-
@img.instance_variable_set(:@horse, :love)
|
15
|
-
class << @img
|
16
|
-
def little
|
17
|
-
:little
|
18
|
-
end
|
19
|
-
end
|
20
|
-
@bunk = @img.clone
|
21
|
-
puts @bunk.instance_variable_get(:@horse)
|
22
|
-
puts @bunk.little
|
23
|
-
end
|
24
|
-
|
25
|
-
def draw
|
26
|
-
x = @img.width * rand
|
27
|
-
y = @img.height * rand
|
28
|
-
|
29
|
-
@img.
|
30
|
-
line(0, 0, 1024, 1024).
|
31
|
-
circle(20, 20, 50).
|
32
|
-
rect 30, 30, 100, 100
|
33
|
-
|
34
|
-
@img.draw 100, 50,1
|
35
|
-
@bunk.draw 500, 300,1
|
36
|
-
@bunk.line 0, 0, 1024, 1024, :color => :red
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@bunk.pixel x, y, :color => :none
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
w = W.new
|
47
|
-
w.show
|
48
|
-
|
data/examples/basic2.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'common'
|
3
|
-
require 'gosu'
|
4
|
-
require 'texplay'
|
5
|
-
|
6
|
-
class Proc
|
7
|
-
def __context__
|
8
|
-
eval('self', self.binding)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class W < Gosu::Window
|
13
|
-
def initialize
|
14
|
-
super(1024, 769, false, 20)
|
15
|
-
@img = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
16
|
-
end
|
17
|
-
|
18
|
-
def trick
|
19
|
-
@img.dup_eval { self }
|
20
|
-
end
|
21
|
-
|
22
|
-
def draw
|
23
|
-
@img.paint {
|
24
|
-
circle -5100, -9700, 20
|
25
|
-
circle(@img.width * rand * 2 - @img.width, @img.height * rand * 2 - @img.height, 40)
|
26
|
-
}
|
27
|
-
@img.draw(100,100,1)
|
28
|
-
end
|
29
|
-
|
30
|
-
def img
|
31
|
-
@img
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
w = W.new
|
36
|
-
w.show
|
37
|
-
|