Skip to content

Commit

Permalink
some doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBarker-NOAA committed Mar 12, 2024
1 parent b469c4a commit 0c4fd3b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 14 deletions.
9 changes: 6 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@
# built documents.
#
# The short X.Y version.
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '0.1.1'
# version = '0.1'
# # The full version, including alpha/beta/rc tags.
# release = '0.1.1'
import py_gd
version = py_gd.__version__
release = version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/draw_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
img = py_gd.Image(w, h)
img.clear('white')

print("Vertices of Star")
print(vertices)

for c, smooth in zip(centers, (0.25, 0.5, 0.75, 1.0)):
verts = vertices + c
img.draw_spline_polygon(verts,
Expand Down
Binary file modified docs/examples/my_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/examples/spline_star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/examples/ultra_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/examples/ultra_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

img.draw_line((1, 1), (400, 300), color='red', line_width=10)

img.save('my_image.png', 'png')
img.save('ultra_simple.png', 'png')

15 changes: 14 additions & 1 deletion docs/sample_scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,28 @@ A good way to learn to use py_gd is to check out a few example scripts.
Ultra Simple:
The very simplest example: :download:`ultra_simple.py <examples/ultra_simple.py>`

.. image:: examples/ultra_simple.png
:width: 200
:align: center


Mandlebrot:
A script to draw a Mandelbrot set by setting individual pixels:
:download:`examples/mandelbrot.py`

.. image:: examples/Mandelbrot.png
:width: 200
:width: 400
:align: center


moderate_complex.png

A pretty picture:
A script to draw a Mandelbrot set by setting individual pixels:
:download:`examples/moderate_complex.py`

.. image:: examples/moderate_complex.png
:width: 400
:align: center


23 changes: 14 additions & 9 deletions docs/splines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ Splines

Splines are curves that can smoothly fit arbitrary points.

``libgd`` does not natively include support for splines, py_gd includes this support natively. The spline calculations are written in Cython, so should be.
``libgd`` does not natively include support for splines, py_gd includes this support natively.

Spline support uses cubic bezier splines -- a cubic bezier spline is defined by two end points, and two control points -- the curve starts and ends at the end points, with the curve in between controlled by the location of the control points. They are smooth, and the entire curve lies within the convex hull of all four points.
.. warning: Splines are new and experimental to py_gd, and thus are poorly documented and may not work as expected. If you have issues, feedback is welcome on gitHub: https://github.com/NOAA-ORR-ERD/py_gd
The spline calculations are written in Cython, so should be fairly fast and efficient.

Cubic Bézier splines
--------------------

Spline support uses cubic Bézier splines -- a cubic bezier spline is defined by two end points and two control points -- the curve starts and ends at the end points, with the curve in between controlled by the location of the control points. They are smooth, and the entire curve lies within the convex hull of all four points.

Drawing Splines
---------------

In order to draw a spline with libgd, the spline is approximated by polyline, and then rendered as a polyline or polygon.
In order to draw a spline with libgd, the spline is approximated by polyline, and then rendered as a polyline or polygon. The spacing of the vertices should be such that the curve looks smooth.

Simple rendering of smoothed polygons is provided by the ``Image.draw_spline_polygon()`` method. It uses a method `developed by the AGG <https://agg.sourceforge.net/antigrain.com/research/bezier_interpolation/index.html>`_ library for determining control points that result in a smooth curve through all the vertices of a polygon. The smoothness can be adjusted as desired.
Simple rendering of smoothed polygons is provided by the ``Image.draw_spline_polygon()`` method.
It uses a method `developed by the AGG <https://agg.sourceforge.net/antigrain.com/research/bezier_interpolation/index.html>`_ library for determining control points that result in a smooth curve through all the vertices of a polygon. The smoothness can be adjusted as desired.

For example:
For examples, see:

To draw a star with a smooth spline:
:download:`draw_star.py <examples/draw_star.py>`

vertices = [(),
(),
()]

0 comments on commit 0c4fd3b

Please sign in to comment.