On 12/19/18 12:19 PM, Dennis Lee Bieber wrote:

        I don't see anything in your code that makes any use of
polar<>rectangular coordinate conversion -- which is what you were
interested in when starting the thread. You appear to just be rastering a
15x15 rectangle (ie: the first 225 digits. If you really want to plot all
the digits you provide, you should be looping over /them/, not some
arbitrary X and Y coordinates.


I didn't say I yet had what I need to use polar coordinates for yet working, or that I even yet had done anything past some planning in my head. In the numberphile video I linked to, the 3rd (I think) way to represent PI (the one professor Grimes says looks like the tiling in a Roman bathhouse) and I think the 4th way (the one that is the other guy's favorite I think) have only been designed a bit in my head so far. I just think those 2 ways, which no code has been written for yet, would be easier to do using polar coordinates. And yes, I know there are ways that I could have used all 1000 digits of PI rather than just 49 of them.
pi1000 =
[3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0,2,8,
           8,4,1,9,7,1,6,9,3,9,9,3,7,5,1,0,
                <SNIP>
           8,7,6,6,1,1,1,9,5,9,0,9,2,1,6,4,2,0,1,9,8,9]

        Pardon me while I go UGH!... That must have been tedious to enter (and
why double spaced). This may add a few milliseconds in processing (I'll
explain later), but looks a lot cleaner:

pi1000 = ("3.1415926535897932384626433832795028"
        "8419716939937510582097494459230781"
                <SNIP>
        "8766111959092164201989")


As for putting in the value for PI, it was actually rather easy. To get the number itself, I just searched for and downloaded a file that had PI to 1000 places and copied and pasted it into the editor. As for the commas, at least to my current understanding of python, I thought those had to between the elements of an array. As for putting in the commas, I did that by using the "replace all" function in my IDE (or perhaps I used gedit, a linux version of notepad) to replace all the "0" with "0,", "1" with "1,", etc, so that was not very tedious and was actually pretty fast. As for the double spacing, like I said it seems that usenet (or perhaps my usenet viewer) seems to mess with spacing or whatever, they do not exist on the actual program on my compputer.

        Python will concatenate adjacent strings, so that becomes just one long
string internally -- if you were to "print pi1000" (Python 2.x syntax) it
would display:

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164
20
1989


        Consider this; I spent way too much time generating the code when I
should be out shopping for Christmas (watch out for line wrapping):

-=-=-=-=-
import math

import matplotlib as mpl
import matplotlib.pyplot as plt

PI1000 = ("3.1415926535897932384626433832795028"
        "8419716939937510582097494459230781"
        "64062862089986280348253421170679821"
        "48086513282306647093844609550582231"
        "72535940812848111745028410270193852"
        "11055596446229489549303819644288109"
        "75665933446128475648233786783165271"
        "20190914564856692346034861045432664"
        "82133936072602491412737245870066063"
        "15588174881520920962829254091715364"
        "36789259036001133053054882046652138"
        "41469519415116094330572703657595919"
        "53092186117381932611793105118548074"
        "46237996274956735188575272489122793"
        "81830119491298336733624406566430860"
        "21394946395224737190702179860943702"
        "77053921717629317675238467481846766"
        "94051320005681271452635608277857713"
        "42757789609173637178721468440901224"
        "95343014654958537105079227968925892"
        "35420199561121290219608640344181598"
        "13629774771309960518707211349999998"
        "37297804995105973173281609631859502"
        "44594553469083026425223082533446850"
        "35261931188171010003137838752886587"
        "53320838142061717766914730359825349"
        "04287554687311595628638823537875937"
        "51957781857780532171226806613001927"
        "8766111959092164201989")

def spiral_plot(digits):
     #create list of (x, y, color) tuples for the digits
     #(provided as a string); non-digits get the 11th color
     #X,Y are coordinates for an spiral
     x_coords = []
     y_coords = []
     xy_color = []
     mx = 0
     my = 0
     for p, d in enumerate(digits):
         #treating p as angle in degrees and as distance
         x = math.cos(math.radians(p)) * p
         y = math.sin(math.radians(p)) * p
         if d.isdigit():
             clr = int(d)       #0..9 so
         else:
             clr = 10           #10 is the 11th color
         x_coords.append(x)
         y_coords.append(y)
         xy_color.append(clr)

     plt.scatter(x_coords, y_coords, c=xy_color, cmap=mpl.cm.Spectral,
s=200)
     plt.show()

if __name__ == "__main__":
     spiral_plot(PI1000)
-=-=-=-

        NOTE: there are no doubt more efficient ways to work this -- for
example, using NumPy arrays to generate the coordinates en-mass


Like I said, or at least think I implied, when I wrote the code I posted, I did not even know that matplotlib or numpy even existed, just the existence of the "graphics package" graphics.py. What I have working, I do not need polar coordinates for, I need them for what I have planned in my head for the indefinite future.

The code you posted appears to make professor Grimes "Roman bathhouse tiling" representation of PI (I have not, as of when I typed this message cut and pasted it into my IDE to see exactly what happens). I think I will use it, or perhaps an adaptation of it for my "Roman bathhouse tiling" representation of PI. Perhaps I will see if I can adapt it to use NumPY, but I suspect that you can do that better than I.



--
My Yonkoma: https://www.flickr.com/photos/brian0908/albums/72157680223526176

The E-mail associated with the account is a "spamcatcher" account that I got to every couple of months to empty out, and anything sent to it will not be seen for probably several months, if it is seen at all.
Brian Christiansen
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to