Skip to content
nasser edited this page Feb 19, 2011 · 2 revisions

Graphics

Methods for drawing shapes and text, changng colors and other visual things. Meant to wrap the ofGraphics.h functions in openFrameworks.

rectangle

Draws a rectangle. The way the x and y arguments are interpreted depends on the current rectangle mode.

Syntax

rectangle x, y, w, h

  • x - The x coordinate of the center or corner, depending on rectangle_mode
  • y - The y coordinate of the center or corner, depending on rectangle_mode
  • w - The width of the rectangle
  • h - The height of the rectangle

Examples

# draw a small rectangle
rectangle 20, 20, 5, 10
# draw a centered rectangle
rectangle_mode :center
rectangle 10, 10, 50, 50

Returns nil

square

Draws a square.The way the x and y arguments are interpreted depends on the current rectangle mode.

Syntax

square x, y, s

  • x - The x coordinate
  • y - The y coordinate
  • s - The side of the square's sides

Examples

# draw a small square
square 100, 100, 5

Returns nil

triangle

Draws an equilateral, isosceles or scalene triangle.

Syntax

triangle x, y, r

  • x - x coordinate of the triangle's center
  • y - y coordinate of the triangle's center
  • r - The "radius" of the triangle. More specifically, the radius of the circle the triangle is inscribed in.

triangle x, y, r, a

  • x - x coordinate of the triangle's center
  • y - y coordinate of the triangle's center
  • r - The "radius" of the triangle. More specifically, the radius of the circle the triangle is inscribed in.
  • a - The size of the isosceles angle in radians

triangle x1, y1, x2, y2, x3, y3

  • x1 - x coordinate of the triangle's first point
  • y1 - y coordinate of the triangle's first point
  • x2 - x coordinate of the triangle's second point
  • y2 - y coordinate of the triangle's second point
  • x3 - x coordinate of the triangle's third point
  • y3 - y coordinate of the triangle's third point

Examples

No examples provided

Returns nil

circle

Draws a circle.

Syntax

circle x, y, r

  • x - the x coordinate of the circle's center
  • y - the y coordinate of the circle's center
  • r - the circle's radius

Examples

No examples provided

Returns nil

ellipse

Draws an ellipse.

Syntax

ellipse x, y, w, h

  • x - the x coordinate of the ellipse's center
  • y - the y coordinate of the ellipse's center
  • w - the width of the ellipse
  • h - the height of the ellipse

Examples

No examples provided

Returns nil

line

Draw a line between two points. The width of the line is determined by line_width methods.

Syntax

line x1, y1, x2, y2

  • x1 - the x coordinate of the first point
  • y1 - the y coordinate of the first point
  • x2 - the x coordinate of the second point
  • y2 - the y coordinate of the second point

Examples

# draw a triangle that fills the window
line 0, 0, width, 0
line 0, 0, width/2, height
line width/2, height, width, 0

Returns nil

rectangle_mode

Gets and sets the current rectangle mode. Calling without an argument returns the current mode, calling with a Symbol sets it. The rectangle mode controls how rectangles and squares are drawn. A rectangle mode of :center means squares and rectangles are centered at their x and y coordinates, while :corner places their top left corner at the their x and y coordinates. The default is :corner.

Syntax

rectangle_mode

rectangle_mode mode

  • mode - The new rectangle mode, either :corner or :center

Examples

size 200

color 128
rectangle_mode :center
square 100, 100, 75

color 240
rectangle_mode :corner
square 100, 100, 75

Returns :corner or :center if called without an argument, nothing otherwise

translate

Apply a translation transformation to the current matrix. Accepts 2D and 3D coordinates.

Syntax

translate x, y

  • x - The distance to move in x
  • y - The distance to move in y

translate x, y, z

  • x - The distance to move in x
  • y - The distance to move in y
  • z - The distance to move in z

Examples

matrix {
  # move origin to center of screen
  translate width/2, height/2
  circle 0, 0, 10
}

Returns nil

scale

Apply a scaling transformation to the current matrix. With one parameter, scales equally in all directions. With two or three parameters, scales in the given x, y, and z directions.

Syntax

scale s

  • s - The amount to scale by in all directions

scale x, y

  • x - The amount to scale by in x
  • y - The amount to scale by in y

scale x, y, z

  • x - The amount to scale by in x
  • y - The amount to scale by in y
  • z - The amount to scale by in z

Examples

No examples provided

Returns nil

smoothing

Gets and sets the smoothing setting. Smoothing determines whether shapes will be drawn antialiased or with jagged pixel edges. Smoothing slows drawing down, so it defaults to false.

Syntax

smoothing

smoothing state

  • state - Optional, true to enable smoothing or false to disable it

Examples

# draw jagged lines
smoothing false
line 10, 10, 13, 17
line 13, 17, 11, 25

# draw smooth circles
smoothing true
circle 15, 15, 5

Returns nil if called with an argument, otherwise current smoothing value as true or false

fill

Controls whether shapes are filled in or not

Syntax

fill state

  • state - true or false, enabling or disabling filling respectively

Examples

# draw outlines
fill false
circle 10, 10, 5

Returns nil

color

Sets the current color to an RGBA value

Syntax

color r, g, b, a

  • r - Amount of red
  • g - Amount of green
  • b - Amount of blue
  • a - Amount of alpha

color r, g, b

  • r - Amount of red
  • g - Amount of green
  • b - Amount of blue

color grey

  • grey - Level of grey

color grey, a

  • grey - Level of grey
  • a - Amount of alpha

Examples

# draws the french flag
color 0, 0, 200, 255
rectangle 0, 0, 50, 200

color 200, 200, 200, 255
rectangle 0, 50, 50, 200

color 200, 0, 0, 255
rectangle 0, 100, 50, 200

Returns nil

curve

Not documented yet

bezier

Not documented yet

push_matrix

Not documented yet

pop_matrix

Not documented yet

matrix

Not documented yet

rotate

Not documented yet

begin_shape

Not documented yet

end_shape

Not documented yet

shape

Not documented yet

vertex

Not documented yet

curve_vertex

Not documented yet

bezier_vertex

Not documented yet

circle_resolution

Not documented yet

curve_resolution

Not documented yet

alpha_blending

Not documented yet

arb_textures

Not documented yet

line_width

Not documented yet

background_auto

Not documented yet

background

Not documented yet


Generated 2011-02-19 16:44 against dc01dbc

39% of methods documented, 26% given examples.