Various graphics algorithms (Tkinter, PIL, Javascript demos)
Python JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
img
.gitignore
3d.svg
BSP-tree-tkdemo.py
Bezier_curve-demo.svg
Cohen_Sutherland-demo.svg
Cohen_Sutherland.py
README.rst
Sutherland-Hodgman.py
aabb2D.py
cbezier-as-tkdemo.py
cbezier-cc-tkdemo.py
cbezier2D.py
elarc_aabb-demo.svg
elarc_aabb.py
fba.py
graham-tkdemo.py
graham.py
isconvex.py
jarvis.py
krzywe_beziera.py
poly_root.py
polyintersect-tkdemo.py
polyintersect.py
quickhull.py
segment-circle-intersection-test.svg
tk_ebbox-demo.py
tk_ebbox.py
tkes-demo.py
tkes.py
utils2D.py

README.rst

Graphics algorithms

Various graphics algorithms I learned. Python program using either Tkinter or Python Imaging Library (PIL), or Javascript embedded in SVG files.

There are following library modules used by demo applications:

  • utils2D.py --- different procedures work with segments, polygons etc.;
  • aabb2D.py --- axis-aligned bounding boxes;
  • isconvex.py --- procedures work with convex polygons;
  • cbezier2D.py --- procedures work with cubic Bezier curves;
  • convex hull algorithms: jarvis.py, graham.py and quickhull.py.

Tkinter events serializer

Most Tkinter-based scripts relie on tkes.py, it's my attempt to express interactive tasks in an imperative way. File tkes-demo.py is a simple drawing program which use this approach.

BSP tree demo (tkinter)

BSP-tree-tkdemo.py allows to edit a polygon and represents it as a BSP tree. Then a user may check if a point lies inside or outside the drawn polygon using the tree.

img/BSP-tree-tkdemo.png

Approximation of a Bezier curve (tkinter)

cbezier-as-tkdemo.py use different metrics to approximate a Bezier curve with polyline.

img/cbezier-as-tkdemo.png

Intersection of Bezier curves (tkinter)

cbezier-cc-tkdemo.py approximates curves with polylines, then check intersection of polylines.

img/cbezier-cc-tkdemo.png

Find a convex hull using Graham algorithm (tkinter)

graham-tkdemo.py calculates convex hull of point using Graham algorithm.

img/graham-tkdemo.png

Sutherland-Hodgman --- clip a polygon against a convex polygon (tkinter)

polyintersect-tkdemo.py allows to define two or more polygons and clip them using Sutherland-Hodgman algorithm.

img/polyintersect-tkdemo.png

Exact bounding box of Tkinter "smooth curve" (tkinter)

tk_ebbox-demo.py --- Tkinter uses Bezier splines to represent "smoothed curves", however its method bbox returns the bounding box of control points. This demo shows how to calculate an exact bounding box.

img/tk_ebbox-demo.png

Clipping segment using Cohen-Sutherland algorithm (JavaScript + SVG)

Cohen_Sutherland-demo.svg demonstrates the algorithm.

img/Cohen_Sutherland-demo.png

Bounding box of an elliptical arc (JavaScript + SVG)

elarc_aabb-demo.svg shows how to find the bounding-box of a rotated elliptical arc using basic math properties.

There's an article in Polish which describes the algorithm.

img/elarc_aabb-demo.png

Segment-circle intersection (JavaScript + SVG)

segment-circle-intersection-test.svg show an algorithm to check whether a segment crosses a circle or not.

Graph layout using force-based approach (Tkinter)

fba.py allows to select a few graphs and adjust algorithm's settings.

img/fba.png