This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via eef84fa42d26341f4dd66b35672957fa35e23b8e (commit) from 93aea6a4e0d920f60743fdb89fa102595d6b0d76 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/eef84fa42d26341f4dd66b35672957fa35e23...
commit eef84fa42d26341f4dd66b35672957fa35e23b8e Author: Cyril Hrubis metan@ucw.cz Date: Sat Mar 23 17:22:57 2013 +0100
docs,demos: Add python gfx demo, continue docs.
diff --git a/demos/py_simple/gfx.py b/demos/py_simple/gfx.py new file mode 100755 index 0000000..9c1ce13 --- /dev/null +++ b/demos/py_simple/gfx.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python + +import sys + +import gfxprim.core as core +import gfxprim.gfx as gfx +import gfxprim.backends as backends +import gfxprim.input as input + +def fill(bk): + color = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bk.context.gfx.Fill(color) + bk.Flip() + +def hline(bk): + fg = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bg = bk.context.RGBToPixel(0, 0, 0); + + bk.context.gfx.Fill(bg) + for i in range(0, bk.context.h, 10): + bk.context.gfx.HLine(0, bk.context.w, i, fg) + bk.Flip() + +def vline(bk): + fg = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bg = bk.context.RGBToPixel(0, 0, 0); + + bk.context.gfx.Fill(bg) + + for i in range(0, bk.context.w, 10): + bk.context.gfx.VLine(i, 0, bk.context.h, fg) + + bk.Flip() + +def line(bk): + fg = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bg = bk.context.RGBToPixel(0, 0, 0); + + bk.context.gfx.Fill(bg) + + for i in range(0, 2 * max(bk.context.w, bk.context.h), 13): + bk.context.gfx.Line(0, i, i, 0, fg) + + bk.Flip() + +def rect(bk): + fg = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bg = bk.context.RGBToPixel(0, 0, 0); + + bk.context.gfx.Fill(bg) + + for i in range(10, 130, 10): + bk.context.gfx.Rect(i, i, bk.context.w - i, bk.context.h - i, fg) + + bk.Flip() + +def triangle(bk): + fg = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bg = bk.context.RGBToPixel(0, 0, 0); + + bk.context.gfx.Fill(bg) + + w = bk.context.w + h = bk.context.h + + for i in range(10, 90, 10): + bk.context.gfx.Triangle(2*i, i, w - 2*i, i, w//2, h - 2*i, fg) + + bk.Flip() + +def tetragon(bk): + fg = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bg = bk.context.RGBToPixel(0, 0, 0); + + bk.context.gfx.Fill(bg) + + w = bk.context.w + h = bk.context.h + + for i in range(10, 70, 10): + bk.context.gfx.Tetragon(i, i, w-2*i, i, w-i, h-i, 2*i, h-i, fg) + + bk.Flip() + +def polygon(bk): + fg = bk.context.RGBToPixel(0xee, 0xee, 0xee) + bg = bk.context.RGBToPixel(0, 0, 0); + + bk.context.gfx.Fill(bg) + + w = bk.context.w + h = bk.context.h + + polygon = [(10, 10), (10, (h-10)//3), ((w-10)//3, (h-10)//2), + (10, 2*(h-10)//3), (10, h-10), ((w-10)//3, h-10), + ((w-10)//2, 2*(h-10)//3), (2*(w-10)//3, h-10), + (w-10, h-10), (w-10, 2*(h-10)//3), (2*(w-10)//3, (h-10)//2), + (w-10, (h-10)//3), (w-10, 10), (2*(w-10)//3, 10), + ((w-10)//2, (h-10)//3), ((w-10)//3, 10)] + + bk.context.gfx.Polygon(polygon, fg) + + bk.Flip() + +def next(bk, i): + + if (i == 0): + fill(bk) + + if (i == 1): + hline(bk) + + if (i == 2): + vline(bk) + + if (i == 3): + line(bk) + + if (i == 4): + rect(bk) + + if (i == 5): + triangle(bk) + + if (i == 6): + tetragon(bk) + + if (i == 7): + polygon(bk) + + i = i + 1; + + if (i >= 8): + i = 0 + + return i + +def main(): + print(dir(gfx)) + + # Create X11 window + bk = backends.BackendX11Init(None, 0, 0, 320, 240, "GFX demo", 0) + assert(bk) + print(dir(bk.context.gfx)) + + bk.Flip() + + i = 0 + + # Event loop + while True: + ev = bk.Wait() + + input.EventDump(ev) + + if (ev.type == input.EV_KEY and ev.code == input.EV_KEY_DOWN): + + if (ev.val.val == input.KEY_ESC): + sys.exit(0) + + i = next(bk, i) + + if (ev.type == input.EV_SYS): + if (ev.code == input.EV_SYS_QUIT): + sys.exit(0) + +if __name__ == '__main__': + main() diff --git a/doc/example_py_gfx.txt b/doc/example_py_gfx.txt new file mode 100644 index 0000000..2c8854d --- /dev/null +++ b/doc/example_py_gfx.txt @@ -0,0 +1,8 @@ +Gfx +--- +.A simple program to show how to use gfx + +[source,python] +------------------------------------------------------------------ +include::../demos/py_simple/gfx.py[] +------------------------------------------------------------------ diff --git a/doc/gfx_python.txt b/doc/gfx_python.txt index 28f8899..3644358 100644 --- a/doc/gfx_python.txt +++ b/doc/gfx_python.txt @@ -17,6 +17,10 @@ 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. + [source,python] ------------------------------------------------------------------------------- import gfxprim.gfx as gfx @@ -32,6 +36,7 @@ Fills context with particualr 'pixel' value. import gfxprim.gfx as gfx
context.gfx.HLine(x0, x1, y, pixel) + -------------------------------------------------------------------------------
Draws a horizontal line from 'x0' to 'x1' at 'y'. @@ -41,8 +46,64 @@ 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'.
+[source,python] +------------------------------------------------------------------------------- +import gfxprim.gfx as gfx + + context.gfx.Line(x0, y0, x1, y1, pixel) + +------------------------------------------------------------------------------- + +Draws a line from x0, y0 to x1, y1. + +[source,python] +------------------------------------------------------------------------------- +import gfxprim.gfx as gfx + + context.gfx.Rect(x0, y0, x1, y1, pixel) + +------------------------------------------------------------------------------- + +Draws a rectangle defined by two points. + +[source,python] +------------------------------------------------------------------------------- +import gfxprim.gfx as gfx + + context.gfx.Triangle(x0, y0, x1, y1, x1, y2, pixel) + +------------------------------------------------------------------------------- + +Draws a triangle defined by three points. + +[source,python] +------------------------------------------------------------------------------- +import gfxprim.gfx as gfx + + context.gfx.Tetragon(x0, y0, x1, y1, x1, y2, x3, y3, pixel) + +------------------------------------------------------------------------------- + +Draws a tetragon defined by four points. + +[source,python] +------------------------------------------------------------------------------- +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. + + +TIP: See gfx module link:example_py_gfx.html[example].
-----------------------------------------------------------------------
Summary of changes: demos/py_simple/gfx.py | 168 ++++++++++++++++++++ ...example_py_showimage.txt => example_py_gfx.txt} | 8 +- doc/gfx_python.txt | 61 +++++++ 3 files changed, 233 insertions(+), 4 deletions(-) create mode 100755 demos/py_simple/gfx.py copy doc/{example_py_showimage.txt => example_py_gfx.txt} (59%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.