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
data/CHANGELOG ADDED
@@ -0,0 +1,103 @@
1
+ 16/10/09
2
+ version 0.2.7
3
+ * removed memory leak from Gosu::Image#to_blob, now writing directly to RSTRING_PTR
4
+
5
+ 12/10/09
6
+ version 0.2.666
7
+ * added Gosu::Image#to_blob
8
+ * to_blob functionality enables Gosu::Images to work with DevIL library
9
+
10
+ 6/10/09
11
+ version 0.2.5
12
+ * fixed quad_draw flicker bug
13
+ * added splice_and_scale (to texplay-contrib.rb)
14
+ * now using rake-compiler to run build process
15
+
16
+ 15/9/09
17
+ version 0.2.4
18
+ * added lsystem
19
+ * made lsystem both 1.9.1 and 1.8.6 compatible
20
+
21
+ 11/9/09
22
+ version 0.2.3
23
+ * added Ruby 1.8.7 compatibility by modifying extconf.rb to define RUBY_19 macro
24
+ * and modified compat.h to get rid of feature test (fails on 1.8.7)
25
+
26
+ 8/9/09
27
+ version 0.2.2
28
+ * fixed color_control bug, action_struct->color was being overwritten (now using a temp).
29
+ * fixed faulty error msg where max tex size was being displayed as 1024 but is actually 1022
30
+ * added :start_angle parameter to ngon action
31
+ * fixed example screen height from 769 to 768
32
+ * arity of -1 and 0 now supported for color_control procs
33
+ * fixed parameter checks for circle and ngon
34
+ * updated documentation to reflect changes, and added details on caching
35
+
36
+ 2/9/09
37
+ version 0.2.1
38
+ * releasing a gem for TexPlay
39
+ * bumped version number so can add add gosu 0.7.14 dependency to github gem
40
+ * hopefully gem works on both github and rubyforge
41
+ 31/8/09
42
+ version 0.2.0
43
+ * added each iterator
44
+ * added alternative to proc for :color_control proc (allowing static linear transforms to pixels)
45
+ * no longer segfaulting on windows (no idea why not)
46
+ * rewrote EmptyImageStub in ruby, using philomory's code. now alot faster.
47
+ * implemented 'shadow' in terms of static :color_control pixel transform
48
+ * added more example code demonstrating each iterator (example_each.rb) and new color_control behaviour
49
+ i.e example_color_transform.rb
50
+ * should be relatively stable now!
51
+
52
+ 28/8/09
53
+ version 0.1.9.1 (still BETA)
54
+ * experimental features: Gosu::Image#dup and Gosu::Image#clone
55
+ * also TexPlay::create_blank_image(window, width, height)
56
+ * I noticed these features SEG FAULT on my setup in windows, so be warned
57
+ * This is a BETA release
58
+
59
+ 14/8/09
60
+ version 0.1.9.0 (BETA)
61
+ * major rewrite. TP now supports beziers, polylines, polygons, and more
62
+ * also supports alpha_blending (though still tempermental)
63
+ * This is a BETA release
64
+
65
+ 1/7/09
66
+ version 0.1.6.2
67
+ * fixed another subtle bug in constrain_local_boundaries(). Function was
68
+ unable to deal with drawing actions that were 100% outside the image
69
+ boundaries.
70
+
71
+ 28/6/09
72
+ version 0.1.6
73
+ * gen_eval now working as a replacement for instance_eval in the #paint block. Allows for more user-friendly interface.
74
+ * #paint can now be called without a block; if invoked this way it executes any commands in the action queue, e.g
75
+ @img.circle 20, 20, 40
76
+ @img.pixel 30, 30
77
+ @img.paint
78
+ * above will function as if: @img.paint { circle 20, 20, 40; pixel 30, 30 }
79
+ * collected 1.8.6/1.9.1 compatibility into compat.h
80
+
81
+ 16/6/09
82
+ version 0.1.4.6
83
+ * allowed arity of 0 (as well as -1) for ruby 1.9 compatibility
84
+
85
+ 13/6/09
86
+ version 0.1.4.5
87
+ * major bugfix with TexPlay#splice method (segfaut). Also added new color format parameter: color [1, 1, 0, 1] (e.g purple with full alpha).
88
+ Also fixed subtle edge-case bug in constrain_local_boundaries().
89
+
90
+ 9/6/09
91
+ version 0.1.4
92
+ * improved error checking. should work better with later gosu releases
93
+
94
+ 20/2/09
95
+ version 0.1.1
96
+ * rerelease of this version fixing the oversized image bug for refresh_cache (i.e images over 500 x 500
97
+
98
+ version 0.1.1
99
+ * oops, bug in leftshift/rightshift functions, fixed!
100
+
101
+ version 0.1.0
102
+ * release!
103
+
data/README.markdown ADDED
@@ -0,0 +1,41 @@
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.2.7**
9
+
10
+ Gem installation:
11
+
12
+ + sudo gem install texplay
13
+
14
+ How to build the gems? (maintainers only)
15
+
16
+ + Install rake-compiler (http://github.com/luislavena/rake-compiler)
17
+ + Install 1.9.1 and 1.8.6 mingw ruby versions (instructions above)
18
+ + Type: rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.1
19
+ + Upload new gems to rubyforge and gemcutter.
20
+
21
+ How to build from source?
22
+ + rake compile
23
+
24
+ OR
25
+
26
+ + rake19 compile (assuming this is the name of your 1.9.1 version of rake)
27
+
28
+ **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!
29
+
30
+ If all goes well, run the example programs:
31
+
32
+ + cd examples
33
+ + ruby example_melt.rb
34
+ + ruby example_simple.rb
35
+ + ..etc
36
+
37
+ + like any gosu application, gosu.so must be in the current directory (or the gosu gem installed) when running the examples.
38
+
39
+
40
+ ---
41
+ Enjoy!
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require 'rake/clean'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/extensiontask'
4
+
5
+ TEXPLAY_VERSION = "0.2.7"
6
+
7
+ $dlext = Config::CONFIG['DLEXT']
8
+
9
+ CLEAN.include("ext/**/*.#{$dlext}", "ext/**/*.log", "ext/**/*.o", "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "ext/**/*.def", "ext/**/*.pdb")
10
+ CLOBBER.include("**/*.#{$dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
11
+
12
+ specification = Gem::Specification.new do |s|
13
+ s.name = "texplay"
14
+ s.summary = "TexPlay is a light-weight image manipulation framework for Ruby and Gosu"
15
+ s.version = TEXPLAY_VERSION
16
+ s.date = Time.now.strftime '%Y-%m-%d'
17
+ s.author = "John Mair (banisterfiend)"
18
+ s.email = 'jrmair@gmail.com'
19
+ s.description = s.summary
20
+ s.require_path = 'lib'
21
+ s.add_dependency("gosu",">=0.7.14")
22
+ s.platform = Gem::Platform::RUBY
23
+ s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
24
+ s.has_rdoc = false
25
+
26
+ s.extensions = ["ext/texplay/extconf.rb"]
27
+ s.files = ["Rakefile", "README.markdown", "CHANGELOG",
28
+ "lib/texplay.rb", "lib/texplay-contrib.rb"] +
29
+ FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "examples/*.rb",
30
+ "examples/media/*"].to_a
31
+ end
32
+
33
+ Rake::GemPackageTask.new(specification) do |package|
34
+ package.need_zip = false
35
+ package.need_tar = false
36
+ end
37
+
38
+ Rake::ExtensionTask.new('texplay', specification) do |ext|
39
+ ext.config_script = 'extconf.rb'
40
+ ext.cross_compile = true
41
+ ext.cross_platform = 'i386-mswin32'
42
+ end
43
+
44
+ # SELENE = '/home/john/ruby/projects/selene'
45
+ # desc "update selene's version of texplay"
46
+ # task :selene => ["#{SELENE}/lib/texplay.rb", "#{SELENE}/lib/texplay-contrib.rb",
47
+ # "#{SELENE}/lib/ctexplay.so"] do
48
+ # puts "...done!"
49
+ # end
50
+
51
+ # file "#{SELENE}/lib/texplay.rb" => "texplay.rb" do |t|
52
+ # cp t.prerequisites.first, t.name, :verbose => true
53
+ # end
54
+
55
+ # file "#{SELENE}/lib/texplay-contrib.rb" => "texplay-contrib.rb" do |t|
56
+ # cp t.prerequisites.first, t.name, :verbose => true
57
+ # end
58
+
59
+ # file "#{SELENE}/lib/ctexplay.#{$dlext}" => "ctexplay.#{$dlext}" do |t|
60
+ # cp t.prerequisites.first, t.name, :verbose => true
61
+ # end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.push(File.dirname(__FILE__) + '/../lib/')
2
+
3
+ require 'rubygems'
4
+ require 'texplay'
5
+
6
+ module Common
7
+ MEDIA = File.dirname(__FILE__) + '/media'
8
+ end
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(1024, 768, false, 20)
9
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
+ @tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
11
+
12
+ # put a border on the image
13
+ @img.rect 0,0, @img.width - 1, @img.height - 1
14
+
15
+ @img.rect 1, 1, @img.width - 2, @img.height - 2, :fill => true, :texture => @tp
16
+
17
+ # NOTE: the current implementation of alpha blending is a bit tempermental, i need to think it
18
+ # through a bit more...
19
+ @img.rect 100, 100, 300, 300, :color => [1, 1, 1, 0.8], :alpha_blend => true, :fill => true
20
+ end
21
+
22
+ def draw
23
+ @img.draw 100, 50,1
24
+ end
25
+
26
+ end
27
+
28
+
29
+ w = W.new
30
+ w.show
31
+
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(1024, 768, false, 20)
9
+ @img = TexPlay::create_blank_image(self, 500, 500)
10
+
11
+ # put a border on the image
12
+ @img.rect 0,0, @img.width - 1, @img.height - 1
13
+
14
+ points = []
15
+
16
+ # NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
17
+ # NOTE: current maximum points for a bezier is 13
18
+ (0..@img.width + 100).step(40) { |x|
19
+ p = TexPlay::TPPoint.new
20
+ p.x = x
21
+ p.y = @img.height * rand
22
+
23
+ points << p
24
+ }
25
+
26
+ # making the bezier
27
+ @img.bezier points, :color => :red
28
+
29
+ # NOTE: can 'close' a bezier curve too (as with polylines)
30
+ end
31
+
32
+ def draw
33
+
34
+ @img.draw 100, 50,1
35
+ end
36
+
37
+ end
38
+
39
+
40
+ w = W.new
41
+ w.show
42
+
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+
7
+ class W < Gosu::Window
8
+ def initialize
9
+ super(1024, 768, false, 20)
10
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/logo.png")
11
+ #@img.rect 0,0, @img.width - 1, @img.height - 1
12
+ @img2 = TexPlay::create_blank_image(self, @img.width, @img.height)
13
+ @img2.rect 0,0, 1000, 100, :fill => true
14
+
15
+ TexPlay::create_macro(:blur) do |*options|
16
+ options = options.first ? options.first : {}
17
+
18
+ radius = options[:blur_radius] || 1
19
+
20
+ self.each(options) { |c,x,y|
21
+ total = [0, 0, 0, 0]
22
+ for ky in (-radius..radius)
23
+ for kx in (-radius..radius)
24
+ v = get_pixel(x + kx, y + ky);
25
+ if v
26
+ total[0] += v[0]
27
+ total[1] += v[1]
28
+ total[2] += v[2]
29
+ total[3] += v[3]
30
+ end
31
+ end
32
+ end
33
+
34
+ c[0] = total[0] / (radius * 2 + 1) ** 2
35
+ c[1] = total[1] / (radius * 2 + 1) ** 2
36
+ c[2] = total[2] / (radius * 2 + 1) ** 2
37
+ c[3] = total[3] / (radius * 2 + 1) ** 2
38
+ }
39
+
40
+ self
41
+ end
42
+
43
+ @img.blur :blur_radius => 4, :region => [0, 0, @img.width/2, @img.height]
44
+ end
45
+
46
+ def draw
47
+ x = @img.width * rand
48
+ y = @img.height * rand
49
+
50
+ @img2.draw 100, 50,1
51
+ @img.draw 100, 50,1
52
+ end
53
+
54
+ end
55
+
56
+
57
+ w = W.new
58
+ w.show
59
+
@@ -0,0 +1,69 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+ class W < Gosu::Window
6
+ def initialize
7
+ super(1024, 768, 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 100, 50,1
62
+ end
63
+
64
+ end
65
+
66
+
67
+ w = W.new
68
+ w.show
69
+
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+
7
+ class W < Gosu::Window
8
+ def initialize
9
+ super(1024, 768, false, 20)
10
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
11
+ end
12
+
13
+ def draw
14
+ x = (@img.width - 100/2) * rand
15
+ y = (@img.height - 100/2) * rand
16
+
17
+ @img.rect x, y, x + 50, y + 50, :fill => true,
18
+ :color_control => { :mult => [0.9 , 0.3, 0.3, 1] }
19
+
20
+
21
+ @img.draw 100, 50,1
22
+ end
23
+
24
+ end
25
+
26
+
27
+ w = W.new
28
+ w.show
29
+
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+
7
+ class W < Gosu::Window
8
+ def initialize
9
+ super(1024, 768, false, 20)
10
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
11
+ @img.rect 0,0, @img.width - 1, @img.height - 1
12
+
13
+ # testing Gosu::Image#dup
14
+ # adding an ivar
15
+ @img.instance_variable_set(:@horse, :love)
16
+
17
+ # adding a method on the singleton
18
+ class << @img
19
+ def little
20
+ :little
21
+ end
22
+ end
23
+
24
+ # clone the image.
25
+ # NB #clone also copies singleton
26
+ @bunk = @img.clone
27
+
28
+ # should output :love
29
+ puts @bunk.instance_variable_get(:@horse)
30
+
31
+ # should output :little
32
+ puts @bunk.little
33
+
34
+ # add a red line to the copy to identify it
35
+ #@bunk.line 0, 0, 1024, 1024, :color => :red
36
+
37
+ @bunk.each(:region =>[200,200,350,350]) { |c,x,y|
38
+
39
+ num_pixels = 0
40
+ total = [0, 0, 0, 0]
41
+ @bunk.circle x, y, 2,
42
+ :color_control => proc { |v|
43
+ if v
44
+ total[0] += v[0]
45
+ total[1] += v[1]
46
+ total[2] += v[2]
47
+ total[3] += v[3]
48
+
49
+ num_pixels += 1
50
+ end
51
+ :none
52
+ }
53
+
54
+ c[0] = total[0] / num_pixels.to_f
55
+ c[1] = total[1] / num_pixels.to_f
56
+ c[2] = total[2] / num_pixels.to_f
57
+ c[3] = total[3] / num_pixels.to_f
58
+ }
59
+
60
+ end
61
+
62
+ def draw
63
+ x = @img.width * rand
64
+ y = @img.height * rand
65
+
66
+ @img.draw 100, 50,1
67
+ @bunk.draw 500, 300,1
68
+ end
69
+
70
+ end
71
+
72
+
73
+ w = W.new
74
+ w.show
75
+
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+
6
+
7
+ class W < Gosu::Window
8
+ def initialize
9
+ super(1024, 768, false, 20)
10
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
11
+
12
+ # each can accept a block of two types of arity:
13
+ # arity 1 - yields just the pixel color
14
+ # arity 3 - yield the pixel color, and the x and y
15
+
16
+ # max out the blue component of every pixel
17
+ @img.each { |v| v[2] = 1 }
18
+
19
+ # a gradient from 0 red to 1 red
20
+ @img.each(:region => [100, 100, 200, 200]) do |c, x, y|
21
+ c[0] = (x - 100) / 100.0
22
+ end
23
+
24
+ # another gradient, this time blocking out everything except red (and alpha)
25
+ @img.each(:region => [100, 250, 200, 350]) do |c, x, y|
26
+ c[0] = (x - 100) / 100.0
27
+ c[1] = 0
28
+ c[2] = 0
29
+ end
30
+ end
31
+
32
+ def draw
33
+
34
+ @img.draw 100, 50,1
35
+ end
36
+
37
+ end
38
+
39
+
40
+ w = W.new
41
+ w.show
42
+
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(1024, 768, false, 20)
9
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
10
+
11
+ # put a border on the image
12
+ @img.rect 0,0, @img.width - 1, @img.height - 1
13
+
14
+ @length = 0
15
+ end
16
+
17
+ def draw
18
+
19
+ # quite a cool effect, very slow of course, because it's using turtle and fill
20
+ @img.paint {
21
+ forward(@length, true, :color => :red)
22
+ turn(170)
23
+ @length += 5
24
+ fill (@img.width * rand), (@img.height * rand), :color => :random, :glow => true
25
+ }
26
+
27
+ @img.draw 100, 50,1
28
+ end
29
+
30
+ end
31
+
32
+
33
+ w = W.new
34
+ w.show
35
+
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'texplay'
4
+
5
+
6
+ class W < Gosu::Window
7
+ def initialize
8
+ super(1024, 768, false, 20)
9
+ @img = TexPlay::create_blank_image(self, 1022, 800)
10
+ @tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
11
+ @gosu = Gosu::Image.new(self, "#{Common::MEDIA}/sand1.png")
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 + 90).step(185) { |x|
18
+ p = TexPlay::TPPoint.new
19
+ p.x = x
20
+ p.y = @img.height * rand
21
+
22
+ points << p
23
+ }
24
+
25
+ @img.bezier points
26
+
27
+ # NOTE: the :texture hash argument works on ALL drawing actions; not just fills
28
+ @img.fill 300, 650, :texture => @gosu
29
+
30
+ # let's demonstrate by drawing a circle using the gosu.png texture
31
+ # NOTE: :texture even works on lines, boxes, polylines, beziers etc.
32
+ @img.circle 400, 50, 40, :fill => true, :texture => @tp
33
+ end
34
+
35
+ def draw
36
+ @img.draw 10, 10,1
37
+ end
38
+
39
+ end
40
+
41
+
42
+ w = W.new
43
+ w.show
44
+