Skip to content

Build up your dreams using Lego pieces based on Python!

Notifications You must be signed in to change notification settings

pengshancai/math-lego

Repository files navigation

Math-Lego 迈思乐高

Build up your dreams using Lego pieces based on Python!

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.

Introduction

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".

Basic Math-Lego Pieces

Constant Bender

Constant Bender

Constant Bender let you create a curved line with a constant curvature. You may adjust the curvature to create a more curly line.

Sin Bender

Sin Bender

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.

Linear Bender

Linear Bender

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)

Customize your own Math-Lego pieces

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

sun shine

Advanced Math-Lego Pieces

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.

sun shine

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:

sun shine

You may also write other advanced Math-Lego pieces by yourself!

Further into art

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:

sun shine

Here is the Math-Lego version:

sun shine

You may also watch the video of how the painting was done at https://www.youtube.com/watch?v=cLr12miy4nE&feature=youtu.be

Dependencies

  • Python 3
  • Numpy = 1.17.0
  • Matplotlib = 3.1.1
  • Pandas = 0.25.1

Running instructions

Simply cd into the folder and do

python sunny.py

Contact

Please contact me via pengshancai@umass.edu

Finally, wish you have a sunny day!

sun shine

About

Build up your dreams using Lego pieces based on Python!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages