Add documentation

This commit is contained in:
Fomys 2019-02-25 20:07:05 +01:00
parent 388ebdb2b9
commit 8dd47da162
7 changed files with 593 additions and 0 deletions

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

35
make.bat Normal file
View File

@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
:end
popd

12
source/Pipfile Normal file
View File

@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
pillow = "*"
[dev-packages]
[requires]
python_version = "3.6"

312
source/betterTurtle.py Normal file
View File

@ -0,0 +1,312 @@
# -*- coding: utf-8 -*-
"""
A new turtle which is faster.
>>> t = Turtle()
>>> t.init()
>>> t.set_position((0, 0))
>>> t.fractal.outline(6, 2, 5)
.. autoclass:: Figures
:members:
:undoc-members:
.. autoclass:: Turtle
:members:
:undoc-members:
"""
import math
import time
from PIL import Image, ImageDraw
class Figures:
"""A lot of function to create some well-know shapes
:param master: turtle2 to use for draw
:type master: Turtle
:returns: Nothing
:rtype: None"""
def __init__(self, master):
self.canvas = master
def _outline_trace(self, number_of_iterations, length, number_of_sides):
"""Internal function to draw outline of a recursive shape
:param number_of_iterations: Number of iteration used to draw
:param length: Size of a single side
:param number_of_sides: Number of sides of the initial shape
:type number_of_iterations: int
:type length: int
:type number_of_sides: int
:returns: Nothing
:rtype: None"""
if number_of_iterations == 0:
self.canvas.forward(length)
else:
self._outline_trace(number_of_iterations - 1, length, number_of_sides)
self.canvas.right(360. / number_of_sides)
self._outline_trace(number_of_iterations - 1, length, number_of_sides)
self.canvas.right(-360. / number_of_sides)
self._outline_trace(number_of_iterations - 1, length, number_of_sides)
self.canvas.right(-360. / number_of_sides)
self._outline_trace(number_of_iterations - 1, length, number_of_sides)
self.canvas.right(360. / number_of_sides)
self._outline_trace(number_of_iterations - 1, length, number_of_sides)
def regular_polygon(self, number_of_sides, length):
"""Draw a regular polygon
:param number_of_sides: Number of sides of the polygon
:param length: Length of a side
:type number_of_sides: int
:type length: int
:returns: Nothing
:rtype: None"""
angle = 360. / number_of_sides
for i in range(number_of_sides):
self.canvas.forward(length)
self.canvas.right(angle)
def poly_repeat(self, length, number_of_side, density):
"""Draw a repetition of a regular polygon
:param length: Length of a side
:param number_of_side: Regular polygon's side number
:param density: quantity of polygon
:type length: int
:type number_of_side: int
:type density: int
:returns: Nothing
:rtype: None"""
angle = 360. / density
for i in range(density):
self.regular_polygon(number_of_side, length)
self.canvas.right(angle)
def outline(self, number_of_iteration, length, number_of_sides):
"""Draw outline of a recursive shape
:param number_of_iteration: Number of iteration used to draw
:param length: Length of a single side
:param number_of_sides: Number of sides of the initial shape
:type number_of_iteration: int
:type length: int
:type number_of_sides: int
:returns: Nothing
:rtype: None"""
for i in range(number_of_sides):
self._outline_trace(number_of_iteration, length, number_of_sides)
self.canvas.right(360. / number_of_sides)
def tree(self, length, angles, factor=1.5, min_size=5):
"""Draw a tree recursively
:param length: Length of the root of the tree
:param angles: List of angles for branch
:param factor: Reduce factor for next branch
:param min_size: Minimal length of a branch
:type length: int
:type angles: list
:type factor: float
:type min_size: float
:returns: Nothing
:rtype: None"""
if length < min_size:
return ""
else:
self.canvas._state["color"] = (int(length), int(length), int(length))
for angle in angles:
pos = self.canvas.get_position()
base_angle = self.canvas.get_angle()
self.canvas.right(angle)
self.canvas.forward(length)
self._tree(length / factor, angles, factor=factor, min_size=min_size)
self.canvas.set_position(pos)
self.canvas.set_angle(base_angle)
def dragon(self, length, number_of_iteration, angle=1):
"""Draw the dragon curve
:param angle: Start angle
:param length: Length of a side
:param number_of_iteration: Number of iteration for the curve
:type length: int
:type number_of_iteration: int
:returns: Nothing
:rtype: None"""
if number_of_iteration == 0:
self.canvas.forward(length)
else:
self.dragon(length, number_of_iteration - 1, 1)
self.canvas.left(angle * 90)
self.dragon(length, number_of_iteration - 1, -1)
def power(self, length, power, base=1.5):
k = base
list_powers = []
for i in range(power):
k = 10 * (k * 0.15 - int(k * 0.15))
n = int((k - int(k)) * 10)
list_powers.append(n)
for i in list_powers:
angle = 36 * i
self.canvas.right(angle)
self.canvas.forward(length)
def turning_tree(self, length, angles):
while True:
self.tree(length, angles)
time.sleep(0.1)
i = 0
for _ in angles:
angles[i] += 1
i += 1
def _koch_curve(self, length):
self.canvas.forward(length)
self.canvas.left(60)
self.canvas.forward(length)
self.canvas.right(120)
self.canvas.forward(length)
self.canvas.left(60)
self.canvas.forward(length)
def koch_curve(self, length, number_of_iteration):
if number_of_iteration > 0:
self.koch_curve(length / 3., number_of_iteration - 1)
self.canvas.left(60)
self.koch_curve(length / 3., number_of_iteration - 1)
self.canvas.right(120)
self.koch_curve(length / 3., number_of_iteration - 1)
self.canvas.left(60)
self.koch_curve(length / 3., number_of_iteration - 1)
else:
self._koch_curve(length)
class Turtle:
@staticmethod
def _calc_center(size):
return size[0] / 2, size[1] / 2
def _forward(self, distance):
AB = (distance * math.cos(math.radians(self._state.get("angle")))) + self._state.get("coordinate_x")
AC = (distance * math.sin(math.radians(self._state.get("angle")))) + self._state.get("coordinate_y")
self._forward_image(distance)
self._set_coordinates((AB, AC))
def _forward_image(self, distance):
AB = (distance * math.cos(math.radians(self._state.get("angle")))) + self._state.get("coordinate_x")
AC = (distance * math.sin(math.radians(self._state.get("angle")))) + self._state.get("coordinate_y")
self.draw.line((self.get_position('x') * self.resolution, self.get_position('y') * self.resolution,
AB * self.resolution, AC * self.resolution), fill=self._state.get("colour"))
def _turn(self, angle):
self._set_angle(self._state.get("angle") + angle)
def _set_angle(self, angle):
self._state["angle"] = angle
while self._state.get("angle") >= 360:
self._state["angle"] = self._state.get("angle") - 360
def _clear(self):
pass
def _clear_img(self):
self.image = Image.new(
'1', (self._config.get("size")), (255, 255, 255))
self.draw = ImageDraw.Draw(self.image)
def __init__(self, titre="Turtle", size=(
400, 400), resolution=10):
self._config = {"titre": titre,
"size": size,
"size_IMG": (size[0] * resolution, size[1] * resolution),
"center": self._calc_center(size),
}
self._state = {"angle": 0,
"coordinate_x": self._config.get("center")[0],
"coordinate_y": self._config.get("center")[1],
"colour": (0, 0, 0),
}
self.fractal = Figures(self)
self.image = Image.new(
'RGB',
(self._config.get("size_IMG")),
(255,
255,
255))
self.draw = ImageDraw.Draw(self.image)
self.resolution = resolution
def forward(self, distance):
self._forward(distance)
def backward(self, distance):
self._forward(-distance)
if self.sauvegarde:
self._forward_image(-distance)
def right(self, angle):
self._turn(angle)
def left(self, angle):
self._turn(-angle)
def goto(self, coordinates):
self._set_coordinates(coordinates)
self.draw.line(coordinates)
def _set_coordinates(self, coordinates):
self._state["coordinate_x"] = coordinates[0]
self._state["coordinate_y"] = coordinates[1]
def clear(self):
self._clear()
def set_position(self, coordinates):
self._set_coordinates(coordinates)
def get_position(self, type_coord=''):
if type_coord == 'x':
return self._state.get("coordinate_x")
elif type_coord == "y":
return self._state.get("coordinate_y")
return self._state.get("coordinate_x"), self._state.get("coordinate_y")
def set_angle(self, angle):
self._set_angle(angle)
def get_angle(self):
return self._state.get("angle")
def get_state(self):
text = ""
for i in self._state.items():
text = text + "\n" + str(i[0]) + ":" + str(i[1])
return text
def save(self, path, type_img=None):
self.image.save(path, type_img)
if __name__ == "__main__":
t = Turtle()
t.set_position((0, 0))
t.fractal.outline(6, 2, 5)
t.save("test.bmp")

186
source/conf.py Normal file
View File

@ -0,0 +1,186 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'fractal'
copyright = '2019, Suwako TheDevKiller Fomys'
author = 'Suwako TheDevKiller Fomys'
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.0.1'
# -- General configuration ---------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'fractaldoc'
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'fractal.tex', 'fractal Documentation',
'Suwako TheDevKiller Fomys', 'manual'),
]
# -- Options for manual page output ------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'fractal', 'fractal Documentation',
[author], 1)
]
# -- Options for Texinfo output ----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'fractal', 'fractal Documentation',
author, 'fractal', 'One line description of project.',
'Miscellaneous'),
]
# -- Options for Epub output -------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = project
# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''
# A unique identification for the text.
#
# epub_uid = ''
# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
# -- Extension configuration -------------------------------------------------
# -- Options for todo extension ----------------------------------------------
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

8
source/documentation.rst Normal file
View File

@ -0,0 +1,8 @@
.. function documentation
function documentation
======================
.. automodule:: betterTurtle
:members:
:undoc-members:

21
source/index.rst Normal file
View File

@ -0,0 +1,21 @@
.. fractal documentation master file, created by
sphinx-quickstart on Mon Feb 25 19:55:50 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to fractal's documentation!
===================================
.. toctree::
:maxdepth: 2
:caption: Contents:
documentation
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`