Using Python code to draw the Penrose dot matrix tutorial _python

Source: Internet
Author: User
Tags python script in python

Here is the Python script that shows the Penrose dot matrix. Yes, this is a valid Phython code that can be run.

Penrose lattice, physics terminology. In the 70 's, the British mathematician Penrose put forward this concept for the first time, called the 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) "F or!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);     (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 the program runs, it outputs a 1000x1000 image file containing about 2,212 Penrose lattices rendered by the 3D stereo effect. This is part of the image (click to enlarge).

Running the script requires Pycairo. It's just a standard Python script in Python, but I tried to make it simpler, so I cut it out a little bit.

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

The Penrose lattice is cool, because they cover the entire plane aperiodic--the converted copy of the picture never agrees with the prototype. They were invented by a series of attempts by Roger Penrose to tile the Pentagon flat.

Python is not a confusing programming language compared to C or Perl. This comparison does not seem to have happened, and there are not many obscure examples of Python on the Web: You can find examples in the official Python FAQ or on various pages such as here and here. There was also a thematic discussion on the Pycon in 2011.

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

Related Article

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.