When I was in my teens, I used to have a big box of Lego. Based on thousands of simple Lego pieces, I built my world of knights, wizards, princesses,explorers, pirates and monsters.
Decades later, as a computer science student, I am obsessed with the question: Would it be possible to use Python to create a set of Lego pieces, based on which people could easily create complex and beautiful patterns.
I'd like to present my answer so far.
No matter how splendid the Lego world is, it is build from very simple Lego pieces.
Likewise, our Math-Lego is based on three simple Math-Lego pieces: Constant Bender, Linear Bender and Sin Bender. The shape of each piece is restricted by a different type of derivative. By combining these simple Math-Lego pieces together, you may create complex and beautiful patterns on a Matplotlib "paper".
Constant Bender let you create a curved line with a constant curvature. You may adjust the curvature to create a more curly line.
The curvature of a Sin Bender is a sinusoid. I.e. the curvature gradually increases to reach a peak, and then gradually falls back. It is usually applied to create a sharp curve.
The curvature of a Linear Bender is a linear function, (i.e. the curvature gradually changes from one constant value to another constant value) It could also be applied to gradually change the curvature of a line. (As shown in the above, the red line transforms the straight blue line into a curly yellow line)
You may customize your own Math-Lego pieces by tuning its length, width, curvature and color.
Please refer to code for details.
By putting your customized Math-Lego pieces together, you could create images as such
In addition to simple Math-Lego pieces, we also offer some advanced Math-Lego pieces. (For now only one, as the semester is about to start and the author has other works to do.) The advanced Math-Lego pieces are made from simple Math-Lego pieces, but encapsulated in a way that is easy to be called by users.
As shown above, the sunshine Math-Lego piece is made from a constant bender and a linear bender.
If combining multiple sunshine Math-Lego pieces in a circular manner, we could get the following pattern:
You may also write other advanced Math-Lego pieces by yourself!
Try exploring other ways to use the Math-Lego on more challenging patterns!
Here is one of my explorations!
This is an attampt to mimic the Chinese calligraphy of the Chinese character "晴" (which stands for "sunny")
Here is the a calligraphy by a human calligrapher:
Here is the Math-Lego version:
You may also watch the video of how the painting was done at https://www.youtube.com/watch?v=cLr12miy4nE&feature=youtu.be
- Python 3
- Numpy = 1.17.0
- Matplotlib = 3.1.1
- Pandas = 0.25.1
Simply cd into the folder and do
python sunny.py
Please contact me via pengshancai@umass.edu
Finally, wish you have a sunny day!