diagcirculaire.py

Created by florian-allard

Created on February 19, 2022

1.21 KB

Diagramme circulaire tracé à partir des données d’une liste.


from math import *
from turtle import *
#from kandinsky import *
for mois in range(2):
  sector=[[0,6,186,987,2054],[0,5,167,946,2080]][mois]#noir,rouge,orange,jaune,vert
  total=sum(sector)
  pourcentage=[k/total for k in sector]
  pourcentcumul=[sum(pourcentage[:i+1]) for i in range(len(pourcentage))]
  hideturtle()
  for angle in range(0,360,3):
    color('black')
    for rang in range(4):
      if angle/360>=pourcentcumul[rang]:
        color(['red','orange','yellow','green'][rang])
    penup()
    goto(-80+160*mois,40)
    pensize(3)
    speed(0)
    setheading(angle+90)
    fd(45//2-1)
    pendown()
    fd(75//2+1)
  for rayon in [43//2,120//2]:#cercles blancs
    penup()
    goto(rayon-80+160*mois,40)
    setheading(90)
    pendown()
    pensize(5)
    color('white')
    circle(rayon)

  for i in range(1,4):
    penup()
    goto(0-80+160*mois,40)
    setheading(90+(pourcentcumul[-i]+pourcentcumul[-i-1])/2*360)
    fd(90//2)
    setheading(0)
    fd(-34//2)
    pendown()
    write(str(pourcentage[-i]*100)[:str(pourcentage[-i]*100).index(".")+2]+"%")#*100+"%")
  penup()
  goto(-48-80+160*mois,-50)
  write(["septembre"," janvier"][mois])
  goto(-25-80+160*mois,-20-50)
  write(["2021","2022"][mois])

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.