This is a demo to use the Tessagon python tiling library in Inkscape, using the Simple Inkscape Scripting extension.
Relevant links:
See demo script (inkscape_simple_demo.py
) and screenshot of image (inkscape_simple.png
).
This is a demo to use the Tessagon python tiling library in Inkscape, using the Simple Inkscape Scripting extension.
Relevant links:
See demo script (inkscape_simple_demo.py
) and screenshot of image (inkscape_simple.png
).
import sys | |
# Replace with your tessagon source directory | |
sys.path.append('/home/cwant/gitwork/tessagon') | |
import tessagon | |
from tessagon.adaptors.list_adaptor import ListAdaptor | |
from tessagon import TessagonDiscovery | |
BLUES = ['#8080ff', '#80ffff', '#aaaaff'] | |
ORANGES = ['#ff6060', '#ffaa60', '#ffff80'] | |
def main(): | |
make_floret() | |
# make_octo() | |
# make_hex_tri() | |
# make_hex_square_tri() | |
# make_square_tri() | |
# make_square_tri2() | |
make_hex() | |
# make_weave() | |
make_rhombus() | |
# make_dodeca_tri() | |
# make_dissected_triangle() | |
# make_dissected_hex_quad() | |
# make_dissected_hex_tri() | |
# make_penta() | |
# make_penta2() | |
# make_zig_zag() | |
make_dodeca() | |
# make_brick() | |
# make_hex_big_tri() | |
make_pythag() | |
def make_floret(): | |
tessagon_cls = TessagonDiscovery.get_class('FloretTessagon') | |
def my_func(u,v): | |
return [10 + 90*u, 10 + 80*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 2, | |
'v_num': 3, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 2, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_hex(): | |
tessagon_cls = TessagonDiscovery.get_class('HexTessagon') | |
def my_func(u,v): | |
return [100 + 60*u, 10 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 13, | |
'v_num': 8, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 2, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, ORANGES) | |
def make_hex_tri(): | |
tessagon_cls = TessagonDiscovery.get_class('HexTriTessagon') | |
def my_func(u,v): | |
return [100 + 60*u, 10 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 13, | |
'v_num': 8, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, ORANGES) | |
def make_hex_square_tri(): | |
tessagon_cls = TessagonDiscovery.get_class('HexSquareTriTessagon') | |
def my_func(u,v): | |
return [100 + 60*u, 10 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 13, | |
'v_num': 8, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, ORANGES) | |
def make_square_tri(): | |
tessagon_cls = TessagonDiscovery.get_class('SquareTriTessagon') | |
def my_func(u,v): | |
return [100 + 60*u, 10 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 6, | |
'v_num': 6, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 2, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_square_tri2(): | |
tessagon_cls = TessagonDiscovery.get_class('SquareTri2Tessagon') | |
def my_func(u,v): | |
return [100 + 60*u, 10 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 10, | |
'v_num': 4, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_octo(): | |
tessagon_cls = TessagonDiscovery.get_class('OctoTessagon') | |
def my_func(u,v): | |
return [100 + 60*u, 10 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 8, | |
'v_num': 8, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, ORANGES) | |
def make_weave(): | |
tessagon_cls = TessagonDiscovery.get_class('WeaveTessagon') | |
def my_func(u,v): | |
return [70 + 60*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 4, | |
'v_num': 4, | |
'rot_factor': 1, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, ORANGES) | |
def make_rhombus(): | |
tessagon_cls = TessagonDiscovery.get_class('RhombusTessagon') | |
def my_func(u,v): | |
return [70 + 60*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 6, | |
'v_num': 4, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, ORANGES) | |
def make_dodeca(): | |
tessagon_cls = TessagonDiscovery.get_class('DodecaTessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 5, | |
'v_num': 4, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_dodeca_tri(): | |
tessagon_cls = TessagonDiscovery.get_class('DodecaTriTessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 3, | |
'v_num': 6, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_dissected_triangle(): | |
tessagon_cls = TessagonDiscovery.get_class('DissectedTriangleTessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 3, | |
'v_num': 6, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_dissected_hex_quad(): | |
tessagon_cls = TessagonDiscovery.get_class('DissectedHexQuadTessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 6, | |
'v_num': 6, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 2, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_dissected_hex_tri(): | |
tessagon_cls = TessagonDiscovery.get_class('DissectedHexTriTessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 3, | |
'v_num': 3, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_penta(): | |
tessagon_cls = TessagonDiscovery.get_class('PentaTessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 3, | |
'v_num': 4, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_penta2(): | |
tessagon_cls = TessagonDiscovery.get_class('Penta2Tessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 6, | |
'v_num': 4, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_zig_zag(): | |
tessagon_cls = TessagonDiscovery.get_class('ZigZagTessagon') | |
def my_func(u,v): | |
return [10 + 50*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 6, | |
'v_num': 6, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 1, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_pythag(): | |
tessagon_cls = TessagonDiscovery.get_class('PythagoreanTessagon') | |
def my_func(u,v): | |
return [130 + 60*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 4, | |
'v_num': 4, | |
'rot_factor': 1, | |
'color_pattern': 1, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_brick(): | |
tessagon_cls = TessagonDiscovery.get_class('BrickTessagon') | |
def my_func(u,v): | |
return [130 + 60*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 6, | |
'v_num': 6, | |
'rot_factor': 1, | |
'color_pattern': 1, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def make_hex_big_tri(): | |
tessagon_cls = TessagonDiscovery.get_class('HexBigTriTessagon') | |
def my_func(u,v): | |
return [130 + 60*u, 100 + 60*v, 0] | |
options = { | |
'function': my_func, | |
'u_range': [0.0, 1.0], | |
'v_range': [0.0, 1.0], | |
'u_num': 2, | |
'v_num': 3, | |
'u_cyclic': False, | |
'v_cyclic': False, | |
'color_pattern': 2, | |
'adaptor_class' : ListAdaptor | |
} | |
tessagon = tessagon_cls(**options) | |
out = tessagon.create_mesh() | |
render_output(out, BLUES) | |
def render_output(out, colors=None): | |
for f in range(len(out['face_list'])): | |
face = out['face_list'][f] | |
verts = [] | |
for v in face: | |
vert = out['vert_list'][v] | |
verts.append((vert[0], vert[1])) | |
if colors: | |
if type(colors) == list: | |
color = colors[out['color_list'][f]] | |
else: | |
color = colors | |
polygon(verts, | |
stroke='#444444', | |
stroke_width=1*pt, | |
fill=color).to_path(True) | |
else: | |
polygon(verts, | |
stroke='#444444', | |
stroke_width=1*pt).to_path(True) | |
main() |