Last active
April 19, 2022 07:12
-
-
Save cavedave/423d67a583ad10925aa6dc85ab7acab4 to your computer and use it in GitHub Desktop.
Logo Turtle picture of pi. 1 million pi digits at https://www.angio.net/pi/digits.html e at https://apod.nasa.gov/htmltest/gifcity/e.1mil sqrt(2) https://apod.nasa.gov/htmltest/rjn_dig.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
import random | |
random.seed(42) | |
i=0 | |
#file = open("emil.txt", "r") | |
#file = open("pi1000000.txt", "r") | |
file = open("sqrt2.txt", "r") | |
text=file.read() | |
pi = list(text) | |
pi = list(map(int, pi)) | |
screen = turtle.Turtle() | |
turtle.clearscreen() | |
wn = turtle.Screen() # creates a graphics window | |
wn.tracer(1000000, 25) | |
wn.setup (width=7000, height=4500, startx=None, starty=None) | |
turtle.penup() | |
turtle.hideturtle() | |
#turtle.setpos(400,240)#pi | |
#turtle.setpos(650,330)#e | |
turtle.setpos(500,-170)#sqrt2 | |
#turtle.setpos(0,330) random | |
turtle.speed(0) | |
turtle.down() | |
turtle.pencolor("#ff0000") | |
angle=0 | |
while i < 1000000: | |
#print(pi[i]) | |
#angle= (int(float(pi[i])))*36 #quicker to turn string to int at start | |
#ran= random.randint(0, 9) | |
#angle= ran*36 | |
angle= pi[i]*36 | |
#print(angle) | |
turtle.right(angle) | |
turtle.forward(1) | |
j=360-angle | |
turtle.right(j) | |
if i == 0: | |
turtle.pencolor("#a6cee3") | |
if i ==100000: | |
turtle.pencolor("#1f78b4") | |
if i == 200000: | |
turtle.pencolor("#b2df8a") | |
if i == 300000: | |
turtle.pencolor("#33a02c") | |
if i == 400000: | |
turtle.pencolor("#fb9a99") | |
if i == 500000: | |
turtle.pencolor("#e31a1c") | |
if i == 600000: | |
turtle.pencolor("#fdbf6f") | |
if i == 700000: | |
turtle.pencolor("#ff7f00") | |
if i == 800000: | |
turtle.pencolor("#cab2d6") | |
if i == 900000: | |
turtle.pencolor("#551A8B") | |
i=i+1 | |
ts = turtle.getscreen() | |
#ts.getcanvas().postscript(file="randompiMC.eps") | |
#ts.getcanvas().postscript(file="eMC600k.eps") | |
ts.getcanvas().postscript(file="sqrt2MC1mil.eps") | |
#ts.getcanvas().postscript(file="pi1mil.eps") | |
turtle.bye() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cavedave hi Dave, thanks very much for your code and blog post!
I worked this weekend to clarify the code: plot/plot_digitangle.py which uses a heatmap color scheme for the angles. It can accept any arbitrary text file, filtering only the digits. The use of generator functions, instead of lists, should ease memory usage for very long iterations.
Here is a plot of the first 10,000 digits of pi using pi-digits.txt: