MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/ulamspiral.py:14–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12DOT_SIZE = 4
13
14def main():
15 turtle.bgcolor('#353337') # Use a dark background color.
16 turtle.pencolor('#CCCCCC') # The spiral is a light gray color.
17
18 # (!) Comment this next line to draw the spiral.
19 turtle.penup()
20 turtle.forward(SPACING) # 1 is not prime, so skip
21 turtle.left(90)
22 turtle.dot(DOT_SIZE) # 2 is prime, so make a dot
23 turtle.forward(SPACING)
24 turtle.left(90)
25
26 currentNumber = 3 # This is the number we test for primality.
27 spiralSideLength = 3
28 while currentNumber < 40000:
29 # We draw two sides before increasing the spiral side length:
30 for i in range(2):
31 for j in range(spiralSideLength):
32 divs = amountOfDivisors(currentNumber)
33 currentNumber += 1
34
35 if divs == 0:
36 # Mark the prime number
37 turtle.dot(DOT_SIZE, '#76b7eb')
38 turtle.forward(SPACING)
39 turtle.left(90)
40 spiralSideLength += 1
41
42 turtle.update() # Finish drawing the screen.
43 turtle.exitonclick() # When user clicks on the window, close it.
44
45
46def amountOfDivisors(number):

Callers 1

ulamspiral.pyFile · 0.70

Calls 1

amountOfDivisorsFunction · 0.85

Tested by

no test coverage detected