texplay 0.3.5 → 0.4
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 +222 -222
- data/README.markdown +43 -43
- data/Rakefile +3 -99
- 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 +1006 -1006
- data/ext/texplay/actions.h +60 -60
- data/ext/texplay/bindings.c +1125 -1186
- data/ext/texplay/bindings.h +46 -46
- data/ext/texplay/cache.c +118 -118
- data/ext/texplay/cache.h +24 -24
- data/ext/texplay/compat.h +27 -27
- data/ext/texplay/extconf.rb +28 -28
- data/ext/texplay/graphics_utils.c +1313 -1313
- data/ext/texplay/graphics_utils.h +22 -22
- data/ext/texplay/texplay.c +201 -216
- data/ext/texplay/texplay.h +153 -153
- data/ext/texplay/utils.c +891 -891
- data/ext/texplay/utils.h +153 -153
- data/lib/texplay-contrib.rb +147 -164
- data/lib/texplay.rb +341 -356
- data/lib/texplay/alone.rb +20 -20
- data/lib/texplay/c_function_docs.rb +178 -190
- 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 -141
- metadata +54 -42
- data/examples/example_gen_eval.rb +0 -32
- data/ext/texplay/gen_eval.c +0 -211
- data/ext/texplay/gen_eval.h +0 -20
- data/ext/texplay/object2module.c +0 -171
- data/ext/texplay/object2module.h +0 -11
data/Rakefile
CHANGED
|
@@ -1,99 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
require 'rake/clean'
|
|
6
|
-
require 'rake/gempackagetask'
|
|
7
|
-
require "#{direc}/lib/#{project_name}/version"
|
|
8
|
-
|
|
9
|
-
CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
|
|
10
|
-
CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o", "ext/**/*~",
|
|
11
|
-
"ext/**/*#*", "ext/**/*.obj", "ext/**/*.def", "ext/**/*.pdb")
|
|
12
|
-
|
|
13
|
-
def apply_spec_defaults(s)
|
|
14
|
-
s.name = "texplay"
|
|
15
|
-
s.summary = "TexPlay is a light-weight image manipulation framework for Ruby and Gosu"
|
|
16
|
-
s.version = TexPlay::VERSION
|
|
17
|
-
s.date = Time.now.strftime '%Y-%m-%d'
|
|
18
|
-
s.author = "John Mair (banisterfiend)"
|
|
19
|
-
s.email = 'jrmair@gmail.com'
|
|
20
|
-
s.description = s.summary
|
|
21
|
-
s.require_path = 'lib'
|
|
22
|
-
s.add_dependency("gosu",">=0.7.25")
|
|
23
|
-
s.add_development_dependency("bacon",">=1.1.0")
|
|
24
|
-
s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
|
|
25
|
-
s.has_rdoc = 'yard'
|
|
26
|
-
s.files = Dir["Rakefile", "README.markdown", "CHANGELOG",
|
|
27
|
-
"lib/**/*.rb", "ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c",
|
|
28
|
-
"examples/*.rb", "examples/media/*", "test/*.rb", "live/*rb", ".gemtest"]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
task :test do
|
|
32
|
-
sh "bacon -k #{direc}/test/texplay_spec.rb"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
[:mingw32, :mswin32].each do |v|
|
|
36
|
-
namespace v do
|
|
37
|
-
spec = Gem::Specification.new do |s|
|
|
38
|
-
apply_spec_defaults(s)
|
|
39
|
-
s.platform = "i386-#{v}"
|
|
40
|
-
s.files += FileList["lib/**/*.#{dlext}"].to_a
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
|
44
|
-
pkg.need_zip = false
|
|
45
|
-
pkg.need_tar = false
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
namespace :ruby do
|
|
51
|
-
spec = Gem::Specification.new do |s|
|
|
52
|
-
apply_spec_defaults(s)
|
|
53
|
-
s.platform = Gem::Platform::RUBY
|
|
54
|
-
s.extensions = ["ext/#{project_name}/extconf.rb"]
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
|
58
|
-
pkg.need_zip = false
|
|
59
|
-
pkg.need_tar = false
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
directories = ["#{direc}/lib/1.8", "#{direc}/lib/1.9"]
|
|
64
|
-
directories.each { |d| directory d }
|
|
65
|
-
|
|
66
|
-
desc "build the 1.8 and 1.9 binaries from source and copy to lib/"
|
|
67
|
-
task :compile => directories do
|
|
68
|
-
build_for = proc do |pik_ver, ver|
|
|
69
|
-
sh %{ \
|
|
70
|
-
c:\\devkit\\devkitvars.bat && \
|
|
71
|
-
pik #{pik_ver} && \
|
|
72
|
-
ruby extconf.rb && \
|
|
73
|
-
make clean && \
|
|
74
|
-
make && \
|
|
75
|
-
cp *.so #{direc}/lib/#{ver} \
|
|
76
|
-
}
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
chdir("#{direc}/ext/#{project_name}") do
|
|
80
|
-
build_for.call("187", "1.8")
|
|
81
|
-
build_for.call("192", "1.9")
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
desc "build all platform gems at once"
|
|
86
|
-
task :gems => [:clean, :rmgems, "mingw32:gem", "mswin32:gem", "ruby:gem"]
|
|
87
|
-
|
|
88
|
-
desc "remove all platform gems"
|
|
89
|
-
task :rmgems => ["ruby:clobber_package"]
|
|
90
|
-
|
|
91
|
-
desc "build and push latest gems"
|
|
92
|
-
task :pushgems => :gems do
|
|
93
|
-
chdir("#{direc}/pkg") do
|
|
94
|
-
Dir["*.gem"].each do |gemfile|
|
|
95
|
-
sh "gem push #{gemfile}"
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
1
|
+
require 'rake/extensiontask'
|
|
2
|
+
|
|
3
|
+
Rake::ExtensionTask.new('texplay')
|
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
|
+
|