Skip to content

Instantly share code, notes, and snippets.

@cavedave
Last active October 27, 2017 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cavedave/0cf462071f684b0c5d6f034db4e08b93 to your computer and use it in GitHub Desktop.
Save cavedave/0cf462071f684b0c5d6f034db4e08b93 to your computer and use it in GitHub Desktop.
Prime Numbers Horizontal Color representation. Make each pixel a color based on the digit. Go through the concatinated primes in the Smarandache Sequence. Start top left. Move right each step and every thousand digits drop down one. This code needs some of the defined earlier functions
#!/usr/bin/python3
import turtle
#the number of digits to use
numDigits = 300000
scale =1
y=450;
filename = "matrix3.eps"
currentPrime=0
def getDigits():
#0.12345678910111213…
current = 1;
print(current)
while True:
current_str = str(current);
for digit in current_str:
yield int(digit)
current = current + 1
def getPrimeDigits():
#0.12345678910111213…
current = 1;
newP =next_prime(current)
while True:
newP =next_prime(current)
#print(newP)
current_str = str(newP);
for digit in current_str:
yield int(digit)
current = current + 1
gen = getPrimeDigits()
ts = turtle.getscreen()
turtle.hideturtle()
turtle.speed(0)
turtle.tracer(0,0)
turtle.pensize(1)
ts.setup(width=1100, height=1100, startx=-1000, starty=1000)
turtle.penup()
turtle.setpos(-500,500)
turtle.pendown()
for i in range(numDigits):
digit = next(gen)
if digit == 0:
turtle.pencolor("#a6cee3")
if digit == 1: #and i > 100000:
turtle.pencolor("#1f78b4")
if digit == 2: # and i > 200000:
turtle.pencolor("#b2df8a")
if digit == 3: # and i > 300000:
turtle.pencolor("#33a02c")
if digit == 4: # and i > 400000:
turtle.pencolor("#fb9a99")
if digit == 5: # and i > 500000:
turtle.pencolor("#e31a1c")
if digit == 6: # and i > 600000:
turtle.pencolor("#fdbf6f")
if digit == 7: # and i > 700000:
turtle.pencolor("#ff7f00")
if digit == 8: # and i > 800000:
turtle.pencolor("#cab2d6")
if digit == 9: # and i > 900000:
turtle.pencolor("#551A8B")
turtle.forward(1)
i=i+1
if i % 1000 == 0:
turtle.penup()
turtle.setpos(-500,y)
turtle.pendown()
y=y-1
print(currentPrime)
turtle.update()
ts.getcanvas().postscript(file=filename)
turtle.bye()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment