texplay 0.2.1-x86-mswin32-60
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 +68 -0
 - data/README +21 -0
 - data/README1st +9 -0
 - data/Rakefile +85 -0
 - data/examples/basic.rb +48 -0
 - data/examples/basic2.rb +37 -0
 - data/examples/benchmark.rb +299 -0
 - data/examples/common.rb +8 -0
 - data/examples/example_alpha_blend.rb +31 -0
 - data/examples/example_bezier.rb +51 -0
 - data/examples/example_color_control.rb +68 -0
 - data/examples/example_color_transform.rb +29 -0
 - data/examples/example_dup.rb +52 -0
 - data/examples/example_each.rb +42 -0
 - data/examples/example_effect.rb +35 -0
 - data/examples/example_fill.rb +49 -0
 - data/examples/example_fill_old.rb +49 -0
 - data/examples/example_fluent.rb +31 -0
 - data/examples/example_gen_eval.rb +34 -0
 - data/examples/example_hash_arguments.rb +47 -0
 - data/examples/example_melt.rb +27 -0
 - data/examples/example_polyline.rb +43 -0
 - data/examples/example_simple.rb +35 -0
 - data/examples/example_sync.rb +60 -0
 - data/examples/example_turtle.rb +40 -0
 - data/examples/media/empty2.png +0 -0
 - data/examples/media/gosu.png +0 -0
 - data/examples/media/maria.png +0 -0
 - data/examples/media/rose.bmp +0 -0
 - data/examples/media/sand1.png +0 -0
 - data/examples/media/sunset.png +0 -0
 - data/examples/media/texplay.png +0 -0
 - data/examples/specs.rb +240 -0
 - data/examples/test.rb +70 -0
 - data/examples/test2.rb +72 -0
 - data/lib/ctexplay.18.so +0 -0
 - data/lib/ctexplay.19.so +0 -0
 - data/lib/texplay-contrib.rb +77 -0
 - data/lib/texplay.rb +134 -0
 - data/src/Makefile +181 -0
 - data/src/TAGS +286 -0
 - data/src/actions.c +1306 -0
 - data/src/actions.h +52 -0
 - data/src/actions.obj +0 -0
 - data/src/bindings.c +1081 -0
 - data/src/bindings.h +45 -0
 - data/src/bindings.obj +0 -0
 - data/src/cache.c +132 -0
 - data/src/cache.h +24 -0
 - data/src/cache.obj +0 -0
 - data/src/compat.h +23 -0
 - data/src/ctexplay-i386-mswin32.def +2 -0
 - data/src/ctexplay-i386-mswin32.exp +0 -0
 - data/src/ctexplay-i386-mswin32.lib +0 -0
 - data/src/ctexplay-i386-mswin32.pdb +0 -0
 - data/src/ctexplay.so +0 -0
 - data/src/extconf.rb +18 -0
 - data/src/gen_eval.c +209 -0
 - data/src/gen_eval.h +20 -0
 - data/src/gen_eval.obj +0 -0
 - data/src/mkmf.log +18 -0
 - data/src/object2module.c +171 -0
 - data/src/object2module.h +11 -0
 - data/src/object2module.obj +0 -0
 - data/src/texplay.c +136 -0
 - data/src/texplay.h +107 -0
 - data/src/texplay.obj +0 -0
 - data/src/utils.c +959 -0
 - data/src/utils.h +143 -0
 - data/src/utils.obj +0 -0
 - data/src/vc60.pdb +0 -0
 - metadata +132 -0
 
    
        data/examples/common.rb
    ADDED
    
    
| 
         @@ -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, 769, 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,51 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'common'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'texplay'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class W < Gosu::Window
         
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 8 
     | 
    
         
            +
                    super(1024, 769, 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 
     | 
    
         
            +
                    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(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.move_to(points.first.x, points.first.y)
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                    # making the bezier more interesting by using turtle graphics :) (a rough bezier)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @img.bezier points, :color => :red, :color_control => proc { |c, x, y|
         
     | 
| 
      
 30 
     | 
    
         
            +
                        if((x % 10) == 0) then
         
     | 
| 
      
 31 
     | 
    
         
            +
                            @img.line_to(x, y + rand * 20 - 10)
         
     | 
| 
      
 32 
     | 
    
         
            +
                        end
         
     | 
| 
      
 33 
     | 
    
         
            +
                        :none
         
     | 
| 
      
 34 
     | 
    
         
            +
                    }
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                    #@img.fill 100, 400, :color => :yellow
         
     | 
| 
      
 37 
     | 
    
         
            +
                    
         
     | 
| 
      
 38 
     | 
    
         
            +
                    # NOTE: can 'close' a bezier curve too (as with polylines)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
                
         
     | 
| 
      
 41 
     | 
    
         
            +
                def draw
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                    @img.draw 100, 50,1
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
                
         
     | 
| 
      
 46 
     | 
    
         
            +
            end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            w = W.new
         
     | 
| 
      
 50 
     | 
    
         
            +
            w.show
         
     | 
| 
      
 51 
     | 
    
         
            +
                    
         
     | 
| 
         @@ -0,0 +1,68 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'common'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'texplay'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            class W < Gosu::Window
         
     | 
| 
      
 6 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 7 
     | 
    
         
            +
                    super(1024, 769, 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 1: just the destination pixel color is yielded
         
     | 
| 
      
 22 
     | 
    
         
            +
                    # arity of 2: both the destination and the source pixel colors are yielded (in that order)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    # arity of 3: the destination pixel color is yielded along with the x and y coords of the current pixel
         
     | 
| 
      
 24 
     | 
    
         
            +
                    # arity of 4: both the destination and the source pixel colours are yielded as well as the x and y vals
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    # just drawing an area to fill
         
     | 
| 
      
 27 
     | 
    
         
            +
                    @img.polyline [30, 30, 100, 100, 200, 76, 300, 9, 50, 200], :color => :random, :closed => true
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                    # below we are 'faking' a texture fill using color_control
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @img.fill 42, 70, :color_control => proc { |c, x, y|
         
     | 
| 
      
 31 
     | 
    
         
            +
                        @tp.get_pixel(x % @tp.width, y % @tp.height)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    }
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    # merging two images together
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @img.rect 100, 200, 400, 300, :fill => true, :texture => @gosu,
         
     | 
| 
      
 36 
     | 
    
         
            +
                    :color_control => proc { |c1, c2, x, y|
         
     | 
| 
      
 37 
     | 
    
         
            +
                        c1 = @tp.get_pixel(x % @tp.width, y % @tp.height)
         
     | 
| 
      
 38 
     | 
    
         
            +
                        c1[0] = (c1[0] + c2[0]) / 2
         
     | 
| 
      
 39 
     | 
    
         
            +
                        c1[1] = (c1[1] + c2[1]) / 2
         
     | 
| 
      
 40 
     | 
    
         
            +
                        c1[2] = (c1[2] + c2[2]) / 2
         
     | 
| 
      
 41 
     | 
    
         
            +
                        c1[3] = 1
         
     | 
| 
      
 42 
     | 
    
         
            +
                        c1
         
     | 
| 
      
 43 
     | 
    
         
            +
                    }
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    # we can even use color_control just for the use of the (x, y) values.
         
     | 
| 
      
 46 
     | 
    
         
            +
                    # here we simply use the x, y values to make our own circle with a rough edge
         
     | 
| 
      
 47 
     | 
    
         
            +
                    @img.circle 200,400, 70,
         
     | 
| 
      
 48 
     | 
    
         
            +
                    :color_control => proc { |c,x,y|
         
     | 
| 
      
 49 
     | 
    
         
            +
                        @img.pixel(x + (rand(4) - 2), y + (rand(4) - 2)) 
         
     | 
| 
      
 50 
     | 
    
         
            +
                        :none   # this ensures that the 'actual' circle isn't drawn, instead its coordinates are
         
     | 
| 
      
 51 
     | 
    
         
            +
                                # simply utilized to draw a ragged edge of another circle (using @img.pixel)
         
     | 
| 
      
 52 
     | 
    
         
            +
                    }
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                    # this just fills a rect with random colours
         
     | 
| 
      
 55 
     | 
    
         
            +
                    @img.rect 400, 400, 470, 470, :fill => true, :color_control => proc { |c| :rand }
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                def draw
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                    @img.draw 100, 50,1
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
                
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            w = W.new
         
     | 
| 
      
 67 
     | 
    
         
            +
            w.show
         
     | 
| 
      
 68 
     | 
    
         
            +
                    
         
     | 
| 
         @@ -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, 769, 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, :color_control => { :mult => [0.9 , 0.3, 0.3, 1] }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 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,52 @@ 
     | 
|
| 
      
 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, 769, 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 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
                
         
     | 
| 
      
 39 
     | 
    
         
            +
                def draw
         
     | 
| 
      
 40 
     | 
    
         
            +
                    x = @img.width * rand
         
     | 
| 
      
 41 
     | 
    
         
            +
                    y = @img.height * rand
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                    @img.draw 100, 50,1
         
     | 
| 
      
 44 
     | 
    
         
            +
                    @bunk.draw 500, 300,1
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
                
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            w = W.new
         
     | 
| 
      
 51 
     | 
    
         
            +
            w.show
         
     | 
| 
      
 52 
     | 
    
         
            +
                    
         
     | 
| 
         @@ -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, 769, 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, 769, 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,49 @@ 
     | 
|
| 
      
 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, 1000, 1000)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    #        @img = Gosu::Image.new(self, "#{Common::MEDIA}/empty2.png")
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @tp = Gosu::Image.new(self, "#{Common::MEDIA}/maria.png")
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @gosu = Gosu::Image.new(self, "#{Common::MEDIA}/sand1.png")
         
     | 
| 
      
 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 + 90).step(85) { |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
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                    # NOTE: the :texture hash argument works on ALL drawing actions; not just fills
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @img.fill 300, 400, :color => :red, :texture => @gosu
         
     | 
| 
      
 31 
     | 
    
         
            +
            #        @img.circle 300, 400, 40
         
     | 
| 
      
 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 => @tp
         
     | 
| 
      
 36 
     | 
    
         
            +
                    
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
                
         
     | 
| 
      
 39 
     | 
    
         
            +
                def draw
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                    @img.draw 10, 10,1
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
                
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            w = W.new
         
     | 
| 
      
 48 
     | 
    
         
            +
            w.show
         
     | 
| 
      
 49 
     | 
    
         
            +
                    
         
     | 
| 
         @@ -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, 769, 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 
     | 
    
         
            +
                    
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'common'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'gosu'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'texplay'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class W < Gosu::Window
         
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 8 
     | 
    
         
            +
                    super(1024, 769, false, 20)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @img = Gosu::Image.new(self, "#{Common::MEDIA}/sunset.png")
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @img.rect 0,0, @img.width - 1, @img.height - 1
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    # test the fluent interface
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @img.
         
     | 
| 
      
 14 
     | 
    
         
            +
                        line(0, 0, 1024, 1024).
         
     | 
| 
      
 15 
     | 
    
         
            +
                        circle(20, 20, 50).
         
     | 
| 
      
 16 
     | 
    
         
            +
                        rect 30, 30, 100, 100
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
                
         
     | 
| 
      
 19 
     | 
    
         
            +
                def draw
         
     | 
| 
      
 20 
     | 
    
         
            +
                    x = @img.width * rand
         
     | 
| 
      
 21 
     | 
    
         
            +
                    y = @img.height * rand
         
     | 
| 
      
 22 
     | 
    
         
            +
                    
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @img.draw 100, 50,1
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            w = W.new
         
     | 
| 
      
 30 
     | 
    
         
            +
            w.show
         
     | 
| 
      
 31 
     | 
    
         
            +
                    
         
     |