A Powerful Tool For Creating Geometric Pattern SVGs
from js import getPolygonSize getPolygonSize()

Try Out Geometry Generator

Make a triangle or other basic polygon by clicking in the code box below and pressing shift + enter

# This is a Python terminal! It has access to all the classes and methods from my geometry_generator # Press SHIFT + ENTER to run all the code in each box clear_drawing() # Or you can press the Clear Drawing button # Add a polygon triangle = Polygon(num_points=3, radius=100, drawing=drawing_global) # Try changing the number of points (sides) # Call the draw method of the polygon to add it to the drawing triangle.draw() render_drawing_html() # Or you can press the Render Drawing button resizeSVG() # Or you can press the Auto Resize button

Make a geometric grid of polygons with an algorithmic morph

clear_drawing() hexagon = Polygon(num_points=6, radius=10, drawing=drawing_global) # Try changing the radius hexGrid = GridIsometric(spacing=20, polygon=hexagon, num_x=15, num_y=20, drawing=drawing_global) # Try changing the spacing # Use the modify_polygons method with circle_morph function to make the polygons get smaller as you get further from the center hexGrid.modify_polygons(circle_morph, magnitude = 0.75, decrease_out = True) # Call the draw_polygons method of the grid to add it to the drawing hexGrid.draw_polygons() render_drawing_html() resizeSVG()

Make a fractal

clear_drawing() # Add a polygon sides = 5 # Try changing the number of sides pentagon = Polygon(num_points=sides, radius=150, drawing=drawing_global) # Call the draw_fractal method of the polygon to add a fractal of it the drawing pentagon.draw_fractal(shrinkage=.4, depth=4, rotate=0) # try changing rotate angle, (hint try 360/(2*sides)) render_drawing_html() resizeSVG()
Note: The code above was integrated using a brand new tool called PyScript which allows Python to run in a browser alongside JavaScript and even interact with JavaScript objects and vice-versa. This was challenging since the Geometry Generator was not initially intended to show the patterns in a browswer but rather to create a stand-alone SVG file. So, I had to implement an interface and write a lot of custom functions that calculate the maximum and minimum X and Y coordinates of all the polygons so I can automatically adjust the size of the window in the web page, and move all of the polygons into the center so they all fit. You will notice no matter how large or small you make the patterns, they will fit perfectly into the SVG window in the web page.

I created Geometry Generator because I have always been enamored with the beauty of geometric patterns like in art such as M.C. Escher, like those found on mosques, and like those found in nature like on diatoms. In junior high, geometry class was what initially got me to fall in love with mathematics and science because the visual aspect of it allowed me to connect to the material more deeply. Geometry can act as a sort of bridge

I also make laser-engraved and 3D printed crafts and often find myself needing such geometric patterns to integrate into them, and I found that there was a lack of available patterns online. I had the thought that vector graphics are basically just code dictating where to draw points and lines, and that I could likely write a program to generate beautiful and intriguing designs

Geometry Generator integrates with SVGWrite which is a Python library which can create SVG files (vector graphics) but it doesn't really have any tools for creating patterns. For this, I created many custom classes to create powerful tools for creating complex designs.

The first of these classes and the foundation of the program is the Polygon class. This allows me to create many polygon objects, each with a different shape, and every one keeps track of all of its points and its center. The polygon class also has methods like draw, which draws itself into the actual SVG file, rotate which lets you rotate it to a certain angle, and draw_fractal which is a robust recursive function for making a fractal of the polygon that lets the user define the amount of size change between fractal layers and even an angle change, allowing for twisted fractals!

The next class is the Grid class which generates the majority of patterns by creating a grid of Polygon objects. Each Grid object has all of the information about the points in the grid, and holds all the polygon objects at each point. It also offers many methods for modifying those polygons like modify_polygons which lets you pass in a callback function to be run on every polygon in the grid. This allows for complex patterns like gradients of polygon size, angle, outline and more

On top of these two classes, there are more like GridIsometric which inherits from Grid but is an isometric (triangular) grid, and there is also the Mandala class which creates a ring of equidistant points and polygons which can be used to create beautiful radial motifs like you would see in a mandala

I have many more features planned like an Edge Mandala which creates polygons on all of the edges of a seed polygon then repeats to make intricate expanding lattices like you might see in a mosque, and a Spiral Grid which can create spirals of all kinds including golden and silver spirals

Output from Python terminals via PyScript