Module: TexPlay

Includes:
Colors
Included in:
Gosu::Image
Defined in:
lib/texplay.rb,
lib/texplay/alone.rb,
lib/texplay/version.rb,
lib/texplay/c_function_docs.rb,
ext/texplay/texplay.c

Defined Under Namespace

Modules: Colors Classes: EmptyImageStub, ImageStub, LSystem, TPPoint

Constant Summary collapse

RENDER_CLEAR_COLOR =
Gosu::Color.new(255, 0, 0, 0)
Win =
Gosu::Window.new(100, 100, false)
VERSION =
"0.4.3"
TP_MAX_QUAD_SIZE =

a constant containing the sidelength of largest allowable quad

INT2FIX(max_quad_size() - 2)

Constants included from Colors

Colors::Alpha, Colors::Black, Colors::Blue, Colors::Brown, Colors::Cyan, Colors::Green, Colors::Grey, Colors::Orange, Colors::Purple, Colors::Red, Colors::Turquoise, Colors::Tyrian, Colors::White, Colors::Yellow

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

Class Method Details

.create_blank_imageObject

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/texplay.rb', line 54

def create_image(window, width, height, options={})
  options = {
    :color => :alpha,
    :caching => false,
  }.merge!(options)

  raise ArgumentError, "Height and width must be positive" if height <= 0 or width <= 0
  
  img = Gosu::Image.new(window, EmptyImageStub.new(width, height), :caching => options[:caching])

  # this should be a major speedup (avoids both a cache and a sync
  # if color is alpha (default)
  if options[:color] != :alpha
    img.rect 0, 0, img.width - 1, img.height - 1, :color => options[:color], :fill => true
  end

  img
end

.create_image(width, height, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/texplay.rb', line 35

def create_image(window, width, height, options={})
  options = {
    :color => :alpha,
    :caching => false,
  }.merge!(options)

  raise ArgumentError, "Height and width must be positive" if height <= 0 or width <= 0
  
  img = Gosu::Image.new(window, EmptyImageStub.new(width, height), :caching => options[:caching])

  # this should be a major speedup (avoids both a cache and a sync
  # if color is alpha (default)
  if options[:color] != :alpha
    img.rect 0, 0, img.width - 1, img.height - 1, :color => options[:color], :fill => true
  end

  img
end

.create_macroObject

singleton method for creating & removing macros

.from_blob(window, blob_data, width, height, options = {}) ⇒ Object

Image can be :tileable, but it will break if it is tileable AND gets modified after creation.

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/texplay.rb', line 57

def from_blob(window, blob_data, width, height, options={})
  options = {
    :caching => false,
    :tileable => false,
  }.merge!(options)

  raise ArgumentError, "Height and width must be positive (received #{width}x#{height})" if height <= 0 or width <= 0

  expected_size = height * width * 4
  if blob_data.size != expected_size
    raise ArgumentError, "Blob data is not of the correct size (expected #{expected_size} but received #{blob_data.size} bytes)"
  end

  Gosu::Image.new(window, ImageStub.new(blob_data, width, height), options[:tileable], :caching => options[:caching])
end

.get_optionsObject



77
78
79
# File 'lib/texplay.rb', line 77

def get_options
  @options
end

.initObject



88
89
90
# File 'lib/texplay.rb', line 88

def init
  set_defaults
end

.load(name) ⇒ Object



11
12
13
# File 'lib/texplay/alone.rb', line 11

def load(name)
  Gosu::Image.new(Win, name)
end

.on_setup(&block) ⇒ Object



21
22
23
24
25
# File 'lib/texplay.rb', line 21

def on_setup(&block)
  raise "need a block" if !block
  @__init_procs__ ||= []
  @__init_procs__.push(block)
end

.original_create_imageObject

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/texplay/alone.rb', line 15

def create_image(window, width, height, options={})
  options = {
    :color => :alpha,
    :caching => false,
  }.merge!(options)

  raise ArgumentError, "Height and width must be positive" if height <= 0 or width <= 0
  
  img = Gosu::Image.new(window, EmptyImageStub.new(width, height), :caching => options[:caching])

  # this should be a major speedup (avoids both a cache and a sync
  # if color is alpha (default)
  if options[:color] != :alpha
    img.rect 0, 0, img.width - 1, img.height - 1, :color => options[:color], :fill => true
  end

  img
end

.refresh_cache_allObject

.remove_macroObject

.set_defaultsObject

default values defined here



82
83
84
85
86
# File 'lib/texplay.rb', line 82

def set_defaults
  @options = {
    :caching => :lazy
  }
end

.set_options(options = {}) ⇒ Object



73
74
75
# File 'lib/texplay.rb', line 73

def set_options(options = {})
  @options.merge!(options)
end

.setup(receiver) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/texplay.rb', line 27

def setup(receiver)
  if @__init_procs__ 
    @__init_procs__.each do |init_proc|
      receiver.instance_eval(&init_proc)
    end
  end
end

Instance Method Details

#[]Object

#bezier(points, options = {}) ⇒ Gosu::Image

Draw a bezier curve.

Parameters:

  • points (Array<Number, TPPoint>)

    Series of points (either [x1, y1, x2, y2, ...] or [point1, point2]).

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :closed (Boolean)

    Whether the last point is linked to the first.

  • :thickness (Number) — default: 1

    Thickness of the line.

  • :fill (Boolean) — default: false

    Whether to fill in the shape.

  • :filled (Boolean) — default: false

    Synonym for :fill

  • :alpha_blend (Boolean) — default: false

    Alpha-blend instead of overwrite.

  • :texture (Gosu::Image)

    Texture to use instead of a flat colour.

  • :mode (Symbol) — default: :copy

    Drawing mode to use.

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



11
12
# File 'lib/texplay/c_function_docs.rb', line 11

def bezier(points, options = {})
end

#cacheObject

#circle(center_x, center_y, radius, options = {}) ⇒ Gosu::Image

Note:

:thickness not implemented for circle.

Draw a circle.

Parameters:

  • center_x (Number)

    Horizontal center.

  • center_y (Number)

    Vertical center.

  • radius (Number)

    Radius.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :fill (Boolean) — default: false

    Whether to fill in the shape.

  • :filled (Boolean) — default: false

    Synonym for :fill

  • :alpha_blend (Boolean) — default: false

    Alpha-blend instead of overwrite.

  • :texture (Gosu::Image)

    Texture to use instead of a flat colour.

  • :mode (Symbol) — default: :copy

    Drawing mode to use.

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



25
26
# File 'lib/texplay/c_function_docs.rb', line 25

def circle(center_x, center_y, radius, options = {})
end

#clear(options = {}) ⇒ Gosu::Image

Clear an image.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :color (Object) — default: :alpha

    Colour of the image.

Returns:



117
118
119
120
121
122
123
124
# File 'lib/texplay.rb', line 117

def clear(options = {})
  options = {
    :color => :alpha,
    :fill => true
  }.merge!(options)

  rect 0, 0, width - 1, height - 1, options
end

#cloneGosu::Image

Make a copy of the image.

Returns:



31
32
# File 'lib/texplay/c_function_docs.rb', line 31

def clone()
end

#colorObject

#colourObject

#delete_optionsObject

#dupObject

rb_define_method(jm_Module, “[]=”, m_special_pixel, -1);



35
36
# File 'lib/texplay/c_function_docs.rb', line 35

def dup()
end

#each {|color, x, y| ... } ⇒ Object

Iterate through every pixel of the image, allowing modification of each pixels.

Yields:

  • (color, x, y)

    Colour and position (arity == 3).

  • (color)

    Colour only (arity == 1).

Yield Parameters:

  • color (Array<Float>)

    RGBA colour array. This can be modified to affect the image directly.

  • x (Integer)

    X position of the pixel.

  • y (Integer)

    Y position of the pixel.



45
46
# File 'lib/texplay/c_function_docs.rb', line 45

def each(&block)
end

#fill(x, y, options = {}) ⇒ Gosu::Image

Perform a Flood Fill at a given position.

Parameters:

  • x (Number)
  • y (Number)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



55
56
# File 'lib/texplay/c_function_docs.rb', line 55

def fill(x, y, options = {})
end

#force_sync(rectangle = [0, 0, width, height]) ⇒ Gosu::Image

Force synchronisation of the image (send from RAM to VRAM).

Parameters:

  • rectangle (Array<Number>) (defaults to: [0, 0, width, height])

    Area to synchronise.

Returns:



62
63
# File 'lib/texplay/c_function_docs.rb', line 62

def force_sync(rectangle = [0, 0, width, height])
end

#get_optionsObject

#get_pixel(x, y) ⇒ Array<Float>

Get the colour of an individual pixel.

Parameters:

  • x (Number)

    Horizontal position.

  • y (Number)

    Vertical position.

Returns:

  • (Array<Float>)

    4-element, RGBA colour array.



70
71
# File 'lib/texplay/c_function_docs.rb', line 70

def get_pixel(x, y)
end

#line(x1, y1, x2, y2, options = {}) ⇒ Gosu::Image

Parameters:

  • x1 (Number)

    X position of start of line.

  • y1 (Number)

    Y position of start of line.

  • x2 (Number)

    X position of end of line.

  • y2 (Number)

    Y position of end of line.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :thickness (Number) — default: 1

    Thickness of the line.

  • :trace (Hash)

    Trace

  • :alpha_blend (Boolean) — default: false

    Alpha-blend instead of overwrite.

  • :texture (Gosu::Image)

    Texture to use instead of a flat colour.

  • :mode (Symbol) — default: :copy

    Drawing mode to use.

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



81
82
# File 'lib/texplay/c_function_docs.rb', line 81

def line(x1, y1, x2, y2, options = {})
end

#ngon(center_x, center_y, radius, sides, options = {}) ⇒ Gosu::Image

Draw an n-sided polygon.

Parameters:

  • sides (Integer)

    Number of sides for the polygon.

  • center_x (Number)

    Horizontal center.

  • center_y (Number)

    Vertical center.

  • radius (Number)

    Radius.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :fill (Boolean) — default: false

    Whether to fill in the shape.

  • :filled (Boolean) — default: false

    Synonym for :fill

  • :alpha_blend (Boolean) — default: false

    Alpha-blend instead of overwrite.

  • :texture (Gosu::Image)

    Texture to use instead of a flat colour.

  • :mode (Symbol) — default: :copy

    Drawing mode to use.

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



90
91
# File 'lib/texplay/c_function_docs.rb', line 90

def ngon(center_x, center_y, radius, sides, options = {})
end

#offset(x, y) ⇒ Gosu::Image

Offset all future drawing actions.

The offset is non-stacking.

Can also use offset(:default) to reset offset to (0, 0).

Parameters:

  • x (Number)
  • y (Number)

Returns:



102
103
# File 'lib/texplay/c_function_docs.rb', line 102

def offset(x, y)
end

#paint(options = {}, &block) ⇒ Object

TexPlay methods



120
121
# File 'lib/texplay/c_function_docs.rb', line 120

def paint(options = {}, &block)
end

#polyline(points, options = {}) ⇒ Gosu::Image

Draw a series of connected lines.

Parameters:

  • points (Array<Number, TPPoint>)

    Series of points (either [x1, y1, x2, y2, ...] or [point1, point2]).

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :closed (Boolean)

    Whether the last point is linked to the first.

  • :thickness (Number) — default: 1

    Thickness of the line.

  • :fill (Boolean) — default: false

    Whether to fill in the shape.

  • :filled (Boolean) — default: false

    Synonym for :fill

  • :alpha_blend (Boolean) — default: false

    Alpha-blend instead of overwrite.

  • :texture (Gosu::Image)

    Texture to use instead of a flat colour.

  • :mode (Symbol) — default: :copy

    Drawing mode to use.

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



129
130
# File 'lib/texplay/c_function_docs.rb', line 129

def polyline(points, options = {})
end

#quad_cached?Boolean

Returns:

  • (Boolean)

#rect(x1, y1, x2, y2, options = {}) ⇒ Gosu::Image Also known as: box

Draw a rectangle.

Parameters:

  • x1 (Number)

    Top of the rectangle.

  • y1 (Number)

    Left of the rectangle.

  • x2 (Number)

    Right of the rectangle.

  • y2 (Number)

    Bottom of the rectangle.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :thickness (Number) — default: 1

    Thickness of the line.

  • :fill (Boolean) — default: false

    Whether to fill in the shape.

  • :filled (Boolean) — default: false

    Synonym for :fill

  • :alpha_blend (Boolean) — default: false

    Alpha-blend instead of overwrite.

  • :texture (Gosu::Image)

    Texture to use instead of a flat colour.

  • :mode (Symbol) — default: :copy

    Drawing mode to use.

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



141
142
# File 'lib/texplay/c_function_docs.rb', line 141

def rect(x1, y1, x2, y2, options = {})
end

#refresh_cacheObject

#set_optionsObject

#set_pixel(x, y, options = {}) ⇒ Gosu::Image Also known as: pixel

Set the colour of an individual pixel.

Parameters:

  • x (Number)
  • y (Number)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :alpha_blend (Boolean) — default: false

    Alpha-blend instead of overwrite.

  • :texture (Gosu::Image)

    Texture to use instead of a flat colour.

  • :mode (Symbol) — default: :copy

    Drawing mode to use.

  • :color (Gosu::Color, Array<Float>, Symbol) — default: :white

    Colour to apply to the drawing action.

  • :color_control (Proc, Hash)

    Effect to apply to the drawing action.

Returns:



154
155
# File 'lib/texplay/c_function_docs.rb', line 154

def set_pixel(x, y, options = {})
end

#splice(x, y, source, options = {}) ⇒ Gosu::Image Also known as: composite

Copy an image into another image.

Parameters:

  • x (Number)

    Horizontal position to splice at.

  • y (Number)

    Vertical position to splice at.

  • source (Gosu::Image)

    Image to copy from.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :chroma_key (Gosu::Color, Array<Float>, Symbol)

    Colour to treat as transparent (only other colour pixels will be spliced).

  • :chroma_key_not (Gosu::Color, Array<Float>, Symbol)

    Colour to copy (other colours won't be spliced).

  • :crop (Array<Float>) — default: [0, 0, source.width - 1, source.height - 1]

    Area of the source image to splice.

Returns:



167
168
# File 'lib/texplay/c_function_docs.rb', line 167

def splice(x, y, source, options = {})
end

#to_blobString

Note:

This method is usually overridden by the default Gosu::Image#to_blob.

Note:

This method causes a segmentation fault in Windows.

Generate binary data from the image.

Returns:

  • (String)

    Raw binary data (blob) in RGBA byte order.



176
177
# File 'lib/texplay/c_function_docs.rb', line 176

def to_blob
end