Tutorials for plotting Penrose dots with Python code

Source: Internet
Author: User
Here is the script that shows the Penrose dot matrix python. Yes, this is a valid Phython code that can be run.

Penrose lattice, physics terminology. In the 70 's, British mathematician Penrose first proposed this concept, called Penrose lattice (pen-rose tiles).

_ =\ "" "if!              1: "E,v=100 0," (0j-1) **-.2;           V,s=.5/v.real, [(0,0,4 *e,4*e* V)];w=1-v "def! E (T,a, B,c):P, q,r=b*w+ a*v,b*w+c *v,a*w+b*v;retur n[(1,q,c,a), (1,p, Q,b), (0,q,p,a)]*t+[ (0,c, R,b), (1,r,c,a)]* (1-t) "For!i!in!_[:11]:s =sum ([E (*x) for!x!in! S],[]) "Imp Ort!cair o!as!   O        S=o.ima GESURFAC E (1,e,e); C=o.con text (s);   M,l,g=c.    Move_to, C.line_to,c.s et_sour Ce_rgb a "def!z (F,a): F (-A.    Imag,a. REAL-E-E) "for!     T,a,b,c!in[i!for!i! in! S!if!i["" "; Exec (X,i:x.replace (Chr (i)," \ n "[34-i:]), range (+), _+" "" 0]]:z (m,a); Z (l,b); Z (     L,C);       C.CLOSE_PA th () "G (. 4,.3, 1); c. Paint ();       G (. 7,. 7,1); C.fil l () "Fo r!i!in!range (9):"! g=1-i/8;d=i/4*g; G (D,d,d, 1-g*.8) "!def!y (f,a): Z (f,a+ (1+2j) * (1j** (I/2.)) *G) "!for! t,a,b,c!in!                    S:y (m,c); y (l,a); Y (M, A); y (l,b) "!c.st Roke ()" s.write_t o_png (' Pen rose.png ') "" ))

When this program runs, it outputs a 1000x1000 image file containing about 2,212 Penrose dots rendered by 3D stereoscopic effects. Here is a part of the image (click to enlarge).

Running the script requires Pycairo. It's only in Python and it's a standard Python script, but I'm trying to make it more concise, so I cut it out a little bit.

Note: Pycairo is a set of Python versions of the Cario graphics library.

The Penrose lattice is cool because they cover the entire plane in a non-cyclical way-the converted copy of the picture never coincides with the prototype. They were invented by a series of attempts by Mr. Roger Penrose to tile the plane of the Pentagon.

Python is not a confusing programming language compared to C or Perl. This kind of comparison never seems to happen, and there are not many puzzling examples of Python on the Web: You can find some examples in the official Python FAQs or on various pages like here and here. In 2011, Pycon also had a panel discussion on this.

I believe that outputting a high-resolution image is the first confusing Python program. If you know other examples, you can tell me in the comments.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.