Navigation C API Pages Python bindings Applications

Python GFX module

The python binding maps mostly to the C API with the GP_ prefix stripped.

The gfx module adds methods to the gfx context submodule.

Note You may want to see the coordinate system first.

Drawing functions

All drawing functions takes a pixel value (to describe color) which can be obtained, for a particular pixel type (context), from a RGB triplet.

All drawing functions are clipped. Drawing outside of a context is no-op.

Warning Drawing functions takes strictly integer coordinates, make sure that all divisions are integer divisions (i.e. use // instead of /) to ensure portability with Python 3.X.

Line Based Primitives

import gfxprim.gfx as gfx

     context.gfx.HLine(x0, x1, y, pixel)

Draws a horizontal line from x0 to x1 at y.

import gfxprim.gfx as gfx

     context.gfx.VLine(x, y0, y1, pixel)

Draws a vertical line from y0 to y1 at x.

import gfxprim.gfx as gfx

     context.gfx.Line(x0, y0, x1, y1, pixel)

Draws a line from x0, y0 to x1, y1.

import gfxprim.gfx as gfx

     context.gfx.Rect(x0, y0, x1, y1, pixel)

Draws a rectangle defined by two points.

import gfxprim.gfx as gfx

     context.gfx.Triangle(x0, y0, x1, y1, x1, y2, pixel)

Draws a triangle defined by three points.

import gfxprim.gfx as gfx

     context.gfx.Tetragon(x0, y0, x1, y1, x1, y2, x3, y3, pixel)

Draws a tetragon defined by four points.

import gfxprim.gfx as gfx

     context.gfx.Polygon([x0, y0, x1, y1, ...], pixel)

     context.gfx.Polygon([(x0, y0), (x1, y1), ...], pixel)

Draws a polygon defined by points, points can be either flat list of 2N integers or list of N tuples.

import gfxprim.gfx as gfx

     context.gfx.Circle(x, y, r, pixel)

Draws a circle.

import gfxprim.gfx as gfx

     context.gfx.Ellipse(x, y, a, b, pixel)

Draws an ellipse.

import gfxprim.gfx as gfx

     context.gfx.Ring(x, y, r1, r2, pixel)

Draws a ring.

Filled Primitives

import gfxprim.gfx as gfx

    context.gfx.Fill(pixel)

Fills context with particular pixel value.

import gfxprim.gfx as gfx

     context.gfx.FillRect(x0, y0, x1, y1, pixel)

Fills a rectangle defined by two points.

import gfxprim.gfx as gfx

     context.gfx.FillTriangle(x0, y0, x1, y1, x1, y2, pixel)

Draws a filled triangle defined by three points.

import gfxprim.gfx as gfx

     context.gfx.FillTetragon(x0, y0, x1, y1, x1, y2, x3, y3, pixel)

Draws a filled tetragon defined by four points.

import gfxprim.gfx as gfx

     context.gfx.FillPolygon([x0, y0, x1, y1, ...], pixel)

     context.gfx.FillPolygon([(x0, y0), (x1, y1), ...], pixel)

Fills a polygon defined by points, points can be either flat list of 2N integers or list of N tuples.

import gfxprim.gfx as gfx

     context.gfx.FillCircle(x, y, r, pixel)

Fills a circle.

import gfxprim.gfx as gfx

     context.gfx.FillEllipse(x, y, a, b, pixel)

Fills an ellipse.

import gfxprim.gfx as gfx

     context.gfx.FillRing(x, y, r1, r2, pixel)

Fills a ring, i.e. area enclosed between two circles.

Tip See gfx module example.