Builds recursive calls tree and saves it as an SVG file.
Project description
Recursion tree
Transforms recursive functions into graphical form.
Installation:
pip install RecursionTree
Usage:
import random
from RecursionTree import recursion_tree
scientific_style = {
'draw_boundary': False,
'color_background': 'white',
'color_num_background': 'white',
'color_node_body': 'white',
'color_node_stroke': 'black',
'color_text': 'black',
'color_connection': 'black',
'node_stroke_bezier': False
}
@recursion_tree(scientific_style)
def fibo(x: int) -> int:
return 1 if x in [1, 2] else fibo(x=x - 1) + fibo(x=x - 2)
# No parameters mean default settings
@recursion_tree
def random_tree(x: int) -> str:
if x == 0:
return 'Dead end'
for _ in range(random.randint(1, x)):
random_tree(x=x - 1)
if __name__ == '__main__':
# Run out target function and save results
fibo(x=5)
random_tree(x=4)
Just add the 'recursion_tree' decorator to any recursive function. The result will be automatically saved as an SVG file. Additional settings might be achieved via settings.py or by passing a dictionary to the decorator.
Default style:
Scientific style:
Default style with boundaries:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
RecursionTree-2.0.tar.gz
(6.8 kB
view hashes)
Built Distribution
Close
Hashes for RecursionTree-2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70b766557cde68de48669a2792b27b0595fa5133aa9d25585aa0096e9def72fb |
|
MD5 | fbd1573c23b855e58420c24ee5561681 |
|
BLAKE2b-256 | 2e75340dcebe075c9a66757fd62ee76ff7308b18a6d52b75ada6b638168e0f27 |