Rename GP_Context -> GP_Pixmap
[gfxprim.git] / doc / gfx_python.txt
blobeda0951d80be5a2326e95382ad40015b76653dd2
1 Python GFX module
2 -----------------
4 The python binding maps mostly to the C API with the 'GP_' prefix stripped.
6 The gfx module adds methods to the gfx pixmap submodule.
8 NOTE: You may want to see the link:coordinate_system.html[coordinate system]
9       first.
11 Drawing functions
12 ~~~~~~~~~~~~~~~~~
14 All drawing functions takes a 'pixel' value (to describe color) which
15 link:core_python.html#Colors_and_Pixels[can be obtained], for a particular
16 pixel type (pixmap), from a RGB triplet.
18 All drawing functions are clipped. Drawing outside of a pixmap is no-op.
20 WARNING: Drawing functions takes strictly integer coordinates, make sure that
21          all divisions are integer divisions (i.e. use // instead of /) to
22          ensure portability with Python 3.X.
24 Line Based Primitives
25 ^^^^^^^^^^^^^^^^^^^^^
27 [source,python]
28 -------------------------------------------------------------------------------
29 import gfxprim.gfx as gfx
31      pixmap.gfx.HLine(x0, x1, y, pixel)
33 -------------------------------------------------------------------------------
35 Draws a horizontal line from 'x0' to 'x1' at 'y'.
37 [source,python]
38 -------------------------------------------------------------------------------
39 import gfxprim.gfx as gfx
41      pixmap.gfx.VLine(x, y0, y1, pixel)
43 -------------------------------------------------------------------------------
45 Draws a vertical line from 'y0' to 'y1' at 'x'.
48 [source,python]
49 -------------------------------------------------------------------------------
50 import gfxprim.gfx as gfx
52      pixmap.gfx.Line(x0, y0, x1, y1, pixel)
54 -------------------------------------------------------------------------------
56 Draws a line from x0, y0 to x1, y1.
58 [source,python]
59 -------------------------------------------------------------------------------
60 import gfxprim.gfx as gfx
62      pixmap.gfx.Rect(x0, y0, x1, y1, pixel)
64 -------------------------------------------------------------------------------
66 Draws a rectangle defined by two points.
68 [source,python]
69 -------------------------------------------------------------------------------
70 import gfxprim.gfx as gfx
72      pixmap.gfx.Triangle(x0, y0, x1, y1, x1, y2, pixel)
74 -------------------------------------------------------------------------------
76 Draws a triangle defined by three points.
78 [source,python]
79 -------------------------------------------------------------------------------
80 import gfxprim.gfx as gfx
82      pixmap.gfx.Tetragon(x0, y0, x1, y1, x1, y2, x3, y3, pixel)
84 -------------------------------------------------------------------------------
86 Draws a tetragon defined by four points.
88 [source,python]
89 -------------------------------------------------------------------------------
90 import gfxprim.gfx as gfx
92      pixmap.gfx.Polygon([x0, y0, x1, y1, ...], pixel)
94      pixmap.gfx.Polygon([(x0, y0), (x1, y1), ...], pixel)
96 -------------------------------------------------------------------------------
98 Draws a polygon defined by points, points can be either flat list of 2N
99 integers or list of N tuples.
101 [source,python]
102 -------------------------------------------------------------------------------
103 import gfxprim.gfx as gfx
105      pixmap.gfx.Circle(x, y, r, pixel)
107 -------------------------------------------------------------------------------
109 Draws a circle.
111 [source,python]
112 -------------------------------------------------------------------------------
113 import gfxprim.gfx as gfx
115      pixmap.gfx.Ellipse(x, y, a, b, pixel)
117 -------------------------------------------------------------------------------
119 Draws an ellipse.
121 [source,python]
122 -------------------------------------------------------------------------------
123 import gfxprim.gfx as gfx
125      pixmap.gfx.Ring(x, y, r1, r2, pixel)
127 -------------------------------------------------------------------------------
129 Draws a ring.
131 Filled Primitives
132 ^^^^^^^^^^^^^^^^^
134 [source,python]
135 -------------------------------------------------------------------------------
136 import gfxprim.gfx as gfx
138     pixmap.gfx.Fill(pixel)
140 -------------------------------------------------------------------------------
142 Fills pixmap with particular 'pixel' value.
144 [source,python]
145 -------------------------------------------------------------------------------
146 import gfxprim.gfx as gfx
148      pixmap.gfx.FillRect(x0, y0, x1, y1, pixel)
150 -------------------------------------------------------------------------------
152 Fills a rectangle defined by two points.
154 [source,python]
155 -------------------------------------------------------------------------------
156 import gfxprim.gfx as gfx
158      pixmap.gfx.FillTriangle(x0, y0, x1, y1, x1, y2, pixel)
160 -------------------------------------------------------------------------------
162 Draws a filled triangle defined by three points.
164 [source,python]
165 -------------------------------------------------------------------------------
166 import gfxprim.gfx as gfx
168      pixmap.gfx.FillTetragon(x0, y0, x1, y1, x1, y2, x3, y3, pixel)
170 -------------------------------------------------------------------------------
172 Draws a filled tetragon defined by four points.
174 [source,python]
175 -------------------------------------------------------------------------------
176 import gfxprim.gfx as gfx
178      pixmap.gfx.FillPolygon([x0, y0, x1, y1, ...], pixel)
180      pixmap.gfx.FillPolygon([(x0, y0), (x1, y1), ...], pixel)
182 -------------------------------------------------------------------------------
184 Fills a polygon defined by points, points can be either flat list of 2N
185 integers or list of N tuples.
187 [source,python]
188 -------------------------------------------------------------------------------
189 import gfxprim.gfx as gfx
191      pixmap.gfx.FillCircle(x, y, r, pixel)
193 -------------------------------------------------------------------------------
195 Fills a circle.
197 [source,python]
198 -------------------------------------------------------------------------------
199 import gfxprim.gfx as gfx
201      pixmap.gfx.FillEllipse(x, y, a, b, pixel)
203 -------------------------------------------------------------------------------
205 Fills an ellipse.
207 [source,python]
208 -------------------------------------------------------------------------------
209 import gfxprim.gfx as gfx
211      pixmap.gfx.FillRing(x, y, r1, r2, pixel)
213 -------------------------------------------------------------------------------
215 Fills a ring, i.e. area enclosed between two circles.
217 TIP: See gfx module link:example_py_gfx.html[example].