texplay 0.2.7-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/CHANGELOG +103 -0
  2. data/README.markdown +41 -0
  3. data/Rakefile +61 -0
  4. data/examples/common.rb +8 -0
  5. data/examples/example_alpha_blend.rb +31 -0
  6. data/examples/example_bezier.rb +42 -0
  7. data/examples/example_blur.rb +59 -0
  8. data/examples/example_color_control.rb +69 -0
  9. data/examples/example_color_transform.rb +29 -0
  10. data/examples/example_dup.rb +75 -0
  11. data/examples/example_each.rb +42 -0
  12. data/examples/example_effect.rb +35 -0
  13. data/examples/example_fill.rb +44 -0
  14. data/examples/example_fill_old.rb +49 -0
  15. data/examples/example_fluent.rb +31 -0
  16. data/examples/example_gen_eval.rb +34 -0
  17. data/examples/example_hash_arguments.rb +47 -0
  18. data/examples/example_lsystem.rb +61 -0
  19. data/examples/example_melt.rb +27 -0
  20. data/examples/example_polyline.rb +43 -0
  21. data/examples/example_scale.rb +29 -0
  22. data/examples/example_simple.rb +38 -0
  23. data/examples/example_splice.rb +33 -0
  24. data/examples/example_sync.rb +60 -0
  25. data/examples/example_turtle.rb +40 -0
  26. data/examples/media/empty2.png +0 -0
  27. data/examples/media/gosu.png +0 -0
  28. data/examples/media/logo.png +0 -0
  29. data/examples/media/maria.png +0 -0
  30. data/examples/media/rose.bmp +0 -0
  31. data/examples/media/sand1.png +0 -0
  32. data/examples/media/sunset.png +0 -0
  33. data/examples/media/texplay.png +0 -0
  34. data/ext/texplay/actions.c +1331 -0
  35. data/ext/texplay/actions.h +52 -0
  36. data/ext/texplay/bindings.c +1129 -0
  37. data/ext/texplay/bindings.h +46 -0
  38. data/ext/texplay/cache.c +135 -0
  39. data/ext/texplay/cache.h +24 -0
  40. data/ext/texplay/compat.h +27 -0
  41. data/ext/texplay/extconf.rb +30 -0
  42. data/ext/texplay/gen_eval.c +211 -0
  43. data/ext/texplay/gen_eval.h +20 -0
  44. data/ext/texplay/object2module.c +171 -0
  45. data/ext/texplay/object2module.h +11 -0
  46. data/ext/texplay/texplay.c +137 -0
  47. data/ext/texplay/texplay.h +107 -0
  48. data/ext/texplay/utils.c +978 -0
  49. data/ext/texplay/utils.h +145 -0
  50. data/lib/1.8/texplay.so +0 -0
  51. data/lib/1.9/texplay.so +0 -0
  52. data/lib/texplay-contrib.rb +171 -0
  53. data/lib/texplay.rb +134 -0
  54. metadata +114 -0
@@ -0,0 +1,145 @@
1
+ #ifndef GUARD_UTILS_H
2
+ #define GUARD_UTILS_H
3
+
4
+
5
+ /* for use with get_image_local, and set_image_local */
6
+ #define DRAW_OFFSET 0
7
+ #define LAZY_BOUNDS 1
8
+ #define IMAGE_COLOR 2
9
+ #define USER_DEFAULTS 3
10
+
11
+
12
+ /* color and pixel related functions */
13
+ rgba find_color_from_string(char * try_color);
14
+ bool cmp_color(rgba color1, rgba color2);
15
+ void color_copy(float * source, float * dest);
16
+ rgba get_pixel_color(texture_info * tex, int x, int y) ;
17
+ float* get_pixel_data(texture_info * tex, int x, int y);
18
+ void set_pixel_color(rgba * pixel_color, texture_info * tex, int x, int y);
19
+ void zero_color(float * tex);
20
+ bool not_a_color(rgba color1);
21
+ bool is_a_color(rgba color1);
22
+ VALUE convert_rgba_to_rb_color(rgba * pix);
23
+ rgba convert_rb_color_to_rgba(VALUE cval);
24
+
25
+ VALUE save_rgba_to_image_local_color(VALUE image, rgba color);
26
+ rgba convert_image_local_color_to_rgba(VALUE image);
27
+
28
+
29
+ /* string/symbol related functions */
30
+ char* lowercase(char*);
31
+ char* sym2string(VALUE);
32
+ VALUE string2sym(char*);
33
+
34
+ /* is it a hash? */
35
+ bool is_a_hash(VALUE try_hash);
36
+
37
+ /* is an array? */
38
+ bool is_an_array(VALUE try_array);
39
+
40
+ /* is a num? */
41
+ bool is_a_num(VALUE try_num);
42
+
43
+ /* helpful C wrapper for rb_hash_aref */
44
+ VALUE get_from_hash(VALUE hash, char * sym);
45
+
46
+ /* a wrapper for rb_hash_aset */
47
+ VALUE set_hash_value(VALUE hash, char * sym, VALUE val);
48
+
49
+ /* a wrapper for rb_hash_delete */
50
+ VALUE delete_from_hash(VALUE hash, char * sym);
51
+
52
+ /* does the hash key 'sym' map to value 'val'? */
53
+ bool hash_value_is(VALUE hash, char * sym, VALUE val);
54
+
55
+ /* determine whether (1) hash is a T_HASH (2) the sym exists in the hash */
56
+ bool has_optional_hash_arg(VALUE hash, char * sym);
57
+
58
+
59
+ /* helpful C wrapper for rb_array_store */
60
+ VALUE set_array_value(VALUE array, int index, VALUE val);
61
+
62
+ /* helpful C wrapper for rb_array_entry */
63
+ VALUE get_from_array(VALUE array, int index);
64
+
65
+ /* set the lazy_bounds ivar for an image */
66
+ VALUE set_ivar_array(VALUE obj, char * ivar, int argc, ...);
67
+
68
+ /* initialize lazy_bounds */
69
+ void init_lazy_bounds(VALUE image);
70
+
71
+ /* initialize the image_local var array */
72
+ VALUE init_image_local(VALUE image);
73
+
74
+ /* return an image local variable */
75
+ VALUE get_image_local(VALUE image, int name);
76
+
77
+ /* set an image local variable */
78
+ void set_image_local(VALUE image, int name, VALUE val);
79
+
80
+ /* error checking functions */
81
+ void check_mask(VALUE mask);
82
+
83
+ void check_image(VALUE image);
84
+
85
+ /* is try_image a Gosu::Image ? */
86
+ bool is_gosu_image(VALUE try_image);
87
+
88
+ /* create a blank gosu image of width and height */
89
+ VALUE create_image(VALUE window, int width, int height);
90
+
91
+ /* make boundaries sane */
92
+ void constrain_boundaries(int * x0, int * y0, int * x1, int * y1, int width, int height);
93
+
94
+ /* line clipping */
95
+ void cohen_sutherland_clip (int * x0, int * y0,int * x1, int * y1, int xmin, int ymin,
96
+ int xmax, int ymax);
97
+
98
+ /* check if point is bound by rect and inner thickness */
99
+ bool bound_by_rect_and_inner(int x, int y, int x0, int y0, int x1, int y1, int inner);
100
+
101
+ /* check if point is bound by rect */
102
+ bool bound_by_rect(int x, int y, int x0, int y0, int x1, int y1);
103
+
104
+ /* calculate the array offset for a given pixel */
105
+ int calc_pixel_offset(texture_info * tex, int x, int y);
106
+
107
+ /* calculate the array offset for a given pixel in an action context */
108
+ int calc_pixel_offset_for_action(action_struct * cur, texture_info * tex, int x, int y);
109
+
110
+ /* return a pointer to a new texture */
111
+ float* allocate_texture(int width, int height);
112
+
113
+ /* other function prototypes, get info for a texture */
114
+ void get_texture_info(VALUE image, texture_info * tex);
115
+
116
+ /* ensure gl_tex_info returns non nil */
117
+ VALUE check_for_texture_info(VALUE image);
118
+
119
+ /* responsible for syncing a subimage to gl */
120
+ void sync_to_gl(int tex_name, int x_offset, int y_offset, int width, int height, void * sub);
121
+
122
+ /* create a subtexture and sync to gl */
123
+ void create_subtexture_and_sync_to_gl(image_bounds * img_bounds, texture_info * tex);
124
+
125
+ float * get_image_chunk(texture_info * tex, int xmin, int ymin, int xmax, int ymax);
126
+
127
+ rgba get_pixel_color_from_chunk(float * chunk, int width, int height, int x, int y);
128
+
129
+ /* from Texture.cpp in Gosu Graphics folder */
130
+ unsigned max_quad_size(void);
131
+
132
+ /* point utils */
133
+ bool is_a_point(VALUE try_point);
134
+ VALUE point_x(VALUE point);
135
+ VALUE point_y(VALUE point);
136
+
137
+ /* mathematical utils, used by bezier curves */
138
+ double power(float base, int exp);
139
+ unsigned fact(int n);
140
+ unsigned comb(int n, int k);
141
+ unsigned perm(int n, int r);
142
+
143
+ double bernstein(int n, int k, float u);
144
+
145
+ #endif
Binary file
Binary file
@@ -0,0 +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
data/lib/texplay.rb ADDED
@@ -0,0 +1,134 @@
1
+ # (C) John Mair 2009, under the MIT licence
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ end
7
+
8
+ # include gosu first
9
+ require 'rbconfig'
10
+ require 'gosu'
11
+
12
+ module TexPlay
13
+ TEXPLAY_VERSION = "0.2.7"
14
+
15
+ def self::on_setup(&block)
16
+ raise "need a block" if !block
17
+
18
+ @__init_procs__ ||= []
19
+ @__init_procs__.push(block)
20
+ end
21
+
22
+ def self::setup(receiver)
23
+ if @__init_procs__ then
24
+ @__init_procs__.each do |init_proc|
25
+ receiver.instance_eval(&init_proc)
26
+ end
27
+ end
28
+ end
29
+
30
+ def self::create_blank_image(window, width, height)
31
+ Gosu::Image.new(window, EmptyImageStub.new(width, height))
32
+ end
33
+
34
+ module Colors
35
+ Red = [1, 0, 0, 1]
36
+ Green = [0, 1, 0, 1]
37
+ Blue = [0, 0, 1, 1]
38
+ Black = [0, 0, 0, 1]
39
+ White = [1, 1, 1, 1]
40
+ Grey = [0.5, 0.5, 0.5, 1]
41
+ Alpha = [0, 0, 0, 0]
42
+ Purple = [1, 0, 1, 1]
43
+ Yellow = [1, 1, 0, 1]
44
+ Cyan = [0, 1, 1, 1]
45
+ Orange = [1, 0.5, 0, 1]
46
+ Brown = [0.39, 0.26, 0.13, 1]
47
+ Turquoise = [1, 0.6, 0.8, 1]
48
+ Tyrian = [0.4, 0.007, 0.235, 1]
49
+ end
50
+ include Colors
51
+ end
52
+
53
+ # credit to philomory for this class
54
+ class EmptyImageStub
55
+ def initialize(w, h)
56
+ @w, @h = w, h
57
+ end
58
+
59
+ def to_blob
60
+ "\0" * @w * @h * 4
61
+ end
62
+
63
+ def rows
64
+ @h
65
+ end
66
+
67
+ def columns
68
+ @w
69
+ end
70
+ end
71
+
72
+ # bring in user-defined extensions to TexPlay
73
+ direc = File.dirname(__FILE__)
74
+ dlext = Config::CONFIG['DLEXT']
75
+ begin
76
+ if RUBY_VERSION && RUBY_VERSION =~ /1.9/
77
+ require "#{direc}/1.9/texplay.#{dlext}"
78
+ else
79
+ require "#{direc}/1.8/texplay.#{dlext}"
80
+ end
81
+ rescue LoadError => e
82
+ require "#{direc}/texplay.#{dlext}"
83
+ end
84
+
85
+ require "#{direc}/texplay-contrib"
86
+
87
+ # monkey patching the Gosu::Image class to add image manipulation functionality
88
+ module Gosu
89
+ class Image
90
+
91
+ # bring in the TexPlay image manipulation methods
92
+ include TexPlay
93
+
94
+ class << self
95
+ alias_method :original_new, :new
96
+
97
+ def new(*args, &block)
98
+
99
+ # invoke old behaviour
100
+ obj = original_new(*args, &block)
101
+
102
+ # refresh the TexPlay image cache
103
+ if obj.width <= (TexPlay::TP_MAX_QUAD_SIZE - 2) &&
104
+ obj.height <= (TexPlay::TP_MAX_QUAD_SIZE - 2) && obj.quad_cached? then
105
+
106
+ obj.refresh_cache
107
+ end
108
+
109
+ # run custom setup
110
+ TexPlay::setup(obj)
111
+
112
+ obj.instance_variable_set(:@__window__, args.first)
113
+
114
+ # return the new image
115
+ obj
116
+ end
117
+ end
118
+
119
+ def __window__
120
+ @__window__
121
+ end
122
+ end
123
+ end
124
+
125
+ # a bug in ruby 1.8.6 rb_eval_string() means i must define this here (rather than in texplay.c)
126
+ class Proc
127
+ def __context__
128
+ eval('self', self.binding)
129
+ end
130
+ end
131
+
132
+
133
+
134
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: texplay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.7
5
+ platform: x86-mswin32
6
+ authors:
7
+ - John Mair (banisterfiend)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-16 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gosu
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.7.14
24
+ version:
25
+ description: TexPlay is a light-weight image manipulation framework for Ruby and Gosu
26
+ email: jrmair@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - Rakefile
35
+ - README.markdown
36
+ - CHANGELOG
37
+ - lib/texplay.rb
38
+ - lib/texplay-contrib.rb
39
+ - ext/texplay/extconf.rb
40
+ - ext/texplay/object2module.h
41
+ - ext/texplay/bindings.h
42
+ - ext/texplay/utils.h
43
+ - ext/texplay/actions.h
44
+ - ext/texplay/compat.h
45
+ - ext/texplay/cache.h
46
+ - ext/texplay/texplay.h
47
+ - ext/texplay/gen_eval.h
48
+ - ext/texplay/texplay.c
49
+ - ext/texplay/actions.c
50
+ - ext/texplay/object2module.c
51
+ - ext/texplay/utils.c
52
+ - ext/texplay/bindings.c
53
+ - ext/texplay/gen_eval.c
54
+ - ext/texplay/cache.c
55
+ - examples/example_dup.rb
56
+ - examples/example_turtle.rb
57
+ - examples/example_color_control.rb
58
+ - examples/example_effect.rb
59
+ - examples/common.rb
60
+ - examples/example_color_transform.rb
61
+ - examples/example_hash_arguments.rb
62
+ - examples/example_gen_eval.rb
63
+ - examples/example_polyline.rb
64
+ - examples/example_fill.rb
65
+ - examples/example_bezier.rb
66
+ - examples/example_simple.rb
67
+ - examples/example_fill_old.rb
68
+ - examples/example_blur.rb
69
+ - examples/example_each.rb
70
+ - examples/example_fluent.rb
71
+ - examples/example_sync.rb
72
+ - examples/example_splice.rb
73
+ - examples/example_alpha_blend.rb
74
+ - examples/example_melt.rb
75
+ - examples/example_lsystem.rb
76
+ - examples/example_scale.rb
77
+ - examples/media/sand1.png
78
+ - examples/media/rose.bmp
79
+ - examples/media/maria.png
80
+ - examples/media/sunset.png
81
+ - examples/media/texplay.png
82
+ - examples/media/gosu.png
83
+ - examples/media/logo.png
84
+ - examples/media/empty2.png
85
+ - lib/1.8/texplay.so
86
+ - lib/1.9/texplay.so
87
+ has_rdoc: false
88
+ homepage: http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.2.0
110
+ signing_key:
111
+ specification_version: 2
112
+ summary: TexPlay is a light-weight image manipulation framework for Ruby and Gosu
113
+ test_files: []
114
+