texplay 0.4.3 → 0.4.4.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +225 -222
- data/README.markdown +48 -48
- data/Rakefile +16 -16
- data/examples/common.rb +18 -18
- data/examples/example_alpha_blend.rb +29 -29
- data/examples/example_bezier.rb +41 -41
- data/examples/example_blank.rb +37 -37
- data/examples/example_cache.rb +21 -21
- data/examples/example_color_control.rb +69 -69
- data/examples/example_color_transform.rb +62 -62
- data/examples/example_color_transform_circle.rb +34 -34
- data/examples/example_darken.rb +24 -24
- data/examples/example_dup.rb +73 -73
- data/examples/example_each.rb +39 -39
- data/examples/example_effect.rb +34 -34
- data/examples/example_fill.rb +43 -43
- data/examples/example_fill_old.rb +48 -48
- data/examples/example_fluent.rb +29 -29
- data/examples/example_font.rb +31 -31
- data/examples/example_hash_arguments.rb +46 -46
- data/examples/example_ippa.rb +23 -23
- data/examples/example_light.rb +75 -75
- data/examples/example_light_multiply.rb +18 -18
- data/examples/example_lsystem.rb +61 -61
- data/examples/example_melt.rb +25 -25
- data/examples/example_meyet.rb +62 -62
- data/examples/example_polyline.rb +42 -42
- data/examples/example_scale.rb +27 -27
- data/examples/example_select.rb +36 -36
- data/examples/example_select2.rb +25 -25
- data/examples/example_simple.rb +46 -46
- data/examples/example_splice.rb +26 -26
- data/examples/example_sync.rb +59 -59
- data/examples/example_tiles.rb +41 -41
- data/examples/example_trace.rb +22 -22
- data/examples/example_transparent.rb +28 -28
- data/examples/example_transparent2.rb +24 -24
- data/examples/example_transparent3.rb +20 -20
- data/examples/example_turtle.rb +39 -39
- data/examples/example_weird.rb +22 -22
- data/examples/example_window_render_to_image.rb +41 -41
- data/examples/example_window_to_blob.rb +35 -35
- data/examples/media/maria.png +0 -0
- data/examples/media/rose.bmp +0 -0
- data/ext/texplay/actions.c +1011 -1006
- data/ext/texplay/actions.h +60 -60
- data/ext/texplay/bindings.c +1130 -1125
- data/ext/texplay/bindings.h +46 -46
- data/ext/texplay/cache.c +123 -118
- data/ext/texplay/cache.h +24 -24
- data/ext/texplay/compat.h +21 -27
- data/ext/texplay/extconf.rb +38 -38
- data/ext/texplay/graphics_utils.c +1318 -1313
- data/ext/texplay/graphics_utils.h +22 -22
- data/ext/texplay/texplay.c +206 -201
- data/ext/texplay/texplay.h +153 -153
- data/ext/texplay/utils.c +896 -891
- data/ext/texplay/utils.h +153 -153
- data/lib/texplay-contrib.rb +147 -147
- data/lib/texplay.rb +347 -347
- data/lib/texplay/alone.rb +20 -20
- data/lib/texplay/c_function_docs.rb +178 -178
- data/lib/texplay/live.rb +84 -84
- data/lib/texplay/version.rb +3 -3
- data/live/live.rb +85 -85
- data/test/image_spec.rb +45 -45
- data/test/texplay_spec.rb +144 -144
- metadata +42 -52
- data/lib/texplay/1.8/texplay.so +0 -0
- data/lib/texplay/1.9/texplay.so +0 -0
data/README.markdown
CHANGED
@@ -1,48 +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.
|
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!
|
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.3**
|
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
CHANGED
@@ -1,16 +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
|
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
CHANGED
@@ -1,18 +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
|
-
|
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
|
+
|
@@ -1,29 +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
|
-
|
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
|
+
|
data/examples/example_bezier.rb
CHANGED
@@ -1,41 +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
|
-
|
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
|
+
|
data/examples/example_blank.rb
CHANGED
@@ -1,37 +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
|
-
|
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
|
+
|
data/examples/example_cache.rb
CHANGED
@@ -1,21 +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
|
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
|
@@ -1,69 +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
|
-
|
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
|
+
|