I'm trying to make a visual representation of the first million digits of pi inside a circle. Like in the coding train channel, but with Python. (https://www.youtube.com/watch?v=WEd_UIKG-uc&index=137&list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH)
It should be looking like this:
but it looks like this:
First off all I imported math
and tkinter
class, I read the document and make the canvas. I think there's no problem in here:
from math import *
from tkinter import *
openpi = open (r'PI_numbers.txt', 'r')
pi = openpi.read()
win= Tk()
win = Canvas(win, width=500, height=500)
win.configure(background=('black'))
win.create_oval(0,0,500,500, fill='white')
Next, as I didn't know how to make a switch case, I searched and found something.
def zero(sx,sy):
angle=36*0
x= 250* (1 + cos(angle))
y= 250* (1 + sin(angle))
win.create_line(sx,sy, x, y)
sx=x
sy=y
def one(sx,sy):
angle=36*1
x = 250 * (1 + cos(angle))
y = 250 * (1 + sin(angle))
win.create_line(sx, sy, x, y)
sx = x
sy = y
def two(sx,sy):
angle=36*2
x = 250 * (1 + cos(angle))
y = 250 * (1 + sin(angle))
win.create_line(sx, sy, x, y)
sx = x
sy = y
And like this to nine. And then:
y=250
x=250
options = {
'0': zero(sx=x, sy= y),
'1': one(sx=x, sy= y),
'2': two(sx=x, sy= y),
'3': three(sx=x, sy= y),
'4': four(sx=x, sy= y),
'5': five(sx=x, sy= y),
'6': six(sx=x, sy= y),
'7': seven(sx=x, sy= y),
'8': eight(sx=x, sy= y),
'9': nine(sx=x, sy= y),
".": point()
}
i=0
while len(pi)> i:
n = pi[i]
options [n]
i += 1
win.pack()
win.mainloop()
So, in here I'm trying to make a line from the last number to the new one. I start at 250 250, the center of the circumference. The problem I detect is not just the x and y are wrong but the fact that it's starting always from the center and i don't know why.
And in line of options [n]
I get this : statement seems to have no effect.