texplay 0.4.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG +222 -0
  3. data/README.markdown +48 -0
  4. data/Rakefile +16 -0
  5. data/examples/common.rb +18 -0
  6. data/examples/example_alpha_blend.rb +29 -0
  7. data/examples/example_bezier.rb +41 -0
  8. data/examples/example_blank.rb +37 -0
  9. data/examples/example_cache.rb +21 -0
  10. data/examples/example_color_control.rb +69 -0
  11. data/examples/example_color_transform.rb +62 -0
  12. data/examples/example_color_transform_circle.rb +34 -0
  13. data/examples/example_darken.rb +24 -0
  14. data/examples/example_dup.rb +73 -0
  15. data/examples/example_each.rb +39 -0
  16. data/examples/example_effect.rb +34 -0
  17. data/examples/example_fill.rb +43 -0
  18. data/examples/example_fill_old.rb +48 -0
  19. data/examples/example_fluent.rb +29 -0
  20. data/examples/example_font.rb +31 -0
  21. data/examples/example_hash_arguments.rb +46 -0
  22. data/examples/example_ippa.rb +23 -0
  23. data/examples/example_light.rb +75 -0
  24. data/examples/example_light_multiply.rb +18 -0
  25. data/examples/example_lsystem.rb +61 -0
  26. data/examples/example_melt.rb +25 -0
  27. data/examples/example_meyet.rb +62 -0
  28. data/examples/example_polyline.rb +42 -0
  29. data/examples/example_scale.rb +27 -0
  30. data/examples/example_select.rb +36 -0
  31. data/examples/example_select2.rb +25 -0
  32. data/examples/example_simple.rb +46 -0
  33. data/examples/example_splice.rb +26 -0
  34. data/examples/example_sync.rb +59 -0
  35. data/examples/example_tiles.rb +41 -0
  36. data/examples/example_trace.rb +22 -0
  37. data/examples/example_transparent.rb +28 -0
  38. data/examples/example_transparent2.rb +24 -0
  39. data/examples/example_transparent3.rb +20 -0
  40. data/examples/example_turtle.rb +39 -0
  41. data/examples/example_weird.rb +22 -0
  42. data/examples/example_window_render_to_image.rb +41 -0
  43. data/examples/example_window_to_blob.rb +35 -0
  44. data/examples/media/bird.png +0 -0
  45. data/examples/media/body.png +0 -0
  46. data/examples/media/empty2.png +0 -0
  47. data/examples/media/face.png +0 -0
  48. data/examples/media/gob.png +0 -0
  49. data/examples/media/gosu.png +0 -0
  50. data/examples/media/green.png +0 -0
  51. data/examples/media/logo.png +0 -0
  52. data/examples/media/maria.png +0 -0
  53. data/examples/media/object.png +0 -0
  54. data/examples/media/rose.bmp +0 -0
  55. data/examples/media/sand1.png +0 -0
  56. data/examples/media/sunset.png +0 -0
  57. data/examples/media/texplay.png +0 -0
  58. data/ext/texplay/actions.c +1006 -0
  59. data/ext/texplay/actions.h +60 -0
  60. data/ext/texplay/bindings.c +1125 -0
  61. data/ext/texplay/bindings.h +46 -0
  62. data/ext/texplay/cache.c +118 -0
  63. data/ext/texplay/cache.h +24 -0
  64. data/ext/texplay/compat.h +27 -0
  65. data/ext/texplay/extconf.rb +38 -0
  66. data/ext/texplay/graphics_utils.c +1313 -0
  67. data/ext/texplay/graphics_utils.h +22 -0
  68. data/ext/texplay/texplay.c +201 -0
  69. data/ext/texplay/texplay.h +153 -0
  70. data/ext/texplay/utils.c +891 -0
  71. data/ext/texplay/utils.h +153 -0
  72. data/ext/texplay/vendor/freeglut/include/GL/freeglut.h +22 -0
  73. data/ext/texplay/vendor/freeglut/include/GL/freeglut_ext.h +236 -0
  74. data/ext/texplay/vendor/freeglut/include/GL/freeglut_std.h +628 -0
  75. data/ext/texplay/vendor/freeglut/include/GL/glut.h +21 -0
  76. data/lib/texplay-contrib.rb +147 -0
  77. data/lib/texplay.rb +347 -0
  78. data/lib/texplay/1.8/texplay.so +0 -0
  79. data/lib/texplay/1.9/texplay.so +0 -0
  80. data/lib/texplay/alone.rb +20 -0
  81. data/lib/texplay/c_function_docs.rb +178 -0
  82. data/lib/texplay/live.rb +84 -0
  83. data/lib/texplay/version.rb +3 -0
  84. data/live/live.rb +85 -0
  85. data/test/image_spec.rb +45 -0
  86. data/test/texplay_spec.rb +144 -0
  87. metadata +179 -0
@@ -0,0 +1,62 @@
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+ #require 'devil/gosu'
4
+
5
+ class W < Gosu::Window
6
+ def initialize
7
+ super(500, 500, false, 20)
8
+ @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
9
+ @x = 100
10
+ @y = 100
11
+
12
+ @x2 = 400
13
+ @y2 = 100
14
+ @rad = 70
15
+ @s = true
16
+
17
+ @copy = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
18
+ @copy2 = TexPlay.create_image(self, @rad * 2 + 1, @rad * 2 + 1)
19
+ end
20
+
21
+ def draw
22
+ @pause = true
23
+
24
+ @x += 1
25
+ @y += 1
26
+
27
+ @x2 -= 1
28
+ @y2 += 1
29
+
30
+
31
+ @copy2.splice @img, 0, 0, :crop => [@x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad], :sync_mode => :no_sync
32
+ @copy.splice @img, 0, 0, :crop => [@x - @rad, @y - @rad, @x + @rad, @y + @rad], :sync_mode => :no_sync
33
+ @img.rect @x - @rad, @y - @rad, @x + @rad, @y + @rad, :fill => true, :mode => :color_dodge, :color => 0xff888888, :alpha_blend => true
34
+
35
+ @img.rect @x2 - @rad, @y2 - @rad, @x2 + @rad, @y2 + @rad, :fill => true, :mode => :color_dodge, :color => 0xff888888
36
+
37
+ # @img.force_sync [0,0, @img.width, @img.height]
38
+
39
+ @img.draw 10, 10,1
40
+
41
+ if button_down?(Gosu::KbEscape)
42
+ IL.Enable(IL::ORIGIN_SET)
43
+ IL.OriginFunc(IL::ORIGIN_UPPER_LEFT)
44
+ # screenshot.crop(0,0, 500, 500).save("screenshot.jpg").free
45
+ exit
46
+ end
47
+
48
+ end
49
+
50
+ def update
51
+ @img.splice @copy, @x - @rad, @y - @rad if !@s
52
+ @img.splice @copy2, @x2 - @rad, @y2 - @rad if !@s
53
+ @s = nil if @s
54
+
55
+ end
56
+
57
+ end
58
+
59
+
60
+ w = W.new
61
+ w.show
62
+
@@ -0,0 +1,34 @@
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, 300, false, 20)
7
+ @spritesheet = Gosu::Image.new(self, "body.png", false)
8
+ @spritesheet.splice(Gosu::Image.new(self, "face.png", false), 0,0, :alpha_blend => true)
9
+ @sprite_array = Gosu::Image::load_tiles(self, @spritesheet, 40, 80, false)
10
+ end
11
+
12
+ def draw
13
+ @sprite_array[0].draw(200,200,0)
14
+ end
15
+
16
+ end
17
+
18
+
19
+ w = W.new
20
+ w.show
21
+
22
+
23
+ # require 'rubygems'
24
+ # require 'gosu'
25
+ # require 'texplay'
26
+ # class Game_Window < Gosu::Window
27
+ # def initialize
28
+ # super(500, 400, false)
29
+ # self.caption = "Image Test"
30
+ # end
31
+
32
+ # def draw
33
+ # end
34
+ # end
@@ -0,0 +1,24 @@
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}/sunset.png")
8
+ @img.rect 0,0, @img.width - 1, @img.height - 1, :color_control => { :mult => [0.25, 0.25, 0.25, 1] }, :fill => true
9
+
10
+ @img.rect 230, 240, 330, 340, :fill => true,
11
+ :color_control => { :mult => [4, 4, 4, 1] }
12
+
13
+ end
14
+
15
+ def draw
16
+ @img.draw 0, 0,1
17
+ end
18
+
19
+ end
20
+
21
+
22
+ w = W.new
23
+ w.show
24
+
@@ -0,0 +1,73 @@
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 = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
9
+ @img.rect 0,0, @img.width - 1, @img.height - 1
10
+
11
+ # testing Gosu::Image#dup
12
+ # adding an ivar
13
+ @img.instance_variable_set(:@horse, :love)
14
+
15
+ # adding a method on the singleton
16
+ class << @img
17
+ def little
18
+ :little
19
+ end
20
+ end
21
+
22
+ # clone the image.
23
+ # NB #clone also copies singleton
24
+ @bunk = @img.clone
25
+
26
+ # should output :love
27
+ puts @bunk.instance_variable_get(:@horse)
28
+
29
+ # should output :little
30
+ puts @bunk.little
31
+
32
+ # add a red line to the copy to identify it
33
+ #@bunk.line 0, 0, 1024, 1024, :color => :red
34
+
35
+ @bunk.each(:region =>[200,200,350,350]) { |c,x,y| #
36
+
37
+ num_pixels = 0
38
+ total = [0, 0, 0, 0]
39
+ @bunk.circle x, y, 2,
40
+ :color_control => proc { |v|
41
+ if v
42
+ total[0] += v[0]
43
+ total[1] += v[1]
44
+ total[2] += v[2]
45
+ total[3] += v[3]
46
+
47
+ num_pixels += 1
48
+ end
49
+ :none
50
+ }
51
+
52
+ c[0] = total[0] / num_pixels.to_f
53
+ c[1] = total[1] / num_pixels.to_f
54
+ c[2] = total[2] / num_pixels.to_f
55
+ c[3] = total[3] / num_pixels.to_f
56
+ }
57
+
58
+ end
59
+
60
+ def draw
61
+ x = @img.width * rand
62
+ y = @img.height * rand
63
+
64
+ @img.draw 0, 0,1
65
+ @bunk.draw 0, 0,1
66
+ end
67
+
68
+ end
69
+
70
+
71
+ w = W.new
72
+ w.show
73
+
@@ -0,0 +1,39 @@
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}/sunset.png")
8
+
9
+ # each can accept a block of two types of arity:
10
+ # arity 1 - yields just the pixel color
11
+ # arity 3 - yield the pixel color, and the x and y
12
+
13
+ # max out the blue component of every pixel
14
+ @img.each { |v| v[2] = 1 }
15
+
16
+ # a gradient from 0 red to 1 red
17
+ @img.each(:region => [100, 100, 200, 200]) do |c, x, y|
18
+ c[0] = (x - 100) / 100.0
19
+ end
20
+
21
+ # another gradient, this time blocking out everything except red (and alpha)
22
+ @img.each(:region => [100, 250, 200, 350]) do |c, x, y|
23
+ c[0] = (x - 100) / 100.0
24
+ c[1] = 0
25
+ c[2] = 0
26
+ end
27
+ end
28
+
29
+ def draw
30
+
31
+ @img.draw 0, 0,1
32
+ end
33
+
34
+ end
35
+
36
+
37
+ w = W.new
38
+ w.show
39
+
@@ -0,0 +1,34 @@
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 = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
9
+
10
+ # put a border on the image
11
+ @img.rect 0,0, @img.width - 1, @img.height - 1
12
+
13
+ @length = 0
14
+ end
15
+
16
+ def draw
17
+
18
+ # quite a cool effect, very slow of course, because it's using turtle and fill
19
+ @img.paint {
20
+ forward(@length, true, :color => :red)
21
+ turn(170)
22
+ @length += 5
23
+ fill (@img.width * rand), (@img.height * rand), :color => :random, :glow => true
24
+ }
25
+
26
+ @img.draw 0, 0,1
27
+ end
28
+
29
+ end
30
+
31
+
32
+ w = W.new
33
+ w.show
34
+
@@ -0,0 +1,43 @@
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_blank_image(self, 1022, 800)
9
+ @tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
10
+ @gosu = Gosu::Image.new(self, "#{Common::MEDIA}/sand1.png")
11
+
12
+ points = []
13
+
14
+ # NOTE: TexPlay also accepts points. a 'point' is any object that responds to 'x' or y
15
+ # NOTE: current maximum points for a bezier is 13
16
+ (0..@img.width + 90).step(185) { |x|
17
+ p = TexPlay::TPPoint.new
18
+ p.x = x
19
+ p.y = @img.height * rand
20
+
21
+ points << p
22
+ }
23
+
24
+ @img.bezier points
25
+
26
+ # NOTE: the :texture hash argument works on ALL drawing actions; not just fills
27
+ @img.fill 300, 650, :texture => @gosu
28
+
29
+ # let's demonstrate by drawing a circle using the gosu.png texture
30
+ # NOTE: :texture even works on lines, boxes, polylines, beziers etc.
31
+ @img.circle 400, 50, 40, :fill => true, :texture => @tp
32
+ end
33
+
34
+ def draw
35
+ @img.draw 0, 0,1
36
+ end
37
+
38
+ end
39
+
40
+
41
+ w = W.new
42
+ w.show
43
+
@@ -0,0 +1,48 @@
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
+ @gosu = Gosu::Image.new(self, "#{Common::MEDIA}/gosu.png")
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).step(50) { |x|
19
+ p = TexPlay::TPPoint.new
20
+ p.x = x
21
+ p.y = @img.height * rand
22
+
23
+ points << p
24
+ }
25
+
26
+ @img.bezier points, :color => :white
27
+
28
+
29
+ # NOTE: the :texture hash argument works on ALL drawing actions; not just fills
30
+ @img.fill 300, 480, :texture => @tp
31
+
32
+ # let's demonstrate by drawing a circle using the gosu.png texture
33
+ # NOTE: :texture even works on lines, boxes, polylines, beziers etc.
34
+ @img.circle 400, 50, 40, :fill => true, :texture => @gosu
35
+
36
+ end
37
+
38
+ def draw
39
+
40
+ @img.draw 0, 0,1
41
+ end
42
+
43
+ end
44
+
45
+
46
+ w = W.new
47
+ w.show
48
+
@@ -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}/sunset.png")
8
+ @img.rect 0,0, @img.width - 1, @img.height - 1
9
+
10
+ # test the fluent interface
11
+ @img.
12
+ line(0, 0, 1024, 1024).
13
+ circle(20, 20, 50).
14
+ rect 30, 30, 100, 100
15
+ end
16
+
17
+ def draw
18
+ x = @img.width * rand
19
+ y = @img.height * rand
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,31 @@
1
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__))
2
+ require 'common'
3
+
4
+
5
+
6
+ # TEST_CASE 1 shows 2 pieces of text, but the background is black, even with :chroma_key. TEST_CASE 2 shows nothing.
7
+ # However, if you remove the :chroma_key's, you see a black background (and no text) in TEST_CASE 2, so there, :chroma_key appears to work.
8
+
9
+ class Wnd < Gosu::Window
10
+ def initialize
11
+ super(500, 200, false)
12
+ self.caption = "Splice Issues"
13
+
14
+ @chrome = TexPlay::create_blank_image(self, 200, 200)
15
+ @sunset = Gosu::Image.new(self, "#{Common::MEDIA}/sand1.png")
16
+
17
+
18
+ @long_text = Gosu::Image.from_text(self, "This is a long piece of text..", Gosu::default_font_name, 60)
19
+ @chrome.splice @long_text, 0, 0
20
+
21
+ @chrome.rect 0,0, @chrome.width, @chrome.height, :texture => @sunset, :fill => true, :mode => :multiply
22
+
23
+ end
24
+
25
+ def draw
26
+ @chrome.draw(0,0,1)
27
+ end
28
+ end
29
+
30
+ Wnd.new.show
31
+
@@ -0,0 +1,46 @@
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 = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
9
+ @tp = Gosu::Image.new(self, "#{Common::MEDIA}/texplay.png")
10
+
11
+
12
+ # put a border on the image
13
+ @img.rect 0,0, @img.width - 1, @img.height - 1
14
+
15
+ # it can be annoying having to specify a bunch of :hash_arguments for every action
16
+ # here is how you specify common hash args that all actions will use (in the same image)
17
+
18
+ # all actions that respond to 'thickness' use a thickness of 8 pixels
19
+ # also set the color to random
20
+ @img.set_options :thickness => 8, :color => :rand
21
+
22
+ @img.rect 100, 100, 200, 200, :fill => false
23
+
24
+ # NOTE: for ngon, the parameters are as follows: x, y, radius, num_sides
25
+ @img.ngon 400, 400, 40, 3
26
+
27
+ # NOTE: the defaults can also be overidden:
28
+ @img.ngon 400, 200, 90, 6, :thickness => 1
29
+
30
+ # you can also delete the defaults
31
+ @img.delete_options
32
+
33
+ # this action will no longer have any default values
34
+ @img.ngon 200, 400, 90, 10
35
+ end
36
+
37
+ def draw
38
+ @img.draw 100, 50,1
39
+ end
40
+
41
+ end
42
+
43
+
44
+ w = W.new
45
+ w.show
46
+