()
| 12 | DOT_SIZE = 4 |
| 13 | |
| 14 | def 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 | |
| 46 | def amountOfDivisors(number): |
no test coverage detected