@Annvil/

Turtle Demo

Python (with Turtle)

No description

fork
loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import turtle

turtleNames = [["Leonardo",240], ["Raphael",327], ["Michelangelo",226], ["Donatello",257], ["Anything else",40]]
turtleColors = ["purple","green","red","orange","blue"]

totalAmt = 0
for piePiece in turtleNames:
  totalAmt += piePiece[1]

splinter = turtle.Turtle()
splinter.speed(5)

R = 175 # Radius
lastX= 0
lastY= -175

for piePiece in enumerate(turtleNames):
  piecePercent = float(piePiece[1][1]) / float(totalAmt)

  splinter.color("black", turtleColors[piePiece[0]])

  splinter.pendown()
  splinter.begin_fill()
  splinter.goto(lastX, lastY)
  splinter.circle(R, piecePercent*360) 

  lastX = splinter.xcor()
  lastY = splinter.ycor()
  splinter.goto(0,0)
  splinter.end_fill()

  splinter.penup()
  splinter.goto(150,225-piePiece[0]*20)
  splinter.write(piePiece[1][0], False, font=("Arial", 12, "bold"))
  
  splinter.goto(0,0)




  
result
console