texplay 0.4.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/CHANGELOG +222 -0
- data/README.markdown +48 -0
- data/Rakefile +16 -0
- data/examples/common.rb +18 -0
- data/examples/example_alpha_blend.rb +29 -0
- data/examples/example_bezier.rb +41 -0
- data/examples/example_blank.rb +37 -0
- data/examples/example_cache.rb +21 -0
- data/examples/example_color_control.rb +69 -0
- data/examples/example_color_transform.rb +62 -0
- data/examples/example_color_transform_circle.rb +34 -0
- data/examples/example_darken.rb +24 -0
- data/examples/example_dup.rb +73 -0
- data/examples/example_each.rb +39 -0
- data/examples/example_effect.rb +34 -0
- data/examples/example_fill.rb +43 -0
- data/examples/example_fill_old.rb +48 -0
- data/examples/example_fluent.rb +29 -0
- data/examples/example_font.rb +31 -0
- data/examples/example_hash_arguments.rb +46 -0
- data/examples/example_ippa.rb +23 -0
- data/examples/example_light.rb +75 -0
- data/examples/example_light_multiply.rb +18 -0
- data/examples/example_lsystem.rb +61 -0
- data/examples/example_melt.rb +25 -0
- data/examples/example_meyet.rb +62 -0
- data/examples/example_polyline.rb +42 -0
- data/examples/example_scale.rb +27 -0
- data/examples/example_select.rb +36 -0
- data/examples/example_select2.rb +25 -0
- data/examples/example_simple.rb +46 -0
- data/examples/example_splice.rb +26 -0
- data/examples/example_sync.rb +59 -0
- data/examples/example_tiles.rb +41 -0
- data/examples/example_trace.rb +22 -0
- data/examples/example_transparent.rb +28 -0
- data/examples/example_transparent2.rb +24 -0
- data/examples/example_transparent3.rb +20 -0
- data/examples/example_turtle.rb +39 -0
- data/examples/example_weird.rb +22 -0
- data/examples/example_window_render_to_image.rb +41 -0
- data/examples/example_window_to_blob.rb +35 -0
- data/examples/media/bird.png +0 -0
- data/examples/media/body.png +0 -0
- data/examples/media/empty2.png +0 -0
- data/examples/media/face.png +0 -0
- data/examples/media/gob.png +0 -0
- data/examples/media/gosu.png +0 -0
- data/examples/media/green.png +0 -0
- data/examples/media/logo.png +0 -0
- data/examples/media/maria.png +0 -0
- data/examples/media/object.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/examples/media/sand1.png +0 -0
- data/examples/media/sunset.png +0 -0
- data/examples/media/texplay.png +0 -0
- data/ext/texplay/actions.c +1006 -0
- data/ext/texplay/actions.h +60 -0
- data/ext/texplay/bindings.c +1125 -0
- data/ext/texplay/bindings.h +46 -0
- data/ext/texplay/cache.c +118 -0
- data/ext/texplay/cache.h +24 -0
- data/ext/texplay/compat.h +27 -0
- data/ext/texplay/extconf.rb +38 -0
- data/ext/texplay/graphics_utils.c +1313 -0
- data/ext/texplay/graphics_utils.h +22 -0
- data/ext/texplay/texplay.c +201 -0
- data/ext/texplay/texplay.h +153 -0
- data/ext/texplay/utils.c +891 -0
- data/ext/texplay/utils.h +153 -0
- data/ext/texplay/vendor/freeglut/include/GL/freeglut.h +22 -0
- data/ext/texplay/vendor/freeglut/include/GL/freeglut_ext.h +236 -0
- data/ext/texplay/vendor/freeglut/include/GL/freeglut_std.h +628 -0
- data/ext/texplay/vendor/freeglut/include/GL/glut.h +21 -0
- data/lib/texplay-contrib.rb +147 -0
- data/lib/texplay.rb +347 -0
- data/lib/texplay/1.8/texplay.so +0 -0
- data/lib/texplay/1.9/texplay.so +0 -0
- data/lib/texplay/alone.rb +20 -0
- data/lib/texplay/c_function_docs.rb +178 -0
- data/lib/texplay/live.rb +84 -0
- data/lib/texplay/version.rb +3 -0
- data/live/live.rb +85 -0
- data/test/image_spec.rb +45 -0
- data/test/texplay_spec.rb +144 -0
- metadata +179 -0
data/.gemtest
ADDED
File without changes
|
data/CHANGELOG
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
*22/2/11 version 0.3.5
|
2
|
+
* added :source, :dest, :source_with_alpha, :dest_with_alpha options to
|
3
|
+
:alpha_blend
|
4
|
+
* added live.rb (repl image editor)
|
5
|
+
* added alone.rb (run texplay image manip independent from gosu)
|
6
|
+
|
7
|
+
*1/11/10 version 0.3.0
|
8
|
+
* pushed gems
|
9
|
+
* tested
|
10
|
+
*1/10/10
|
11
|
+
version 0.2.983pre2
|
12
|
+
* added Window#to_texture(...) seems to be broken! releasing pre2 so
|
13
|
+
* others can test it :)
|
14
|
+
|
15
|
+
*27/9/10
|
16
|
+
version 0.2.983pre1
|
17
|
+
* added Window#to_blob(x,y,width,height), grab a screenshot region
|
18
|
+
|
19
|
+
*24/9/10
|
20
|
+
version 0.2.982pre1
|
21
|
+
* added :default drawing mode (equivalent to :mode => nil)
|
22
|
+
* changed Linux texture size to 512
|
23
|
+
|
24
|
+
16/8/10
|
25
|
+
version 0.2.981
|
26
|
+
* oops, added :caching => false to TexPlay#dup
|
27
|
+
* oops, put 'self' inside the capture block for TexPlay#clear
|
28
|
+
* got rid of tolerance member from rgba struct, as tolerance is now stored
|
29
|
+
separately
|
30
|
+
|
31
|
+
|
32
|
+
16/8/10
|
33
|
+
version 0.2.980
|
34
|
+
* added :caching option to TexPlay.set_options, and Gosu::Image.new. For
|
35
|
+
control over whether images are cached or not. (accepts true and
|
36
|
+
false values)
|
37
|
+
* TexPlay.create_image() no longer calls refresh_cache
|
38
|
+
* added new TexPlay#clear() method, just draws a filled rect over image.
|
39
|
+
|
40
|
+
14/8/10
|
41
|
+
version 0.2.975
|
42
|
+
* fixed :tolerance bug (was in special_cmp_color_with_tolerance, was checking color1.alpha <= tolerance instead of color2.alpha <= tolerance)
|
43
|
+
* modified TexPlay.create_image() so it only draws a colored, filled rect if a :color parameter is specified
|
44
|
+
|
45
|
+
14/8/10
|
46
|
+
version 0.2.970
|
47
|
+
* fixed :transparent bug (bug was in rb_convert_rb_color_to_rgba(), :transparent was being matched as
|
48
|
+
not_a_color)
|
49
|
+
* limited not_a_color() to match just color.red == -1 && color.green == -1, etc rather than color.red < 0
|
50
|
+
* Now we can use negative values to define other pseudo-colors (in similar vein to :transparent)
|
51
|
+
|
52
|
+
16/7/10
|
53
|
+
version 0.2.965
|
54
|
+
* fixed MAX_TEXTURE_SIZE at 1024 for linux (to avoid segfault)
|
55
|
+
|
56
|
+
4/7/10
|
57
|
+
version 0.2.960
|
58
|
+
* added :transparent pseudo-color
|
59
|
+
* added :tolerance option (applies to :trace and :source_select etc
|
60
|
+
family)
|
61
|
+
* fixed memleak in to_blob
|
62
|
+
|
63
|
+
10/6/10
|
64
|
+
version 0.2.950
|
65
|
+
* fixed bug in apply_drawing_mode, wasn't using blended_pixel as source_pixel
|
66
|
+
* hex literal colors now accepted, e.g 0xffff0000 (red)
|
67
|
+
|
68
|
+
9/6/10
|
69
|
+
version 0.2.940
|
70
|
+
* hopefully fixed :trace behaviour. Should now return nil for color when
|
71
|
+
pixel out of bounds.
|
72
|
+
|
73
|
+
9/6/10
|
74
|
+
version 0.2.930
|
75
|
+
* not_a_color now returns true when color channel < 0
|
76
|
+
|
77
|
+
8/6/10
|
78
|
+
version 0.2.920
|
79
|
+
* :trace now supports :color_mode => :gosu
|
80
|
+
|
81
|
+
7/6/10
|
82
|
+
version 0.2.910
|
83
|
+
* 1.8.7 incompatibility fixed
|
84
|
+
|
85
|
+
7/6/10
|
86
|
+
version 0.2.900
|
87
|
+
* added source_select, source_ignore, dest_select, dest_ignore
|
88
|
+
* :chroma_key now deprecated (by above functionality)
|
89
|
+
* using Gosu::MAX_TEXTURE_SIZE, hopefully fixes crashes on some linux
|
90
|
+
distros
|
91
|
+
* Gosu::Color objects now accepted (and optionally returned by get_pixel)
|
92
|
+
* Monkey patched Gosu::Image.from_text() for auto-caching
|
93
|
+
* bitwise drawing modes no longer affect alpha
|
94
|
+
* rows and columns methods added to Gosu::Image, allowed Gosu::Image to be
|
95
|
+
reopened by Gosu::Image.new (works with Gosu::Image#to_blob)
|
96
|
+
|
97
|
+
|
98
|
+
23/03/10
|
99
|
+
version 0.2.800
|
100
|
+
* added 28 drawing modes (using :mode option)
|
101
|
+
* added linear interpolation (:lerp)
|
102
|
+
* added 'trace' option to line for efficient pixel-based collision detection
|
103
|
+
|
104
|
+
12/03/10
|
105
|
+
version 0.2.721
|
106
|
+
* fixed bug in alpha_blend (now blends alpha channels too)
|
107
|
+
|
108
|
+
6/12/09
|
109
|
+
version 0.2.710
|
110
|
+
* fixed bug in line drawing code (wasn't drawing final pixel)
|
111
|
+
* fixed bug in filled rect code (wasn't drawing final row)
|
112
|
+
* fixed bug in flood fill (wasn't drawing on first column)
|
113
|
+
* added glDisable(GL_TEXTURE_2D) calls to cache.c, and removed 'restore previous texture binding' (i doubt there is any previous binding to restore)
|
114
|
+
* using version.rb to help manage versions
|
115
|
+
|
116
|
+
23/11/09
|
117
|
+
* fixed bug in texplay.rb. Replaced TexPlay::TP_MAX_QUAD_SIZE - 2 with
|
118
|
+
just TexPlay::TP_MAX_QUAD_SIZE (the -2 is now built into the constant)
|
119
|
+
|
120
|
+
16/10/09
|
121
|
+
version 0.2.700
|
122
|
+
* removed memory leak from Gosu::Image#to_blob, now writing directly to RSTRING_PTR
|
123
|
+
|
124
|
+
12/10/09
|
125
|
+
version 0.2.666
|
126
|
+
* added Gosu::Image#to_blob
|
127
|
+
* to_blob functionality enables Gosu::Images to work with DevIL library
|
128
|
+
|
129
|
+
6/10/09
|
130
|
+
version 0.2.5
|
131
|
+
* fixed quad_draw flicker bug
|
132
|
+
* added splice_and_scale (to texplay-contrib.rb)
|
133
|
+
* now using rake-compiler to run build process
|
134
|
+
|
135
|
+
15/9/09
|
136
|
+
version 0.2.4
|
137
|
+
* added lsystem
|
138
|
+
* made lsystem both 1.9.1 and 1.8.6 compatible
|
139
|
+
|
140
|
+
11/9/09
|
141
|
+
version 0.2.3
|
142
|
+
* added Ruby 1.8.7 compatibility by modifying extconf.rb to define RUBY_19 macro
|
143
|
+
* and modified compat.h to get rid of feature test (fails on 1.8.7)
|
144
|
+
|
145
|
+
8/9/09
|
146
|
+
version 0.2.2
|
147
|
+
* fixed color_control bug, action_struct->color was being overwritten (now using a temp).
|
148
|
+
* fixed faulty error msg where max tex size was being displayed as 1024 but is actually 1022
|
149
|
+
* added :start_angle parameter to ngon action
|
150
|
+
* fixed example screen height from 769 to 768
|
151
|
+
* arity of -1 and 0 now supported for color_control procs
|
152
|
+
* fixed parameter checks for circle and ngon
|
153
|
+
* updated documentation to reflect changes, and added details on caching
|
154
|
+
|
155
|
+
2/9/09
|
156
|
+
version 0.2.1
|
157
|
+
* releasing a gem for TexPlay
|
158
|
+
* bumped version number so can add add gosu 0.7.14 dependency to github gem
|
159
|
+
* hopefully gem works on both github and rubyforge
|
160
|
+
31/8/09
|
161
|
+
version 0.2.0
|
162
|
+
* added each iterator
|
163
|
+
* added alternative to proc for :color_control proc (allowing static linear transforms to pixels)
|
164
|
+
* no longer segfaulting on windows (no idea why not)
|
165
|
+
* rewrote EmptyImageStub in ruby, using philomory's code. now alot faster.
|
166
|
+
* implemented 'shadow' in terms of static :color_control pixel transform
|
167
|
+
* added more example code demonstrating each iterator (example_each.rb) and new color_control behaviour
|
168
|
+
i.e example_color_transform.rb
|
169
|
+
* should be relatively stable now!
|
170
|
+
|
171
|
+
28/8/09
|
172
|
+
version 0.1.9.1 (still BETA)
|
173
|
+
* experimental features: Gosu::Image#dup and Gosu::Image#clone
|
174
|
+
* also TexPlay::create_blank_image(window, width, height)
|
175
|
+
* I noticed these features SEG FAULT on my setup in windows, so be warned
|
176
|
+
* This is a BETA release
|
177
|
+
|
178
|
+
14/8/09
|
179
|
+
version 0.1.9.0 (BETA)
|
180
|
+
* major rewrite. TP now supports beziers, polylines, polygons, and more
|
181
|
+
* also supports alpha_blending (though still tempermental)
|
182
|
+
* This is a BETA release
|
183
|
+
|
184
|
+
1/7/09
|
185
|
+
version 0.1.6.2
|
186
|
+
* fixed another subtle bug in constrain_local_boundaries(). Function was
|
187
|
+
unable to deal with drawing actions that were 100% outside the image
|
188
|
+
boundaries.
|
189
|
+
|
190
|
+
28/6/09
|
191
|
+
version 0.1.6
|
192
|
+
* gen_eval now working as a replacement for instance_eval in the #paint block. Allows for more user-friendly interface.
|
193
|
+
* #paint can now be called without a block; if invoked this way it executes any commands in the action queue, e.g
|
194
|
+
@img.circle 20, 20, 40
|
195
|
+
@img.pixel 30, 30
|
196
|
+
@img.paint
|
197
|
+
* above will function as if: @img.paint { circle 20, 20, 40; pixel 30, 30 }
|
198
|
+
* collected 1.8.6/1.9.1 compatibility into compat.h
|
199
|
+
|
200
|
+
16/6/09
|
201
|
+
version 0.1.4.6
|
202
|
+
* allowed arity of 0 (as well as -1) for ruby 1.9 compatibility
|
203
|
+
|
204
|
+
13/6/09
|
205
|
+
version 0.1.4.5
|
206
|
+
* major bugfix with TexPlay#splice method (segfaut). Also added new color format parameter: color [1, 1, 0, 1] (e.g purple with full alpha).
|
207
|
+
Also fixed subtle edge-case bug in constrain_local_boundaries().
|
208
|
+
|
209
|
+
9/6/09
|
210
|
+
version 0.1.4
|
211
|
+
* improved error checking. should work better with later gosu releases
|
212
|
+
|
213
|
+
20/2/09
|
214
|
+
version 0.1.1
|
215
|
+
* rerelease of this version fixing the oversized image bug for refresh_cache (i.e images over 500 x 500
|
216
|
+
|
217
|
+
version 0.1.1
|
218
|
+
* oops, bug in leftshift/rightshift functions, fixed!
|
219
|
+
|
220
|
+
version 0.1.0
|
221
|
+
* release!
|
222
|
+
|
data/README.markdown
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
![Alt text](https://dl.getdropbox.com/u/239375/texplay.png)
|
2
|
+
|
3
|
+
*an image manipulation tool for ruby and gosu*
|
4
|
+
|
5
|
+
INSTRUCTIONS
|
6
|
+
============
|
7
|
+
|
8
|
+
**TexPlay version 0.4.2**
|
9
|
+
|
10
|
+
[Read The Documentation](http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/)
|
11
|
+
|
12
|
+
Gem installation:
|
13
|
+
|
14
|
+
+ sudo gem install texplay
|
15
|
+
|
16
|
+
How to build the gems? (maintainers only)
|
17
|
+
|
18
|
+
+ Install rake-compiler (http://github.com/luislavena/rake-compiler)
|
19
|
+
+ Install 1.9.1 and 1.8.6 mingw ruby versions (instructions above)
|
20
|
+
+ Type (on Linux/OSX to build fat Win32 binary): `rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.1`
|
21
|
+
|
22
|
+
+ Upload new gems to rubyforge and gemcutter.
|
23
|
+
|
24
|
+
How to build from source?
|
25
|
+
+ rake compile
|
26
|
+
|
27
|
+
OR
|
28
|
+
|
29
|
+
+ rake19 compile (assuming this is the name of your 1.9.1 version of rake)
|
30
|
+
|
31
|
+
**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!
|
32
|
+
|
33
|
+
If all goes well, run the example programs:
|
34
|
+
|
35
|
+
+ cd examples
|
36
|
+
+ ruby example_melt.rb
|
37
|
+
+ ruby example_simple.rb
|
38
|
+
+ ..etc
|
39
|
+
|
40
|
+
+ like any gosu application, gosu.so must be in the current directory (or the gosu gem installed) when running the examples.
|
41
|
+
|
42
|
+
Third party
|
43
|
+
-----------
|
44
|
+
|
45
|
+
+ (Windows only) [Freeglut](http://freeglut.sourceforge.net/) [Freeglut Copyright]
|
46
|
+
|
47
|
+
---
|
48
|
+
Enjoy!
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'devkit' # Only on Windows.
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'rake/extensiontask'
|
7
|
+
|
8
|
+
spec = Gem::Specification.load Dir['*.gemspec'].first
|
9
|
+
|
10
|
+
Gem::PackageTask.new spec do
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::ExtensionTask.new 'texplay', spec do |ext|
|
14
|
+
RUBY_VERSION =~ /(\d+.\d+)/
|
15
|
+
ext.lib_dir = "lib/texplay/#{$1}"
|
16
|
+
end
|
data/examples/common.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
EXAMPLES_DIR = File.dirname(File.expand_path(__FILE__))
|
2
|
+
|
3
|
+
# Ensure that the texplay loaded is the one in this repository, not any gem installed.
|
4
|
+
$LOAD_PATH.unshift File.expand_path(File.join(EXAMPLES_DIR, '..', 'lib'))
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError => ex
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'gosu'
|
12
|
+
require 'texplay'
|
13
|
+
|
14
|
+
module Common
|
15
|
+
MEDIA = File.join(EXAMPLES_DIR, 'media')
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
|
2
|
+
require 'common'
|
3
|
+
|
4
|
+
class W < Gosu::Window
|
5
|
+
def initialize
|
6
|
+
super(500, 500, false, 20)
|
7
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
8
|
+
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
9
|
+
|
10
|
+
# put a border on the image
|
11
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
12
|
+
|
13
|
+
@img.rect 1, 1, @img.width - 2, @img.height - 2, :fill => true, :texture => @tp
|
14
|
+
|
15
|
+
# NOTE: the current implementation of alpha blending is a bit tempermental, i need to think it
|
16
|
+
# through a bit more...
|
17
|
+
@img.rect 100, 100, 300, 300, :color => [1, 1, 1, 0.8], :alpha_blend => true, :fill => true
|
18
|
+
end
|
19
|
+
|
20
|
+
def draw
|
21
|
+
@img.draw 100, 50,1
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
w = W.new
|
28
|
+
w.show
|
29
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
|
2
|
+
require 'common'
|
3
|
+
|
4
|
+
|
5
|
+
class W < Gosu::Window
|
6
|
+
def initialize
|
7
|
+
super(500, 500, false, 20)
|
8
|
+
@img = TexPlay.create_image(self, 500, 500)
|
9
|
+
|
10
|
+
# put a border on the image
|
11
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
12
|
+
|
13
|
+
points = []
|
14
|
+
|
15
|
+
# NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
|
16
|
+
# NOTE: current maximum points for a bezier is 13
|
17
|
+
(0..@img.width + 100).step(40) { |x|
|
18
|
+
p = TexPlay::TPPoint.new
|
19
|
+
p.x = x
|
20
|
+
p.y = @img.height * rand
|
21
|
+
|
22
|
+
points << p
|
23
|
+
}
|
24
|
+
|
25
|
+
# making the bezier
|
26
|
+
@img.bezier points, :color => :red
|
27
|
+
|
28
|
+
# NOTE: can 'close' a bezier curve too (as with polylines)
|
29
|
+
end
|
30
|
+
|
31
|
+
def draw
|
32
|
+
|
33
|
+
@img.draw 100, 50,1
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
w = W.new
|
40
|
+
w.show
|
41
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
|
2
|
+
require 'common'
|
3
|
+
|
4
|
+
|
5
|
+
class W < Gosu::Window
|
6
|
+
def initialize
|
7
|
+
super(500, 500, false, 20)
|
8
|
+
@img = TexPlay.create_image(self, 50, 50, :color => Gosu::Color::BLUE)
|
9
|
+
@img2 = TexPlay.create_image(self, 50, 50, :color => Gosu::Color::RED)
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
@img.draw 0, 0,1
|
19
|
+
@img2.draw 100, 100,1
|
20
|
+
if button_down?(Gosu::KbEscape)
|
21
|
+
# self.flush
|
22
|
+
@blob = self.to_blob(0,self.height - 70, 50, 50)
|
23
|
+
if @blob
|
24
|
+
@img3 = TexPlay.from_blob(self, @blob,50, 50 )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@img3.draw rand(300), rand(300), 1 if @img3
|
29
|
+
500000.times {}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
w = W.new
|
36
|
+
w.show
|
37
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
|
2
|
+
require 'common'
|
3
|
+
|
4
|
+
class W < Gosu::Window
|
5
|
+
def initialize
|
6
|
+
super(400, 300, false, 20)
|
7
|
+
TexPlay.set_options :caching => true
|
8
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/object.png", :caching => false)
|
9
|
+
|
10
|
+
@img.clear :color => :red, :dest_select => :transparent, :tolerance => 0.9
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw
|
14
|
+
@img.draw 100, 100, 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
w = W.new
|
21
|
+
w.show
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'common'
|
3
|
+
require 'texplay'
|
4
|
+
|
5
|
+
class W < Gosu::Window
|
6
|
+
def initialize
|
7
|
+
super(500, 500, false, 20)
|
8
|
+
@img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
|
9
|
+
@tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
|
10
|
+
@gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
|
11
|
+
|
12
|
+
# put a border on the image
|
13
|
+
@img.rect 0,0, @img.width - 1, @img.height - 1
|
14
|
+
|
15
|
+
# When using color_control the pixel the draw action is currently manipulating is yielded
|
16
|
+
# to the proc. This gives you pixel-level control over the drawing.
|
17
|
+
# (NOTE: the return value of the proc is used as the pixel color, so it should be a 4 element array or
|
18
|
+
# a valid color symbol)
|
19
|
+
|
20
|
+
# color_control accepts procs of 4 types:
|
21
|
+
# arity of 0: nothing is yielded and color is set by return value of block
|
22
|
+
# arity of 1: just the destination pixel color is yielded
|
23
|
+
# arity of 2: both the destination and the source pixel colors are yielded (in that order)
|
24
|
+
# arity of 3: the destination pixel color is yielded along with the x and y coords of the current pixel
|
25
|
+
# arity of 4: both the destination and the source pixel colours are yielded as well as the x and y vals
|
26
|
+
|
27
|
+
# just drawing an area to fill
|
28
|
+
@img.polyline [30, 30, 100, 100, 200, 76, 300, 9, 50, 200], :color => :random, :closed => true
|
29
|
+
|
30
|
+
# below we are 'faking' a texture fill using color_control
|
31
|
+
@img.fill 42, 70, :color_control => proc { |c, x, y|
|
32
|
+
@tp.get_pixel(x % @tp.width, y % @tp.height)
|
33
|
+
}
|
34
|
+
|
35
|
+
# merging two images together
|
36
|
+
@img.rect 100, 200, 400, 300, :fill => true, :texture => @gosu,
|
37
|
+
:color_control => proc { |c1, c2, x, y|
|
38
|
+
c1 = @tp.get_pixel(x % @tp.width, y % @tp.height)
|
39
|
+
c1[0] = (c1[0] + c2[0]) / 2
|
40
|
+
c1[1] = (c1[1] + c2[1]) / 2
|
41
|
+
c1[2] = (c1[2] + c2[2]) / 2
|
42
|
+
c1[3] = 1
|
43
|
+
c1
|
44
|
+
}
|
45
|
+
|
46
|
+
# we can even use color_control just for the use of the (x, y) values.
|
47
|
+
# here we simply use the x, y values to make our own circle with a rough edge
|
48
|
+
@img.circle 200,400, 70,
|
49
|
+
:color_control => proc { |c,x,y|
|
50
|
+
@img.pixel(x + (rand(4) - 2), y + (rand(4) - 2))
|
51
|
+
:none # this ensures that the 'actual' circle isn't drawn, instead its coordinates are
|
52
|
+
# simply utilized to draw a ragged edge of another circle (using @img.pixel)
|
53
|
+
}
|
54
|
+
|
55
|
+
# this just fills a rect with random colours
|
56
|
+
@img.rect 400, 400, 470, 470, :fill => true, :color_control => proc { :rand }
|
57
|
+
end
|
58
|
+
|
59
|
+
def draw
|
60
|
+
|
61
|
+
@img.draw 0, 0,1
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
w = W.new
|
68
|
+
w.show
|
69
|
+
|