# Experiment With Changing These ------------------------ GridWidth = 16 # Changes width of grid | GridHeight = 16 # Changes height of grid | PixelSize = 10 # Change size of 'pi-xel' | Sides = 4 # Changes number of sides of 'pi-xel' | #-------------------------------------------------------- # Basic Parameters TurningAngle = (90-(((180 + (Sides-3)*180)/Sides)-90)) # Calculates Angles xStart = (GridHeight*-10)/2 # X-Axis Starting Position yStart = (GridHeight*10)/2 # Y-Axis Starting Position PixelNumber = 0 # Pixel Counter (For Colour Information) PixelList = [] # Stores Colour Information # Calculate Necessary Digits of Pi from decimal import Decimal, getcontext getcontext().prec = GridWidth*GridHeight Pi = sum(1/Decimal(16)**x* (Decimal(4)/(8*x+1) - Decimal(2)/(8*x+4) - Decimal(1)/(8*x+5) - Decimal(1)/(8*x+6)) for x in range(100)) Pi = str(Pi) Pi = Pi.replace(".","") # Decimal point is removed # Adds colour data for every digit into a list for Digit in Pi: if int(Digit) == 0: PixelList.append([170, 0, 0]) # 0 = Dark Red if int(Digit) == 1: PixelList.append([255, 0, 0]) # 1 = Red if int(Digit) == 2: PixelList.append([255, 128, 0]) # 2 = Orange if int(Digit) == 3: PixelList.append([255, 255, 85])# 3 = Yellow if int(Digit) == 4: PixelList.append([85, 255, 85]) # 4 = Light Green if int(Digit) == 5: PixelList.append([0, 85, 0]) # 5 = Dark Green if int(Digit) == 6: PixelList.append([0, 0, 255]) # 6 = Blue if int(Digit) == 7: PixelList.append([128, 0, 255]) # 7 = Purple if int(Digit) == 8: PixelList.append([170, 0, 170]) # 8 = Magenta if int(Digit) == 9: PixelList.append([255, 85, 255])# 9 = Pink # Turtle Parameters import turtle turtle.speed(0) # 0 = Fastest Speed turtle.colormode(255) # Mode = RGB Colour Values turtle.pencolor(0, 0, 0) # Outline = Black turtle.title("Pi-xel Art") # Title = 'Pi-xel Art' turtle.hideturtle() # Hides Turtle # Draw and Fill 'Pi-xel' def Pixel(xStart, yStart, Red, Green, Blue): turtle.goto(xStart, yStart) # Go to next position in grid turtle.fillcolor(Red, Green, Blue) # Set fill colour # Start drawing 'pi-xel' turtle.pendown() turtle.begin_fill() # Draw the 'pi-xel' for i in range(Sides): # Number of sides of the 'pi-xel' turtle.forward(PixelSize) # Size of each side of the 'pi-xel' turtle.right(TurningAngle) # Angle which the pen turns # End drawing 'pi-xel' turtle.end_fill() turtle.penup() # Move to next position in grid for Coloumn in range(GridWidth): for Row in range(GridHeight): turtle.penup() Pixel(xStart, yStart, PixelList[PixelNumber][0], PixelList[PixelNumber][1], PixelList[PixelNumber][2]) # Retrieve colour & position of next pi-xel # Move to next pi-xel xStart += PixelSize PixelNumber += 1 # Start new row xStart = (GridHeight*-10)/2 yStart -= PixelSize