texplay 0.2.721-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/CHANGELOG +119 -0
  2. data/README.markdown +41 -0
  3. data/Rakefile +66 -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_color_control.rb +69 -0
  8. data/examples/example_color_transform.rb +68 -0
  9. data/examples/example_dup.rb +75 -0
  10. data/examples/example_each.rb +42 -0
  11. data/examples/example_effect.rb +35 -0
  12. data/examples/example_fill.rb +44 -0
  13. data/examples/example_fill_old.rb +49 -0
  14. data/examples/example_fluent.rb +31 -0
  15. data/examples/example_gen_eval.rb +34 -0
  16. data/examples/example_hash_arguments.rb +47 -0
  17. data/examples/example_lsystem.rb +61 -0
  18. data/examples/example_melt.rb +27 -0
  19. data/examples/example_polyline.rb +43 -0
  20. data/examples/example_scale.rb +29 -0
  21. data/examples/example_simple.rb +38 -0
  22. data/examples/example_splice.rb +27 -0
  23. data/examples/example_sync.rb +60 -0
  24. data/examples/example_turtle.rb +40 -0
  25. data/examples/example_weird.rb +29 -0
  26. data/examples/media/bird.png +0 -0
  27. data/examples/media/empty2.png +0 -0
  28. data/examples/media/gob.png +0 -0
  29. data/examples/media/gosu.png +0 -0
  30. data/examples/media/green.png +0 -0
  31. data/examples/media/logo.png +0 -0
  32. data/examples/media/maria.png +0 -0
  33. data/examples/media/rose.bmp +0 -0
  34. data/examples/media/sand1.png +0 -0
  35. data/examples/media/sunset.png +0 -0
  36. data/examples/media/texplay.png +0 -0
  37. data/lib/1.8/texplay.so +0 -0
  38. data/lib/1.9/texplay.so +0 -0
  39. data/lib/texplay/version.rb +3 -0
  40. data/lib/texplay-contrib.rb +171 -0
  41. data/lib/texplay.rb +137 -0
  42. metadata +115 -0
data/CHANGELOG ADDED
@@ -0,0 +1,119 @@
1
+ 12/03/10
2
+ version 0.2.721
3
+ * fixed bug in alpha_blend (now blends alpha channels too)
4
+
5
+ 6/12/09
6
+ version 0.2.710
7
+ * fixed bug in line drawing code (wasn't drawing final pixel)
8
+ * fixed bug in filled rect code (wasn't drawing final row)
9
+ * fixed bug in flood fill (wasn't drawing on first column)
10
+ * added glDisable(GL_TEXTURE_2D) calls to cache.c, and removed 'restore previous texture binding' (i doubt there is any previous binding to restore)
11
+ * using version.rb to help manage versions
12
+
13
+ 23/11/09
14
+ * fixed bug in texplay.rb. Replaced TexPlay::TP_MAX_QUAD_SIZE - 2 with
15
+ just TexPlay::TP_MAX_QUAD_SIZE (the -2 is now built into the constant)
16
+
17
+ 16/10/09
18
+ version 0.2.700
19
+ * removed memory leak from Gosu::Image#to_blob, now writing directly to RSTRING_PTR
20
+
21
+ 12/10/09
22
+ version 0.2.666
23
+ * added Gosu::Image#to_blob
24
+ * to_blob functionality enables Gosu::Images to work with DevIL library
25
+
26
+ 6/10/09
27
+ version 0.2.5
28
+ * fixed quad_draw flicker bug
29
+ * added splice_and_scale (to texplay-contrib.rb)
30
+ * now using rake-compiler to run build process
31
+
32
+ 15/9/09
33
+ version 0.2.4
34
+ * added lsystem
35
+ * made lsystem both 1.9.1 and 1.8.6 compatible
36
+
37
+ 11/9/09
38
+ version 0.2.3
39
+ * added Ruby 1.8.7 compatibility by modifying extconf.rb to define RUBY_19 macro
40
+ * and modified compat.h to get rid of feature test (fails on 1.8.7)
41
+
42
+ 8/9/09
43
+ version 0.2.2
44
+ * fixed color_control bug, action_struct->color was being overwritten (now using a temp).
45
+ * fixed faulty error msg where max tex size was being displayed as 1024 but is actually 1022
46
+ * added :start_angle parameter to ngon action
47
+ * fixed example screen height from 769 to 768
48
+ * arity of -1 and 0 now supported for color_control procs
49
+ * fixed parameter checks for circle and ngon
50
+ * updated documentation to reflect changes, and added details on caching
51
+
52
+ 2/9/09
53
+ version 0.2.1
54
+ * releasing a gem for TexPlay
55
+ * bumped version number so can add add gosu 0.7.14 dependency to github gem
56
+ * hopefully gem works on both github and rubyforge
57
+ 31/8/09
58
+ version 0.2.0
59
+ * added each iterator
60
+ * added alternative to proc for :color_control proc (allowing static linear transforms to pixels)
61
+ * no longer segfaulting on windows (no idea why not)
62
+ * rewrote EmptyImageStub in ruby, using philomory's code. now alot faster.
63
+ * implemented 'shadow' in terms of static :color_control pixel transform
64
+ * added more example code demonstrating each iterator (example_each.rb) and new color_control behaviour
65
+ i.e example_color_transform.rb
66
+ * should be relatively stable now!
67
+
68
+ 28/8/09
69
+ version 0.1.9.1 (still BETA)
70
+ * experimental features: Gosu::Image#dup and Gosu::Image#clone
71
+ * also TexPlay::create_blank_image(window, width, height)
72
+ * I noticed these features SEG FAULT on my setup in windows, so be warned
73
+ * This is a BETA release
74
+
75
+ 14/8/09
76
+ version 0.1.9.0 (BETA)
77
+ * major rewrite. TP now supports beziers, polylines, polygons, and more
78
+ * also supports alpha_blending (though still tempermental)
79
+ * This is a BETA release
80
+
81
+ 1/7/09
82
+ version 0.1.6.2
83
+ * fixed another subtle bug in constrain_local_boundaries(). Function was
84
+ unable to deal with drawing actions that were 100% outside the image
85
+ boundaries.
86
+
87
+ 28/6/09
88
+ version 0.1.6
89
+ * gen_eval now working as a replacement for instance_eval in the #paint block. Allows for more user-friendly interface.
90
+ * #paint can now be called without a block; if invoked this way it executes any commands in the action queue, e.g
91
+ @img.circle 20, 20, 40
92
+ @img.pixel 30, 30
93
+ @img.paint
94
+ * above will function as if: @img.paint { circle 20, 20, 40; pixel 30, 30 }
95
+ * collected 1.8.6/1.9.1 compatibility into compat.h
96
+
97
+ 16/6/09
98
+ version 0.1.4.6
99
+ * allowed arity of 0 (as well as -1) for ruby 1.9 compatibility
100
+
101
+ 13/6/09
102
+ version 0.1.4.5
103
+ * major bugfix with TexPlay#splice method (segfaut). Also added new color format parameter: color [1, 1, 0, 1] (e.g purple with full alpha).
104
+ Also fixed subtle edge-case bug in constrain_local_boundaries().
105
+
106
+ 9/6/09
107
+ version 0.1.4
108
+ * improved error checking. should work better with later gosu releases
109
+
110
+ 20/2/09
111
+ version 0.1.1
112
+ * rerelease of this version fixing the oversized image bug for refresh_cache (i.e images over 500 x 500
113
+
114
+ version 0.1.1
115
+ * oops, bug in leftshift/rightshift functions, fixed!
116
+
117
+ version 0.1.0
118
+ * release!
119
+
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.710**
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,66 @@
1
+
2
+ require 'rake/clean'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/extensiontask'
5
+
6
+ # get the texplay version
7
+ require 'lib/texplay/version'
8
+
9
+ $dlext = Config::CONFIG['DLEXT']
10
+
11
+ CLEAN.include("ext/**/*.#{$dlext}", "ext/**/*.log", "ext/**/*.o", "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "ext/**/*.def", "ext/**/*.pdb")
12
+ CLOBBER.include("**/*.#{$dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
13
+
14
+ specification = Gem::Specification.new do |s|
15
+ s.name = "texplay"
16
+ s.summary = "TexPlay is a light-weight image manipulation framework for Ruby and Gosu"
17
+ s.version = TexPlay::VERSION
18
+ s.date = Time.now.strftime '%Y-%m-%d'
19
+ s.author = "John Mair (banisterfiend)"
20
+ s.email = 'jrmair@gmail.com'
21
+ s.description = s.summary
22
+ s.require_path = 'lib'
23
+ s.add_dependency("gosu",">=0.7.14")
24
+ s.platform = Gem::Platform::RUBY
25
+ s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
26
+ s.has_rdoc = false
27
+
28
+ s.extensions = ["ext/texplay/extconf.rb"]
29
+ s.files = ["Rakefile", "README.markdown", "CHANGELOG",
30
+ "lib/texplay.rb", "lib/texplay-contrib.rb", "lib/texplay/version.rb"] +
31
+ FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "examples/*.rb", "examples/media/*"].to_a
32
+ end
33
+
34
+ Rake::ExtensionTask.new('texplay', specification) do |ext|
35
+ # ext.config_script = 'extconf.rb'
36
+ # ext.cross_compile = true
37
+ #ext.cross_platform = 'i386-mswin32'
38
+ # ext.platform = 'i386-mswin32'
39
+ end
40
+
41
+
42
+
43
+ specification = Gem::Specification.new do |s|
44
+ s.name = "texplay"
45
+ s.summary = "TexPlay is a light-weight image manipulation framework for Ruby and Gosu"
46
+ s.version = TexPlay::VERSION
47
+ s.date = Time.now.strftime '%Y-%m-%d'
48
+ s.author = "John Mair (banisterfiend)"
49
+ s.email = 'jrmair@gmail.com'
50
+ s.description = s.summary
51
+ s.require_path = 'lib'
52
+ s.add_dependency("gosu",">=0.7.14")
53
+ s.platform = 'i386-mingw32'
54
+ s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
55
+ s.has_rdoc = false
56
+
57
+ s.files = ["Rakefile", "README.markdown", "CHANGELOG",
58
+ "lib/texplay.rb", "lib/texplay-contrib.rb", "lib/texplay/version.rb", "lib/1.8/texplay.so",
59
+ "lib/1.9/texplay.so"] +
60
+ FileList["examples/*.rb", "examples/media/*"].to_a
61
+ end
62
+
63
+ Rake::GemPackageTask.new(specification) do |package|
64
+ package.need_zip = false
65
+ package.need_tar = false
66
+ 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,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,68 @@
1
+ require 'rubygems'
2
+ require 'common'
3
+ require 'gosu'
4
+ require 'texplay'
5
+ #require 'devil/gosu'
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
+ @x = 100
12
+ @y = 100
13
+
14
+ @x2 = 400
15
+ @y2 = 100
16
+ @rad = 50
17
+ @s = true
18
+
19
+ @copy = TexPlay.create_blank_image(self, @rad * 2 + 1, @rad * 2 + 1)
20
+ @copy2 = TexPlay.create_blank_image(self, @rad * 2 + 1, @rad * 2 + 1)
21
+ end
22
+
23
+ def draw
24
+
25
+
26
+ @x += 1
27
+ @y += 1
28
+
29
+ @x2 -= 1
30
+ @y2 += 1
31
+
32
+
33
+ @copy2.splice @img, 0, 0, :crop => [@x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad]
34
+ @copy.splice @img, 0, 0, :crop => [@x - @rad, @y - @rad, @x + @rad, @y + @rad]
35
+ @img.
36
+ circle @x, @y, @rad, :fill => true,
37
+ :color_control => { :mult => [1.0, 0.5, 0.5, 1] }
38
+
39
+ # circle @x2, @y2, @rad, :fill => true,
40
+ # :color_control => { :mult => [0.3, 0.9, 0.3, 1] }
41
+
42
+
43
+ # @img.force_sync [0,0, @img.width, @img.height]
44
+
45
+ @img.draw 10, 10,1
46
+
47
+ if button_down?(Gosu::KbEscape)
48
+ IL.Enable(IL::ORIGIN_SET)
49
+ IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
50
+ # screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
51
+ exit
52
+ end
53
+
54
+ end
55
+
56
+ def update
57
+ @img.splice @copy, @x - @rad, @y - @rad if !@s
58
+ @img.splice @copy2, @x2 - @rad, @y2 - @rad if !@s
59
+ @s = nil if @s
60
+
61
+ end
62
+
63
+ end
64
+
65
+
66
+ w = W.new
67
+ w.show
68
+
@@ -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
+
@@ -0,0 +1,49 @@
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
+ points = []
16
+
17
+ # NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or 'y'
18
+ # NOTE: current maximum points for a bezier is 13
19
+ (0..@img.width).step(50) { |x|
20
+ p = TexPlay::TPPoint.new
21
+ p.x = x
22
+ p.y = @img.height * rand
23
+
24
+ points << p
25
+ }
26
+
27
+ @img.bezier points, :color => :white
28
+
29
+
30
+ # NOTE: the :texture hash argument works on ALL drawing actions; not just fills
31
+ @img.fill 300, 480, :texture => @tp
32
+
33
+ # let's demonstrate by drawing a circle using the gosu.png texture
34
+ # NOTE: :texture even works on lines, boxes, polylines, beziers etc.
35
+ @img.circle 400, 50, 40, :fill => true, :texture => @gosu
36
+
37
+ end
38
+
39
+ def draw
40
+
41
+ @img.draw 100, 50,1
42
+ end
43
+
44
+ end
45
+
46
+
47
+ w = W.new
48
+ w.show
49
+