Class: Yeah::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/yeah/_platform/display.rb

Overview

Note:

Provided by a Platform.

The Display is responsible for drawing to a game display. It provides a procedural drawing API similar to Processing or HTML5 Canvas. Its drawing origin is the top-left corner. Without an explicit size, it fills its entire container.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Display

Returns a new instance of Display

Parameters:

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

    for new object

Options Hash (options):

  • :width (Integer)

    of display

  • :height (Integer)

    of display

  • :canvas_selector (String) — default: 'canvas'

    for canvas HTML element (applies only to Web::Display)

Raises:

  • (NotImplementedError)

14
15
16
# File 'lib/yeah/_platform/display.rb', line 14

def initialize(options = {})
  raise NotImplementedError
end

Instance Attribute Details

#fill_colorColor

Returns color for fill

Parameters:

  • color (Color)

    for fill

Returns:

  • (Color)

    color for fill


# File 'lib/yeah/_platform/display.rb', line 30

#heightInteger

Returns height of display in pixels

Parameters:

  • height (Integer)

    to make display in pixels

Returns:

  • (Integer)

    height of display in pixels


# File 'lib/yeah/_platform/display.rb', line 22

#size(Integer, Integer)

Returns size of display in pixels

Parameters:

  • size ((Integer, Integer))

    to make display in pixels

Returns:

  • ((Integer, Integer))

    size of display in pixels


# File 'lib/yeah/_platform/display.rb', line 26

#stroke_colorColor

Returns color for stroke

Parameters:

  • color (Color)

    for stroke

Returns:

  • (Color)

    color for stroke


# File 'lib/yeah/_platform/display.rb', line 34

#stroke_widthNumeric

Returns width for stroke in pixels

Parameters:

  • width (Numeric)

    for stroke in pixels

Returns:

  • (Numeric)

    width for stroke in pixels


# File 'lib/yeah/_platform/display.rb', line 38

#text_fontFont

Returns font for text

Parameters:

  • font (Font)

    for text

Returns:

  • (Font)

    font for text


# File 'lib/yeah/_platform/display.rb', line 42

#text_sizeInteger

Returns size for text in pixels

Parameters:

  • size (Integer)

    for text in pixels

Returns:

  • (Integer)

    size for text in pixels


# File 'lib/yeah/_platform/display.rb', line 46

#widthInteger

Returns width of display in pixels

Parameters:

  • width (Integer)

    to make display in pixels

Returns:

  • (Integer)

    width of display in pixels


# File 'lib/yeah/_platform/display.rb', line 18

Instance Method Details

#begin_shapenil

Begin new shape.

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 166

#clearnil

Clear display with fill color.

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 162

#color_at(x, y) ⇒ Color

Returns color of pixel

Parameters:

  • x (Integer)

    position of pixel to get color from

  • y (Integer)

    position of pixel to get color from

Returns:

  • (Color)

    color of pixel


# File 'lib/yeah/_platform/display.rb', line 50

#curve2_to(x, y, control1_x, control1_y, control2_x, control2_y) ⇒ nil

Trace curve with 2 control points to position as part of shape.

Parameters:

  • x (Numeric)

    position

  • y (Numeric)

    position

  • first (Numeric)

    control point x position

  • first (Numeric)

    control point y position

  • second (Numeric)

    control point x position

  • second (Numeric)

    control point y position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 194

#curve_to(x, y, control_x, control_y) ⇒ nil

Trace curve with a control point to position as part of shape.

Parameters:

  • x (Numeric)

    position

  • y (Numeric)

    position

  • control (Numeric)

    point x position

  • control (Numeric)

    point y position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 186

#draw_image(image, x, y) ⇒ nil

Draw an image at a position.

Examples:

Draw a duck within a game

display.image(Image['images/duck.png'], 80, 80)

Parameters:

  • image (Image)

    to draw

  • x (Numeric)

    position

  • y (Numeric)

    position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 212

#draw_image_cropped(image, x, y, crop_x, crop_y, crop_width, crop_height) ⇒ nil

Draw a cropped image at a position.

Parameters:

  • image (Image)

    to draw

  • x (Numeric)

    position

  • y (Numeric)

    position

  • x (Numeric)

    position of crop

  • y (Numeric)

    position of crop

  • width (Numeric)

    of crop

  • height (Numeric)

    of crop

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 221

#end_shapenil

End shape.

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 170

#fill_ellipse(center_x, center_y, radius_x, radius_y) ⇒ nil

Fill an ellipse at a center position and 2D radius.

Parameters:

  • center (Numeric)

    x position

  • center (Numeric)

    y position

  • radius (Numeric)

    on x axis

  • radius (Numeric)

    on y axis

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 154

#fill_rectangle(x, y, width, height) ⇒ nil

Fill a rectangle at a position and size.

Parameters:

  • x (Numeric)

    position

  • y (Numeric)

    position

  • width (Numeric)
  • height (Numeric)

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 138

#fill_shapenil

Fill previously made shape.

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 208

#fill_text(text, x, y) ⇒ nil

Fill text at a position.

Parameters:

  • text (String)

    value

  • x (Numeric)

    position

  • y (Numeric)

    position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 232

#line_to(x, y) ⇒ nil

Trace line to position as part of shape.

Parameters:

  • x (Numeric)

    position

  • y (Numeric)

    position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 180

#move_to(x, y) ⇒ nil

Move shape cursor to position.

Parameters:

  • x (Numeric)

    position

  • y (Numeric)

    position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 174

#popnil

Pop a transformation off the transformation stack and use it.

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 96

#pushnil

Push current transformation to the transformation stack.

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 92

#rotate(radians) ⇒ nil

Rotate the transformation in 2D by radians.

Parameters:

  • radians (Numeric)

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 87

#scale(x, y) ⇒ nil

Scale the transformation by a 2D multiplier.

Parameters:

  • x (Numeric)

    axis multiplier

  • y (Numeric)

    axis multiplier

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 71

#scale_x(x) ⇒ nil

Scale the transformation by a multiplier on the X axis.

Parameters:

  • x (Numeric)

    axis multiplier

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 77

#scale_y(y) ⇒ nil

Scale the transformation by a multiplier on the Y axis.

Parameters:

  • y (Numeric)

    axis multiplier

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 82

#stroke_curve(start_x, start_y, end_x, end_y, control_x, control_y) ⇒ nil

Stroke curve with a control point between two positions.

Parameters:

  • start (Numeric)

    x position

  • start (Numeric)

    y position

  • end (Numeric)

    x position

  • end (Numeric)

    y position

  • control (Numeric)

    point x position

  • control (Numeric)

    point y position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 108

#stroke_curve2(start_x, start_y, end_x, end_y, control1_x, control1_y, control2_x, control2_y) ⇒ nil

Stroke curve with 2 control points between two positions.

Parameters:

  • start (Numeric)

    x position

  • start (Numeric)

    y position

  • end (Numeric)

    x position

  • end (Numeric)

    y position

  • first (Numeric)

    control point x position

  • first (Numeric)

    control point y position

  • second (Numeric)

    control point x position

  • second (Numeric)

    control point y position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 118

#stroke_ellipse(center_x, center_y, radius_x, radius_y) ⇒ nil

Stroke an ellipse at a center position and 2D radius.

Parameters:

  • center (Numeric)

    x position

  • center (Numeric)

    y position

  • radius (Numeric)

    on x axis

  • radius (Numeric)

    on y axis

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 146

#stroke_line(start_x, start_y, end_x, end_y) ⇒ nil

Stroke a line between two positions.

Parameters:

  • start (Numeric)

    x position

  • start (Numeric)

    y position

  • end (Numeric)

    x position

  • end (Numeric)

    y position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 100

#stroke_rectangle(x, y, width, height) ⇒ nil

Stroke a rectangle at a position and size.

Parameters:

  • x (Numeric)

    position

  • y (Numeric)

    position

  • width (Numeric)
  • height (Numeric)

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 130

#stroke_shapenil

Stroke previously made shape.

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 204

#stroke_text(text, x, y) ⇒ nil

Stroke text at a position.

Parameters:

  • text (String)

    value

  • x (Numeric)

    position

  • y (Numeric)

    position

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 239

#translate(x, y) ⇒ nil

Move the transformation by a 2D displacement.

Parameters:

  • x (Numeric)

    axis displacement

  • y (Numeric)

    axis displacement

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 55

#translate_x(x) ⇒ nil

Move the transformation by a displacement on the X axis.

Parameters:

  • x (Numeric)

    axis displacement

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 61

#translate_y(y) ⇒ nil

Move the transformation by a displacement on the Y axis.

Parameters:

  • y (Numeric)

    axis displacement

Returns:

  • (nil)

# File 'lib/yeah/_platform/display.rb', line 66