π
<-
Chat plein-écran
[^]

Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotlib

Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotlib

Unread postby critor » 19 Oct 2020, 11:49

Juste à temps pour le lancement des journées APMEP ce week-end, Casio nous a offert une mise à jour majeure de l'ensemble de sa gamme graphique non formelle ! :bj:

Pour une fois, les mises à jour ciblent aussi bien les dernières générations monochromes et couleurs que les générations les ayant précédées :
  • 3.50 pour Graph 90+E et fx-CG50
  • 3.40 pour la génération monochrome USB Power Graphic 3 (Graph 35+E II en France, fx-9750GIII et fx-9860GIII dans d'autres pays)
  • 3.12 pour fx-CG10 et fx-CG20
  • 2.11 pour les anciennes générations monochromes USB Power Graphic 1 et USB Power Graphic 2

Des nouveautés d'importance sont donc ici transversales, d'où notre tentative de les traiter dans un unique article.

Avant cela, nous avons une petite chose à mettre au point. Les logiciels d'installation de mises à jour Casio contiennent usuellement plusieurs images système installables sur différentes variantes d'un modèle selon les pays. Avant de traiter des nouveautés, listons donc rapidement ce que nous avons ici afin de pouvoir nous y référer plus tard :
Mise à
jour
Image
système
Version nouvelle
+ précédente
Timbre à date nouveau
+ précédent
Référence
modèles ciblés
Modèles
ciblés
3.50
3070
3.50
3.40
2020.0924.1830
2020.0313.0216
CY810A
Graph 90+E, fx-CG50
3071
3.50
3.40
2020.0924.1845
2020.0313.0229
CY810F
fx-CG50AU
3.40
3070
3.40
3.30
2020.0918.1757
2020.0313.0229
CY835A
Graph 35+E II
3071
3.40
3.21
2020.0918.1811
2020.0313.0229
CY837A
fx-9860GIII
3072
3.40
3.21
2020.0918.1820
2020.0313.0229
CY838A
fx-9750GIII
3.12
3070
3.12
3.11
2020.0924.1914
2018.0308.1942
LY755A
fx-CG10/20
3071
3.12
3.11
2020.0924.1926
2018.0308.1951
LY755F
fx-CG20AU
2.11
3071
2.08
2015.1201.1207
GY493A
fx-9860GII SD (USB Power Graphic 1)
3072
2.08
2015.1201.1207
GY493B
Graph 95 (USB Power Graphic 1)
3073
2.08
2015.1201.1215
GY495A
fx-9860GII (USB Power Graphic 1)
3074
2.08
2015.1201.1219
GY495B
Graph 75 (USB Power Graphic 1)
3075
2.08
2015.1201.1223
GY495E
fx-9860G AU
3080
2.11
2.09
2020.0910.1404
2015.1204.1158
GY497A
fx-9860GII SD (USB Power Graphic 2)
3081
2.09
2015.1204.1203
GY497B
Graph 95 (USB Power Graphic 2)
3082
2.09
2015.1204.1208
GY498A
fx-9860GIIs
3083
2.11
2.09
2020.0910.1353
2015.1204.1213
GY499A
fx-9860GII (USB Power Graphic 2)
3084
2.09
2015.1204.1218
GY499B
Graph 75+
3085
2.09
2015.1204.1223
GY499E
fx-9860G AU+
3086
2.09
2015.1202.1718
CY802A
Graph 75+E


131691316813157Pour ce qui est simple, nous avons donc :
  • la Graph 90+E et ses équivalents internationaux fx-CG50 qui passent de la version 3.40 du 13 mars 2020 à la nouvelle version 3.50 compilée le 24 septembre 2020
  • la Graph 35+E II qui passe de la version 3.30 du 13 mars 2020 à la nouvelle version 3.40 compilée le 18 septembre 2020
  • ses pendants internationaux fx-9750GIII et fx-9860GIII qui passent directement de la version 3.21 du 13 mars 2020 à la nouvelle version 3.40 compilée le 18 septembre 2020

13171Quant à la mise à jour 2.11 pour les anciennes générations monochromes USB Power Graphic 1 et USB Power Graphic 2 :
  • rien de nouveau pour les modèles de la génération USB Power Graphic 1 (processeur SH3) qui ne seront mis à jour qu'au maximum vers la version 2.08 compilée le 1er décembre 2015
  • rien de nouveau non plus pour les déclinaisons locales à certains pays de la génération USB Power Graphic 2 (Graph 75+ et Graph 75+E pour la France, fx-9860G AU+ pour l'Australie, fx-9860GIIs pour Singapour) qui ne seront mis à jour qu'au maximum vers la version 2.09 compilée le 4 décembre 2015
Ne peuvent être mis à jour vers la nouvelle version 2.11 que les seuls modèles internationaux de la génération USB Power Graphic 2 : fx-9860G II et fx-9860GII SD.

Maintenant que nous avons toutes ces bases, découvrons ensemble les nouveautés.








1) Python et casioplot

Go to top

1315513165Commençons par les nouveautés autour de l'application Python intégrée apportées à la fois :
  • par la mise à jour 3.50 de la dernière génération couleur :
    • Graph 90+E
    • fx-CG50
  • par la mise à jour 3.40 de la dernière génération monochrome :
    • Graph 35+E II
    • fx-9860GIII
    • fx-9750GIII
Rappelons que les fx-9860GIII et fx-9750GIII, équivalents de la Graph 35+E II respectivement en Europe et Amérique du Nord, n'ont à la différence de cette dernière pas bénéficié d'une mise à jour intermédiaire 3.30. En passant directement de la version 3.21 à 3.40, leur application Python bénéficie déjà de tout ce qui a été apporté sur Graph 35+E II avec la version 3.30 et que nous t'invitons à aller consulter, et notamment enfin du module de tracé par pixels casioplot. :bj:

Passons maintenant aux nouveautés spécifiquement apportées par la dernière version 3.40 ou 3.50.

Nous avions déjà remarqué que le module de tracé par pixels casioplot offrait une fonction clear_screen() pour effacer l'écran, fonction parfaitement fonctionnelle mais qui bizarrement n'était pas au catalogue de modules et fonctions accessible via
SHIFT
4
, et les appels à cette fonction doivent redonc être saisis à la main caractère par caractère.

Désormais clear_screen() est bien disponible au catalogue. :)




2) Python et turtle

Go to top

La dernière mise à jour apportait donc le module de tracé par pixels casioplot. Casio France diffusait de plus un script turtle.py, une réécriture complète en Python du module de tracés relatifs turtle standard.

Ce choix de passer par un script turtle.py additionnel avait toutefois trois inconvénients majeurs :
  • déjà, turtle.py ne venait pas avec les mises à jour et devait donc être ajouté manuellement dans la calculatrice
  • les fonctions du module turtle n'étaient pas listées au catalogue ; elles devaient donc être connues et saisies manuellement caractère par caractère :(
  • comme tout fichier additionnel, turtle.py était de plus inutilisable en mode examen. :'(

Et bien gros changement sur les modèles français Graph 90+E et Graph 35+E II avec la dernière version, le module turtle est désormais directement intégré au système ! :bj:
Il devient donc à la fois :
  • disponible immédiatement
  • décrit au catalogue
  • utilisable en mode examen

13155A noter que cette amélioration semble ne concerner que les modèles français. La fx-9750GIII mise à jour ne bénéficie pas de cette amélioration, et probablement pas mieux pour les autres modèles internationaux fx-9860GIII et fx-CG50. :#non#:

Sur ces modèles il faudra donc continuer à passer par les scripts additionnels que nous te lierons en fin d'article, scripts qui deviendront indisponibles en mode examen.




3) Exemples turtle

Go to top

Ce qui était déjà remarquable avec la réécriture intégrale du module turtle par Casio, c'est la haute conformité au standard que l'on vérifiait aisément en comparant ce que donne le même script sur ordinateur, et on peut en passant comparer avec les plateformes concurrentes.
Voici quelques exemples utilisant du code turtle standard. Nous allons juste mettre dans le code quelques protections concernant les fonctions parfois non définies sur certaines plateformes, afin que leur appel n'empêche pas l'affichage du tracé obtenu. Mais nous ne coderons ici rien pour corriger des incompatibilités avec la norme.
ordi
Graph 90+E
Graph 35+E II
NumWorks
TI-83 Premium CE
TI-84 Plus CE


Code: Select all
try: #TI-83 Premium CE
  from ce_turtl import turtle
  turtle.clear()
except ImportError: import turtle

turtle.speed(0)
for i in range(12):
  turtle.left(30)
  for i in range(8):
    turtle.forward(30)
    turtle.left(45)

try: turtle.show() #TI-83 Premium CE
except: pass

ordi
Graph 90+E
Graph 35+E II
NumWorks
TI-83 Premium CE
TI-84 Plus CE


Code: Select all
try: #TI-83 Premium CE
  from ce_turtl import turtle
  turtle.clear()
except ImportError: import turtle

def try_pencolor(c):
  try: turtle.pencolor(c)
  except: pass
  try: turtle.color(c)
  except: pass

def koch(n, l):
  if n==0:
    turtle.forward(l)
  else:
    koch(n-1, l/3)
    turtle.left(60)
    koch(n-1, l/3)
    turtle.right(120)
    koch(n-1, l/3)
    turtle.left(60)
    koch(n-1, l/3)

try_pencolor("blue")
turtle.penup()
turtle.goto(-180, -50)
turtle.pendown()
koch(4, 360)

try: turtle.show() #TI-83 Premium CE
except: pass



ordi
Graph 90+E
Graph 35+E II
NumWorks
TI-83 Premium CE
TI-84 Plus CE


Code: Select all
try: #TI-83 Premium CE
  from ce_turtl import turtle
  turtle.clear()
except ImportError: import turtle

from math import exp

def try_colormode(m):
  try: turtle.colormode(m)
  except: pass
def try_pencolor(c):
  try: turtle.pencolor(c)
  except: pass
  try: turtle.color(c)
  except: pass

try_colormode(1)
for i in range(1,37):
  red=(exp(-0.5 * ((i-6)/12)**2))
  green=(exp(-0.5 * ((i-18)/12)**2))
  blue=(exp(-0.5 * ((i-30)/12)**2))
  try_pencolor([red, green, blue])
  for i in range(1, 5):
    turtle.forward(60)
    turtle.right(90)
  turtle.right(10)

try: turtle.show() #TI-83 Premium CE
except: pass

ordi
Graph 90+E
Graph 35+E II
NumWorks
TI-83 Premium CE
TI-84 Plus CE


Code: Select all
try: #TI-83 Premium CE
  from ce_turtl import turtle
  turtle.clear()
except ImportError: import turtle

from math import exp

def try_colormode(m):
  try: turtle.colormode(m)
  except: pass
def try_pencolor(c):
  try: turtle.pencolor(c)
  except: pass
  try: turtle.color(c)
  except: pass

try_colormode(1)
turtle.penup()
turtle.goto(0, -20)
turtle.pendown()
for i in range(1,37):
  red=(exp(-0.5 * ((i-6)/12)**2))
  green=(exp(-0.5 * ((i-18)/12)**2))
  blue=(exp(-0.5 * ((i-30)/12)**2))
  try_pencolor([red,green,blue])
  turtle.circle(50-i)
  turtle.right(10)

try: turtle.show() #TI-83 Premium CE
except: pass

ordi
Graph 90+E
Graph 35+E II
NumWorks
TI-83 Premium CE
TI-84 Plus CE


Code: Select all
try: #TI-83 Premium CE
  from ce_turtl import turtle
  turtle.clear()
except ImportError: import turtle

def try_colormode(m):
  try: turtle.colormode(m)
  except: pass
def try_pencolor(c):
  try: turtle.pencolor(c)
  except: pass
  try: turtle.color(c)
  except: pass

def sierp(n, l):
  if n == 0:
    for i in range (0, 3):
      turtle.forward(l)
      turtle.left(120)
  if n > 0:
    sierp(n-1, l/2)
    turtle.forward(l/2)
    sierp(n-1, l/2)
    turtle.backward(l/2)
    turtle.left(60)
    turtle.forward(l/2)
    turtle.right(60)
    sierp(n-1, l/2)
    turtle.left(60)
    turtle.backward(l/2)
    turtle.right(60)

try_colormode(1)
turtle.penup()
turtle.backward(109)
turtle.left(90)
turtle.backward(100)
turtle.right(90)
turtle.pendown()
try_pencolor((1, 0, 0))
sierp(6, 217)
turtle.penup()
turtle.forward(400)

try: turtle.show() #TI-83 Premium CE
except: pass

Comme tu peux le voir, les Graph 90+E et Graph 35+E II comptaient déjà parmi les meilleures solutions sur le critère de la conformité au standard turtle, pas d'écart sur ces exemples contrairement à certaines solutions concurrentes ! :bj:

Niveau fonctions dont les appels ont ici été protégés pour palier leur absence sur certaines plateformes, en fait il ne manque pas grand chose aux Graph 90+E et Graph 35+E II, juste turtle.colormode().




4) Nouveautés turtle

Go to top

Nous remarquons en fait que le module turtle désormais intégré est toujours écrit en Python, son code étant lisible en clair en mémoire. Et nous notons surtout qu'il s'agit d'une nouvelle version par rapport à celle sortie au printemps dernier, une mise à jour assez majeure si tu compares toutes les différences ci-dessous :
Code: Select all
import casioplot
from math import sqrt
from math import pi
from math import cos
from math import sin
from math import atan2

turtleshapes={"classic":[[-9,5],[-9,4],[-8,4],[-8,3],[-8,2],[-8,-2],[-8,-3],[-8,-4],[-9,-4],[-9,-5],[-7,4],[-7,1],[-7,0],[-7,-1],[-7,-4],[-6,3],[-6,-3],[-5,3],[-5,-3],[-4,2],[-4,-2],[-3,2],[-3,-2],[-2,1],[-2,-1],[-1,1],[-1,-1],[0,0]],"turtle": [[-3,3],[2,3],[-2,2],[-1,2],[0,2],[1,2],[-2,1],[-1,1],[1,1],[0,1],[2,1],[3,1],[-2,0],[-1,0],[0,0],[1,0],[-1,-1],[-2,-1],[0,-1],[1,-1],[2,0],[3,0],[-3,-2],[2,-2]]}
turtle_name="classic"
turtle_data=turtleshapes[turtle_name]
turtle_pos=[0,0]
turtle_angle=0
turtle_color=(0,0,0)
writing=True
pen_size=1
turtle_buffer=[[]]
turtle_speed=5
frame_count=0
turtle_visible=True

def draw_turtle(x,y,a,c):
  global turtle_buffer
  def inbuffer(x,y):
    inlist=False
    for i in range(1,len(turtle_buffer)):
      if x==turtle_buffer[i][0] and y==turtle_buffer[i][1]:
        inlist=True
    return inlist
  if turtle_visible==True:
    u=cos(a*pi/180)
    v=sin(a*pi/180)
    for point in turtle_data:
      xx=x+(point[0]*u-point[1]*v)
      yy=y+(point[1]*u+point[0]*v)
      xpixel=int(round(xx+192))
      ypixel=int(round(-yy+96))
      if (0<=xpixel<=383 and 0<=ypixel<=191):
        if not inbuffer(xpixel,ypixel):
          turtle_buffer+=[[xpixel,ypixel,casioplot.get_pixel(xpixel,ypixel)]]
        casioplot.set_pixel(xpixel,ypixel,c)

def erase_turtle():
  global turtle_buffer
  for i in range(1,len(turtle_buffer)):
    xpixel=turtle_buffer[i][0]
    ypixel=turtle_buffer[i][1]
    if turtle_buffer[i][2]!=None :
      lastcolor=turtle_buffer[i][2]
    else:
      lastcolor=(255,255,255)
    casioplot.set_pixel(xpixel,ypixel,lastcolor)
  turtle_buffer=[[]]

def pen_brush(x,y,turtle_color):
  global frame_count
  erase_turtle()
  xpixel=int(round(x+192))
  ypixel=int(round(-y+96))
  if writing==True and (0<=xpixel<=383 and 0<=ypixel<=191) :
    colorpixel=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
    casioplot.set_pixel(xpixel,ypixel,colorpixel)
    frame_count+=1
    if turtle_speed!=0:
      if frame_count%(turtle_speed*4)==0:
        draw_turtle(x,y,turtle_angle,colorpixel)
        casioplot.show_screen()
    else :
      if frame_count%500==0:
        draw_turtle(x,y,turtle_angle,colorpixel)
        casioplot.show_screen()

def refresh_turtle():
  c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
  erase_turtle()
  draw_turtle(turtle_pos[0],turtle_pos[1],turtle_angle,c)
  casioplot.show_screen()

def back(n):
  forward(-n)

def backward(n):
  back(n)

def bk(n):
  back(n)

def circle(radius,extent=360):
  global  turtle_angle, turtle_pos
  x1=turtle_pos[0]
  y1=turtle_pos[1]
  if round(radius)==0:
    pen_brush(x1,y1,turtle_color)
    turtle_angle+=extent
  elif round(extent,8)==0:
    pen_brush(x1,y1,turtle_color)
  else:
    e=radius/abs(radius)
    theta=extent*pi/180*e
    Rx=cos(theta)
    Ry=sin(theta)
    Dx=radius*sin(turtle_angle*pi/180)
    Dy=-radius*cos(turtle_angle*pi/180)
    xcenter=x1-Dx
    ycenter=y1-Dy
    nbpixelarc=int(round(abs(radius*theta*1.05)))
    angle=turtle_angle
    if nbpixelarc!=0:
      alpha=theta/nbpixelarc
      for k in range(nbpixelarc+1):
        x=xcenter+Dx*cos(alpha*k)-Dy*sin(alpha*k)
        y=ycenter+Dx*sin(alpha*k)+Dy*cos(alpha*k)
        turtle_angle+=alpha*180/pi
        pen_brush(x,y,turtle_color)
    turtle_pos[0]=xcenter+Dx*Rx-Dy*Ry
    turtle_pos[1]=ycenter+Dx*Ry+Dy*Rx
    turtle_angle=angle+extent*e
  refresh_turtle()

def clear():
  erase_turtle()
  casioplot.clear_screen()
  casioplot.show_screen()
  refresh_turtle()

def distance(x,y):
  return sqrt((x-turtle_pos[0])**2+(y-turtle_pos[1])**2)

def down():
  global writing
  writing=True

def fd(d):
  forward(d)

def forward(d):
  global turtle_pos
  dx=d*cos(turtle_angle*pi/180)
  dy=d*sin(turtle_angle*pi/180)
  x1=turtle_pos[0]
  y1=turtle_pos[1]
  if round(abs(d))==0:
    pen_brush(x1+dx,y1+dy,turtle_color)
  elif abs(dx)>=abs(dy):
    e=int(dx/abs(dx))
    m=dy/dx
    p=y1-m*x1
    for x in range(int(round(x1)),int(round(x1+dx)),e):
      pen_brush(x,m*x+p,turtle_color)
  else:
    e=int(dy/abs(dy))
    m=dx/dy
    p=x1-m*y1
    for y in range(int(round(y1)),int(round(y1+dy)),e):
      pen_brush(m*y+p,y,turtle_color)
  turtle_pos[0]+=dx
  turtle_pos[1]+=dy
  refresh_turtle()

def goto(x,y):
  a=turtle_angle
  setheading(towards(x,y))
  forward(distance(x,y))
  setheading(a)
  refresh_turtle()

def heading():
  return turtle_angle

def hideturtle():
  global turtle_visible
  turtle_visible=False
  refresh_turtle()

def home():
  global turtle_pos,turtle_angle
  turtle_pos[0]=turtle_pos[1]=0
  turtle_angle=0
  refresh_turtle()

def ht():
  hideturtle()

def isdown():
  return writing

def isvisible():
  return turtle_visible

def left(a):
  right(-a)

def lt(a):
  right(-a)

def pd():
  down()

def pencolor(*c):
  global turtle_color
  colornames={"black":(0,0,0),"blue":(0,0,1),"green":(0,1,0),"red":(1,0,0),"cyan":(0,1,1),"yellow":(1,1,0),"magenta":(1,0,1),"white":(1,1,1),"orange":(1,0.65,0),"purple":(0.66,0,0.66),"brown":(0.75,0.25,0.25),"pink":(1,0.75,0.8),"grey":(0.66,0.66,0.66)}
  if c==():
    return turtle_color
  elif c[0] in colornames:
    turtle_color=colornames[c[0]]
  elif isinstance(c[0],(list,tuple)) and len(c[0])==3 and isinstance(c[0][0],(int,float)) and isinstance(c[0][1],(int,float)) and isinstance(c[0][2],(int,float)) and 0<=c[0][0]<=1 and 0<=c[0][1]<=1 and 0<=c[0][2]<=1:
    turtle_color=list(c[0])
  else:
    raise ValueError('error using pencolor : enter a color text or 3 floats between 0 and 1')
  refresh_turtle()

def pendown():
  down()

def pensize(n):
  global pen_size
  pen_size=n
  refresh_turtle()

def penup():
  global writing
  writing=False

def pos():
  return (xcor(),ycor())

def position():
  return (xcor(),ycor())

def pu():
  penup()

def reset():
  global turtle_color,writing,pen_size,speed,turtle_visible
  clear()
  turtle_color=(0,0,0)
  home()
  writing=True
  pen_size=1
  speed=5
  turtle_visible=True
  shape("classic")
  refresh_turtle()

def right(a):
  global turtle_angle
  turtle_angle-=a
  refresh_turtle()

def rt(a):
  right(a)

def seth(a):
  setheading(a)

def setheading(a):
  global turtle_angle
  turtle_angle=a
  refresh_turtle()

def setpos(x,y):
  goto(x,y)
  refresh_turtle()

def setposition(x,y):
  setpos(x,y)

def setx(x):
  global turtle_pos
  turtle_pos[0]=x
  refresh_turtle()

def sety(y):
  global turtle_pos
  turtle_pos[1]=y
  refresh_turtle()

def shape(text=None):
  global turtle_name,turtle_data
  if text==None:
    return turtle_name
  elif text in turtleshapes:
    turtle_name=text
    turtle_data=turtleshapes[text]
  else:
    raise ValueError('available shapes: "classic" or "turtle"')
  refresh_turtle()

def showturtle():
  global turtle_visible
  turtle_visible=True
  refresh_turtle()

def speed(v=None):
  global turtle_speed
  speedwords = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
  if v==None:
    pass
  elif isinstance(v,(int,float)) and (v<=0.5 or v>=10.5):
    turtle_speed=0
  elif isinstance(v,(int,float)) and (0.5<v<10.5):
    turtle_speed=int(round(v))
  elif isinstance(v,str) and v in speedwords:
    turtle_speed=speedwords[v]
  else:
    raise ValueError("Error using function speed: enter a real between 0 & 10")

def st():
  showturtle()

def towards(x,y):
  if round(x-turtle_pos[0],8)==0 and round(y-turtle_pos[1],8)==0:
    return 0
  else:
    return (atan2(y-turtle_pos[1],x-turtle_pos[0])*180/pi)

def up():
  penup()

def width(n):
  pensize(n)

def write(text):
  xpixel=int(round(turtle_pos[0]+192))
  ypixel=int(round(-turtle_pos[1]+96))
  c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
  casioplot.draw_string(xpixel,ypixel,str(text),c,"small")
  casioplot.show_screen()

def xcor():
  return round(turtle_pos[0],6)
def ycor():
  return round(turtle_pos[1],6)
Code: Select all
import casioplot
from math import sqrt
from math import pi
from math import cos
from math import sin
from math import atan2

turtleshapes={"classic":[[-9,5],[-9,4],[-8,4],[-8,3],[-8,2],[-8,-2],[-8,-3],[-8,-4],[-9,-4],[-9,-5],[-7,4],[-7,1],[-7,0],[-7,-1],[-7,-4],[-6,3],[-6,-3],[-5,3],[-5,-3],[-4,2],[-4,-2],[-3,2],[-3,-2],[-2,1],[-2,-1],[-1,1],[-1,-1],[0,0]],"turtle": [[-3,3],[2,3],[-2,2],[-1,2],[0,2],[1,2],[-2,1],[-1,1],[1,1],[0,1],[2,1],[3,1],[-2,0],[-1,0],[0,0],[1,0],[-1,-1],[-2,-1],[0,-1],[1,-1],[2,0],[3,0],[-3,-2],[2,-2]]}
turtle_name="classic"
turtle_data=turtleshapes[turtle_name]
turtle_pos=[0,0]
turtle_angle=0
turtle_color=(0,0,0)
writing=True
pen_pixels=[[0,0]]
turtle_buffer=[]
turtle_speed=5
frame_count=0
turtle_visible=True
pen_size=1

def _draw_turtle(x,y,a,c):
  global turtle_buffer
  def inbuffer(x,y):
    inlist=False
    for i in range(len(turtle_buffer)):
      if x==turtle_buffer[i][0] and y==turtle_buffer[i][1]:
        inlist=True
    return inlist
  if turtle_visible==True:
    u=cos(a*pi/180)
    v=sin(a*pi/180)
    for point in turtle_data:
      xx=x+(point[0]*u-point[1]*v)
      yy=y+(point[1]*u+point[0]*v)
      xpixel=int(round(xx+192))
      ypixel=int(round(-yy+96))
      if (0<=xpixel<=383 and 0<=ypixel<=191):
        if not inbuffer(xpixel,ypixel):
          turtle_buffer+=[[xpixel,ypixel,casioplot.get_pixel(xpixel,ypixel)]]
        casioplot.set_pixel(xpixel,ypixel,c)

def _erase_turtle():
  global turtle_buffer
  for i in range(len(turtle_buffer)):
    xpixel=turtle_buffer[i][0]
    ypixel=turtle_buffer[i][1]
    if turtle_buffer[i][2]!=None :
      lastcolor=turtle_buffer[i][2]
    else:
      lastcolor=(255,255,255)
    casioplot.set_pixel(xpixel,ypixel,lastcolor)
  turtle_buffer.clear()

def _pen_brush(x,y,turtle_color):
  global frame_count
  _erase_turtle()
  xpixel=int(round(x+192))
  ypixel=int(round(-y+96))
  if writing==True and (0<=xpixel<=383 and 0<=ypixel<=191) :
    colorpixel=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))

    for point in pen_pixels:
      casioplot.set_pixel(xpixel+point[0],ypixel+point[1],colorpixel)

    frame_count+=1
    if turtle_speed!=0:
      if frame_count%(turtle_speed*4)==0:
        _draw_turtle(x,y,turtle_angle,colorpixel)
        casioplot.show_screen()
    else :
      if frame_count%500==0:
        _draw_turtle(x,y,turtle_angle,colorpixel)
        casioplot.show_screen()

def _refresh_turtle():
  c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
  _erase_turtle()
  _draw_turtle(turtle_pos[0],turtle_pos[1],turtle_angle,c)
  casioplot.show_screen()

def _conv_angle(a):
  a=a%360
  if a < 0:
    a=360+a
  return a

def back(n):
  forward(-n)

def backward(n):
  back(n)

def bk(n):
  backward(n)

def circle(radius,extent=360):
  global  turtle_angle, turtle_pos
  x1=turtle_pos[0]
  y1=turtle_pos[1]
  if round(radius)==0:
    _pen_brush(x1,y1,turtle_color)
    turtle_angle+=extent
  elif round(extent,8)==0:
    _pen_brush(x1,y1,turtle_color)
  else:
    e=radius/abs(radius)
    theta=extent*pi/180*e
    Rx=cos(theta)
    Ry=sin(theta)
    Dx=radius*sin(turtle_angle*pi/180)
    Dy=-radius*cos(turtle_angle*pi/180)
    xcenter=x1-Dx
    ycenter=y1-Dy
    nbpixelarc=int(round(abs(radius*theta*1.05)))
    angle=turtle_angle
    if nbpixelarc!=0:
      alpha=theta/nbpixelarc
      for k in range(nbpixelarc+1):
        x=xcenter+Dx*cos(alpha*k)-Dy*sin(alpha*k)
        y=ycenter+Dx*sin(alpha*k)+Dy*cos(alpha*k)
        turtle_angle+=alpha*180/pi
        _pen_brush(x,y,turtle_color)
    turtle_pos[0]=xcenter+Dx*Rx-Dy*Ry
    turtle_pos[1]=ycenter+Dx*Ry+Dy*Rx
    turtle_angle=angle+extent*e
  turtle_angle=_conv_angle(turtle_angle)
  _refresh_turtle()

def clear():
  _erase_turtle()
  casioplot.clear_screen()
  casioplot.show_screen()
  _refresh_turtle()

def distance(x,y):
  return sqrt((x-turtle_pos[0])**2+(y-turtle_pos[1])**2)

def down():
  global writing
  writing=True

def fd(d):
  forward(d)

def forward(d):
  global turtle_pos
  dx=d*cos(turtle_angle*pi/180)
  dy=d*sin(turtle_angle*pi/180)
  x1=turtle_pos[0]
  y1=turtle_pos[1]
  if round(abs(d))==0:
    _pen_brush(x1+dx,y1+dy,turtle_color)
  elif abs(dx)>=abs(dy):
    e=int(dx/abs(dx))
    m=dy/dx
    p=y1-m*x1
    for x in range(int(round(x1)),int(round(x1+dx)),e):
      _pen_brush(x,m*x+p,turtle_color)
  else:
    e=int(dy/abs(dy))
    m=dx/dy
    p=x1-m*y1
    for y in range(int(round(y1)),int(round(y1+dy)),e):
      _pen_brush(m*y+p,y,turtle_color)
  turtle_pos[0]+=dx
  turtle_pos[1]+=dy
  _refresh_turtle()

def goto(x,y):
  a=turtle_angle
  setheading(towards(x,y))
  forward(distance(x,y))
  setheading(a)
  _refresh_turtle()

def heading():
  return turtle_angle

def hideturtle():
  global turtle_visible
  turtle_visible=False
  _refresh_turtle()

def home():
  global turtle_angle
  goto(0,0)
  turtle_angle=0
  _refresh_turtle()

def ht():
  hideturtle()

def isdown():
  return writing

def isvisible():
  return turtle_visible

def left(a):
  right(-a)

def lt(a):
  left(a)

def pd():
  down()

def pencolor(*c):
  global turtle_color
  colornames={"black":(0,0,0),"blue":(0,0,1),"green":(0,1,0),"red":(1,0,0),"cyan":(0,1,1),"yellow":(1,1,0),"magenta":(1,0,1),"white":(1,1,1),"orange":(1,0.65,0),"purple":(0.66,0,0.66),"brown":(0.75,0.25,0.25),"pink":(1,0.75,0.8),"grey":(0.66,0.66,0.66)}
  if c==():
    return turtle_color
  elif c[0] in colornames:
    turtle_color=colornames[c[0]]
  elif isinstance(c[0],(list,tuple)) and len(c[0])==3 and isinstance(c[0][0],(int,float)) and isinstance(c[0][1],(int,float)) and isinstance(c[0][2],(int,float)) and 0<=c[0][0]<=1 and 0<=c[0][1]<=1 and 0<=c[0][2]<=1:
    turtle_color=list(c[0])

  elif len(c)==3 and isinstance(c[0],(int,float)) and isinstance(c[1],(int,float)) and isinstance(c[2],(int,float)) and 0<=c[0]<=1 and 0<=c[1]<=1 and 0<=c[2]<=1:
    turtle_color=list(c)

  else:
    raise ValueError('error using pencolor : enter a color text or 3 floats between 0 and 1')
  _refresh_turtle()

def pendown():
  down()

def pensize(n=None):
  global pen_pixels,pen_size
  penshape=[[0,0],[1,0],[0,1],[-1,0],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1],[2,0],[0,2],[-2,0],[0,-2],[2,1],[1,2],[-2,1],[-1,2],[2,-1],[1,-2],[-2,-1],[-1,-2]]
  if n==None:
    return pen_size
  elif isinstance(n,(int,float)) and n>=0:
    pen_size=n
    if round(n)==0 or round(n)==1 :
      pen_pixels=[[0,0]]
    elif round(n)==2 :
      pen_pixels=penshape[0:5]
    elif round(n)==3 :
      pen_pixels=penshape[0:9]
    elif round(n)==4 :
      pen_pixels=penshape[0:13]
    elif round(n)==5 :
      pen_pixels=penshape[0:21]
    elif round(n)>5 :
      pen_pixels=penshape[0:21]
      pen_size=5
      print('Userwarning: pensize over 5 automatically set to 5.')
  else:
    raise ValueError('Error using function pensize: enter a real between 0 & 5')
  _refresh_turtle()

def penup():
  global writing
  writing=False

def pos():
  return position()

def position():
  return (xcor(),ycor())

def pu():
  penup()

def reset():
  global turtle_color,writing,pen_pixels,turtle_speed,turtle_visible,pen_size
  turtle_color=(0,0,0)
  clear()
  hideturtle()
  penup()
  home()
  pendown()
  writing=True
  pen_size=1
  pen_pixels=[[0,0]]
  turtle_speed=5
  shape("classic")
  turtle_visible=True
  _refresh_turtle()

def right(a):
  global turtle_angle
  if isinstance(a, (int, float)):
    turtle_angle = _conv_angle(turtle_angle-a)
  else:
    raise ValueError('error')
  _refresh_turtle()

def rt(a):
  right(a)

def seth(a):
  setheading(a)

def setheading(a):
  global turtle_angle
  turtle_angle=_conv_angle(a)
  _refresh_turtle()

def setpos(x,y):
  goto(x,y)

def setposition(x,y):
  setpos(x,y)

def setx(x):
  goto(x,turtle_pos[1])

def sety(y):
  goto(turtle_pos[0],y)

def shape(name=None):
  global turtle_name,turtle_data
  if name==None:
    return turtle_name
  elif name in turtleshapes:
    turtle_name=name
    turtle_data=turtleshapes[name]
  else:
    raise ValueError('available shapes: "classic" or "turtle"')
  _refresh_turtle()

def showturtle():
  global turtle_visible
  turtle_visible=True
  _refresh_turtle()

def speed(speed=None):
  global turtle_speed
  speedwords = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
  if speed==None:
    return turtle_speed
  elif isinstance(speed,(int,float)) and (speed<=0.5 or speed>=10.5):
    turtle_speed=0
  elif isinstance(speed,(int,float)) and (0.5<speed<10.5):
    turtle_speed=int(round(speed))
  elif isinstance(speed,str) and speed in speedwords:
    turtle_speed=speedwords[speed]
  else:
    raise ValueError("Error using function speed: enter a real between 0 & 10")

def st():
  showturtle()

def towards(x,y):
  if round(x-turtle_pos[0],8)==0 and round(y-turtle_pos[1],8)==0:
    return 0
  else:
    ang=atan2(y-turtle_pos[1],x-turtle_pos[0])*180/pi
    if ang>=0:
        return (ang)
    else:
        return (360+ang)

def up():
  penup()

def width(n=None):
  return pensize(n)

def write(text):
  _refresh_turtle()
  xpixel=int(round(turtle_pos[0]+192))
  ypixel=int(round(-turtle_pos[1]+96))
  c=(int(turtle_color[0]*255), int(turtle_color[1]*255),int(turtle_color[2]*255))
  casioplot.draw_string(xpixel,ypixel,str(text),c,"small")
  casioplot.show_screen()

def xcor():
  return round(turtle_pos[0],6)
def ycor():
  return round(turtle_pos[1],6)


Nous avions remarqué un petit écart avec la fonction turtle.write(), cette dernière écrivant le texte fourni dans un rectangle dont la tortue occupe le sommet supérieur gauche, alors que dans le standard c'est le sommet inférieur gauche. Vérifions :
ordi
Graph 90+E
Graph 35+E II
NumWorks
TI-83 Premium CE
TI-84 Plus CE


Code: Select all
try: #TI-83 Premium CE
  from ce_turtl import turtle
  turtle.clear()
except ImportError: import turtle

def try_pencolor(c):
  try: turtle.pencolor(c)
  except: pass
  try: turtle.color(c)
  except: pass

turtle.forward(40)
turtle.backward(100)
turtle.left(90)
turtle.forward(30)
turtle.right(60)
turtle.forward(60)
turtle.right(30)
turtle.forward(30)
turtle.penup()
turtle.forward(18)
turtle.right(90)
turtle.forward(60)
turtle.pendown()
turtle.right(30)
turtle.backward(30)
turtle.right(60)
turtle.forward(60)
try_pencolor("red")
turtle.penup()
turtle.goto(80,40)
turtle.right(140)
turtle.pendown()
turtle.circle(30)
turtle.penup()
turtle.goto(105,50)
try_pencolor("green")
turtle.pendown()
turtle.circle(-50)
turtle.penup()
try_pencolor("red")
turtle.right(21)
turtle.goto(60,20)
turtle.pendown()
turtle.circle(40,60)
turtle.penup()
try_pencolor("blue")
turtle.goto(-50,15)
turtle.setheading(0)
turtle.pendown()
turtle.write("CASIO")

try: turtle.show() #TI-83 Premium CE
except: pass

Non finalement pas de changement ici, mais vu en comparaison les énormes écarts que se permettent d'autres plateformes on peut bien passer l'éponge cette fois-ci.

Autre chose que nous avions remarqué, un petit bug au niveau de la fonction turtle.pensize() qui semblait inopérante :
ordi
Graph 90+E
Graph 35+E II
NumWorks
TI-83 Premium CE
TI-84 Plus CE



Et bien ici bonne nouvelle, la nouvelle version intégrée de turtle corrige le problème ! :bj:




5) Python et matplotlib.pyplot

Go to top

Ici aussi Casio France diffusait depuis la dernière mise à jour un script matplotl.py, une réécriture complète en Python du module de tracés par coordonnées matplotl.pyplot standard.

Ce choix de passer par un script matplotl.py additionnel avait ici encore plusieurs inconvénients majeurs :
  • matplotl.py ne venait pas avec les mises à jour et devait donc être ajouté manuellement dans la calculatrice
  • Les fonctions du module matplotl n'étaient pas listées au catalogue ; elles devaient donc être connues et saisies manuellement caractère par caractère :(
  • Comme tout fichier additionnel, matplot.py était de plus inutilisable en mode examen. :'(
  • La calculatrice ne gérant que partiellement les noms de fichiers longs, le fichier de script correspondant avait donc été nommé matplotl.py et non matplotlib.pyplot.py afin de respecter la limitation à 8 caractères, ce qui introduisait donc une incompatibilté avec les scripts conçus pour le standard matplotlib.pyplot.
    La compatibilité avec des scripts conçus pour d'autres plateformes nécessitait un léger effort, quelques lignes d'importation spécifiques en début de script :
    Code: Select all
    try: from matplotlib.pyplot import *
    except ImportError: from matplotl import *

Gros changement en conséquence sur les modèles français Graph 90+E et Graph 35+E II avec la dernière version, le module est désormais directement intégré au système et de plus renommé correctement en matplotlib.pyplot ! :bj:
Il devient donc à la fois :
  • disponible immédiatement
  • décrit au catalogue
  • utilisable en mode examen
  • directement utilisable avec les scripts matplotlib.pyplot conçus pour d'autres plateformes, même plus besoin de modifier les lignes d'importation

13155A noter que cette amélioration semble ici encore ne concerner que les modèles français. La fx-9750GIII mise à jour ne bénéficie pas de cette amélioration, et même si nous n'en disposons pas c'est probablement pareil sur les autres modèles internationaux fx-9860GIII et fx-CG50. :#non#:

Sur ces modèles il faudra donc continuer à passer par les scripts additionnels que nous te lierons en fin d'article, scripts qui seront inutilisables en mode examen.




6) Exemples matplotlib.pyplot

Go to top

Pour une réécriture intégrale, observons ici encore la remarquable compatibilité avec le standard matplotlib.pyplot de l'ordinateur, ainsi que ce que donnent les implémentations concurrentes :
ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
try:
  from matplotlib.pyplot import *
except ImportError:
  from matplotl import *

x = [119.1, 119.3, 119.5, 119.6, 119.9, 120.0, 120.1, 120.3, 120.4]
y = [1, 3, 4, 3, 1, 3, 1, 3, 1]

bar(x, y, 0.08)
show()

ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
try:
  from matplotlib.pyplot import *
except ImportError:
  from matplotl import *

x = [119.1, 119.3, 119.5, 119.6, 119.9, 120.0, 120.1, 120.3, 120.4]
y = [1, 3, 4, 3, 1, 3, 1, 3, 1]

bar(x, y, 0.08)
show()

ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
try:
  from matplotlib.pyplot import *
except ImportError:
  from matplotl import *

V=[20,40,60,80,100]
P=[307,150,101.7,75.8,61]
axis([0,110,0,350])
plot(V,P,"blue")
text(40,250,"P (kPa) versus V (mL)")
show()

ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
try:
  from matplotlib.pyplot import *
except ImportError:
  from matplotl import *

def f(x):
  return x**3-6*x**2+9*x+1
start = -0.5
end = 4.5
steps = 0.1
x = [start+i*steps for i in range(int((end-start)/steps)+1)]
y = [f(j) for j in x]
plot(x, y)
show()

Comme tu peux le noter, les Graph 90+E et Graph 35+E II comptent ici encore parmi les meilleures solutions du point de vue de la compatibilité avec le standard matplotlib.pyplot, pas d'écart sur ces exemples contrairement à certaines solutions concurrentes ! :bj:




7) Nouveautés matplotlib.pyplot

Go to top

Le module matplotlib.pyplot intégré est toujours écrit en Python, son code étant lisible en clair en mémoire. Et il s'agit surtout d'une nouvelle version par rapport à celle sortie au printemps dernier, une mise à jour assez majeure selon toutes les différences ci-dessous :
Code: Select all
import casioplot as plt

limits=[40,165,384,0]
fenetre=[0,1,0,1]
points=[[]]
lines=[[]]
textes=[[]]
xmin,xmax,ymin,ymax=0,1,0,1
win_scaling='init'
axis_display='on'
color_auto=['b','r','g','k','m','c','y']
color_count=0

def axis(*L):
    global fenetre,win_scaling,axis_display
    if L==():
        if win_scaling=='auto':
            if xmin==xmax:
                if xmin==0:
                    fenetre[0:2]=[-0.05,0.05]
                else:
                    fenetre[0:2]=[0.95*xmin,1.05*xmin]
            else:
                fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
            if ymin==ymax:
                if ymin==0:
                    fenetre[2:4]=[-0.05,0.05]
                else:
                    fenetre[2:4]=[0.95*ymin,1.05*ymin]
            else:
                fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
        return fenetre
    elif isinstance(L[0],(list,tuple)) and len(L[0])==4:
        fenetre=list(L[0])
        if fenetre[0]==fenetre[1]:
            if fenetre[0]==0:
                fenetre[0:2]=[-0.05,0.05]
            else:
                fenetre[0:2]=[0.95*fenetre[0],1.05*fenetre[0]]
            raise Exception('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
        if fenetre[2]==fenetre[3]:
            if fenetre[2]==0:
                fenetre[2:4]=[-0.05,0.05]
            else:
                fenetre[2:4]=[0.95*fenetre[2],1.05*fenetre[2]]
            raise Exception('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
        win_scaling='fixed'
        axis_display='on'
        return fenetre
    elif L[0]=='off':
        axis_display='off'
    elif L[0]=='on':
        axis_display='on'
    elif L[0]=='auto':
        win_scaling='auto'
        if xmin==xmax:
            if xmin==0:
                fenetre[0:2]=[-0.05,0.05]
            else:
                fenetre[0:2]=[0.95*xmin,1.05*xmin]
        else:
            fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
        if ymin==ymax:
            if ymin==0:
                fenetre[2:4]=[-0.05,0.05]
            else:
                fenetre[2:4]=[0.95*ymin,1.05*ymin]
        else:
            fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
        return fenetre
    else:
        raise Exception('function axis() : error using arguments')

def text(x,y,txt):
    global textes
    if textes==[[]]:
        textes[0]=[x,y,txt]
    else:
        if [x,y,txt] not in textes :
            textes+=[[x,y,txt]]

def plot(*L,**kwargs):
    global color_count,win_scaling
    # if len(L)==2:
    #     L=([list(L[0]),list(L[1])])
    def plotpoint(x,y,c):
        global points,xmin,xmax,ymin,ymax
        if points==[[]]:
            points[0]=[x,y,c]
            xmin=xmax=x
            ymin=ymax=y
        else:
            if [x,y,c] not in points :
                points+=[[x,y,c]]
                xmin=min(x,xmin)
                xmax=max(x,xmax)
                ymin=min(y,ymin)
                ymax=max(y,ymax)

    def plotline(x1,y1,x2,y2,c):
        global lines,xmin,xmax,ymin,ymax
        if lines==[[]]:
            lines[0]=[x1,y1,x2,y2,c]
            xmin=min(x1,x2)
            xmax=max(x1,x2)
            ymin=min(y1,y2)
            ymax=max(y1,y2)
        else:
            if [x1,y1,x2,y2,c] not in lines :
                lines+=[[x1,y1,x2,y2,c]]
                xmin=min(x1,x2,xmin)
                xmax=max(x1,x2,xmax)
                ymin=min(y1,y2,ymin)
                ymax=max(y1,y2,ymax)

    color=kwargs.get('color',None)
    if color!=None and not color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
        raise ValueError('function plot() : unknown color code')
    if len(L)==2 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)):
        plotpoint(L[0],L[1],color)
        if win_scaling=='init':
            win_scaling='auto'
    elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)):
        if (len(L[0])==len(L[1])):
            if color==None:
                color=color_auto[color_count%7]
                color_count+=1
            for i in range(len(L[0])-1):
                plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
            if win_scaling=='init':
                win_scaling='auto'
        else:
            raise ValueError('function plot() : x and y must have same dimension')
    elif len(L)==1 and isinstance(L[0],(list,tuple)):
        if color==None:
            color=color_auto[color_count%7]
            color_count+=1
        for i in range(len(L[0])-1):
            plotline(i,L[0][i],i+1,L[0][i+1],color)
        if win_scaling=='init':
            win_scaling='auto'
    elif len(L)==3 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)) and isinstance(L[2],(str)):
        color=L[2]
        if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
            plotpoint(L[0],L[1],color[0])
            if win_scaling=='init':
                win_scaling='auto'
        elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
            plotpoint(L[0],L[1],color)
            if win_scaling=='init':
                win_scaling='auto'
        elif color in ['o','.','+','*','-']:
            color=color_auto[color_count%7]
            color_count+=1
            plotpoint(L[0],L[1],color)
            if win_scaling=='init':
                win_scaling='auto'
        else:
            raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
    elif len(L)==3 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)) and isinstance(L[2],(str)):
        if (len(L[0])==len(L[1])):
            color=L[2]
            if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
                for i in range(len(L[0])-1):
                    plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color[0])
                if win_scaling=='init':
                    win_scaling='auto'
            elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
                for i in range(len(L[0])-1):
                    plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
                if win_scaling=='init':
                    win_scaling='auto'
            elif color in ['o','.','+','*','-']:
                color=color_auto[color_count%7]
                color_count+=1
                for i in range(len(L[0])-1):
                    plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],color)
                if win_scaling=='init':
                    win_scaling='auto'
            else:
                raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
        else:
            raise ValueError('function plot() : x and y must have same dimension')
    elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(str)):
        color=L[1]
        if (len(color)==2 and color[0] in ['b','r','g','k','m','c','y','w']) and color[1] in ['o','.','+','*','-']:
            for i in range(len(L[0])-1):
                plotline(i,L[0][i],i+1,L[0][i+1],color[0])
            if win_scaling=='init':
                win_scaling='auto'
        elif color in ['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white']:
            for i in range(len(L[0])-1):
                plotline(i,L[0][i],i+1,L[0][i+1],color)
            if win_scaling=='init':
                win_scaling='auto'
        elif color in ['o','.','+','*','-']:
            color=color_auto[color_count%7]
            color_count+=1
            for i in range(len(L[0])-1):
                plotline(i,L[0][i],i+1,L[0][i+1],color)
            if win_scaling=='init':
                win_scaling='auto'
        else:
            raise ValueError('function plot() : available color codes are b,r,g,k,m,c,y,w')
    else:
        raise Exception('function plot() : error using arguments')

def show():
    global fenetre, limits, points, lines, textes, xmin, ymin, xmax, ymax, win_scaling, axis_display, color_count

    def RGB(c):
        if c=="k" or c=="black":
            return (0,0,0)
        elif c=="b" or c=="blue":
            return (0,0,255)
        elif c=="g" or c=="green":
            return (0,255,0)
        elif c=="r" or c=="red":
            return (255,0,0)
        elif c=="c" or c=="cyan":
            return (0,255,255)
        elif c=="y" or c=="yellow":
            return (255,255,0)
        elif c=="m" or c=="magenta":
            return (255,0,255)
        elif c=="w" or c=="white":
            return (255,255,255)
        else:
            raise ValueError("invalid color code")

    def printable(x,y):
        global limits
        return(limits[0]<=x<=limits[2] and limits[3]<=y<=limits[1])

    def echelle(a,b):
        k=0
        e=abs(b-a)
        while e>=10 :
            e/=10
            k+=1
        while e<1 :
            e*=10
            k-=1
        return k

    def pas(a,b):
        pas=10**echelle(a,b)
        while (abs(b-a))//pas<4:
            pas/=2
        return pas

    def converttopixel(x,y):
        global fenetre,limits
        ax=(limits[2]-limits[0])/(fenetre[1]-fenetre[0])
        bx=limits[0]-ax*fenetre[0]
        xpixel=round(ax*x+bx)
        ay=(limits[3]-limits[1])/(fenetre[3]-fenetre[2])
        by=limits[1]-ay*fenetre[2]
        ypixel=round(ay*y+by)
        return xpixel,ypixel

    color_count=0
    plt.clear_screen()
    if win_scaling=='auto':
        if xmin==xmax:
            if xmin==0:
                fenetre[0:2]=[-0.05,0.05]
            else:
                fenetre[0:2]=[0.95*xmin,1.05*xmin]
        else:
            fenetre[0:2]=[xmin-0.05*(xmax-xmin),xmax+0.05*(xmax-xmin)]
        if ymin==ymax:
            if ymin==0:
                fenetre[2:4]=[-0.05,0.05]
            else:
                fenetre[2:4]=[0.95*ymin,1.05*ymin]
        else:
            fenetre[2:4]=[ymin-0.05*(ymax-ymin),ymax+0.05*(ymax-ymin)]
    if axis_display=='on' or axis_display=='boxplot':
        for i in range(limits[0],limits[2]+1):
            plt.set_pixel(i,limits[1],RGB("k"))
        for j in range(limits[3],limits[1]+1):
            plt.set_pixel(limits[0],j,RGB("k"))
        fenetreb=sorted([fenetre[0],fenetre[1]])+sorted([fenetre[2],fenetre[3]])
        gx=round(fenetreb[0],-echelle(fenetreb[0],fenetreb[1]))
        gy=round(fenetreb[2],-echelle(fenetreb[2],fenetreb[3]))
        if axis_display=='boxplot':
            for i in range(nbre_boite):
                y=fenetre[2]
                xpixel,ypixel=converttopixel(i+1,y)
                plt.set_pixel(xpixel,ypixel+1,RGB("k"))
                plt.set_pixel(xpixel,ypixel+2,RGB("k"))
                plt.set_pixel(xpixel,ypixel+3,RGB("k"))
                plt.draw_string(xpixel,ypixel+13,str(round(i+1,8)),[0,0,0],"small")
        else :
            for i in range(-11,11):
                x=gx+i*pas(fenetreb[0],fenetreb[1])
                y=fenetre[2]
                xpixel,ypixel=converttopixel(x,y)
                if printable(xpixel,ypixel):
                    plt.set_pixel(xpixel,ypixel+1,RGB("k"))
                    plt.set_pixel(xpixel,ypixel+2,RGB("k"))
                    plt.set_pixel(xpixel,ypixel+3,RGB("k"))
                    plt.draw_string(xpixel,ypixel+13,str(round(x,8)),[0,0,0],"small")
        for j in range(-11,11):
            x=fenetre[0]
            y=gy+j*pas(fenetreb[2],fenetreb[3])
            xpixel,ypixel=converttopixel(x,y)
            if printable(xpixel,ypixel):
                plt.set_pixel(xpixel-1,ypixel,RGB("k"))
                plt.set_pixel(xpixel-2,ypixel,RGB("k"))
                plt.set_pixel(xpixel-3,ypixel,RGB("k"))
                plt.draw_string(xpixel-40,ypixel,str(round(y,8)),[0,0,0],"small")
    if points!=[[]]:
        if points[0]==[]:
            del points[0]
        for i in range(len(points)):
            xpixel,ypixel=converttopixel(points[i][0],points[i][1])
            if printable(xpixel,ypixel) and points[i][2]!=None:
                for j in range(-2,3):
                    plt.set_pixel(xpixel+j,ypixel,RGB(points[i][2]))
                    plt.set_pixel(xpixel,ypixel+j,RGB(points[i][2]))
    if textes!=[[]]:
        if textes[0]==[]:
            del textes[0]
        for i in range(len(textes)):
            xpixel,ypixel=converttopixel(textes[i][0],textes[i][1])
            if printable(xpixel,ypixel):
                plt.draw_string(xpixel,ypixel,textes[i][2],[0,0,0],"small")
    if lines!=[[]]:
        if lines[0]==[]:
            del lines[0]
        for i in range(len(lines)):
            xpixel1,ypixel1=converttopixel(lines[i][0],lines[i][1])
            xpixel2,ypixel2=converttopixel(lines[i][2],lines[i][3])
            deltax=abs(xpixel2-xpixel1)
            deltay=abs(ypixel2-ypixel1)
            if deltax==deltay==0:
                if printable(xpixel1,ypixel1):
                    plt.set_pixel(xpixel1,ypixel1,RGB(lines[i][4]))
            if deltax<=1 and deltay<=1:
                if printable(xpixel1,ypixel1):
                    plt.set_pixel(xpixel1,ypixel1,RGB(lines[i][4]))
                    plt.set_pixel(xpixel2,ypixel2,RGB(lines[i][4]))
            if deltax>=deltay and deltax!=0:
                m=(ypixel2-ypixel1)/(xpixel2-xpixel1)
                p=ypixel1-m*xpixel1
                xpixelmin=max(limits[0],min(xpixel1,xpixel2))
                xpixelmax=min(limits[2],max(xpixel1,xpixel2))
                if xpixelmin<=limits[2] and xpixelmax>=limits[0]:
                    for xpixel in range(xpixelmin,xpixelmax+1):
                        ypixel=round(m*xpixel+p)
                        if printable(xpixel,ypixel):
                            plt.set_pixel(xpixel,ypixel,RGB(lines[i][4]))
            if deltay>deltax:
                m=(xpixel2-xpixel1)/(ypixel2-ypixel1)
                p=xpixel1-m*ypixel1
                ypixelmin=max(limits[3],min(ypixel1,ypixel2))
                ypixelmax=min(limits[1],max(ypixel1,ypixel2))
                if ypixelmin<=limits[1] and ypixelmax>=limits[3]:
                    for ypixel in range(ypixelmin,ypixelmax+1):
                        xpixel=round(m*ypixel+p)
                        if printable(xpixel,ypixel):
                            plt.set_pixel(xpixel,ypixel,RGB(lines[i][4]))
    axis([limits[0]-50,limits[2],limits[1]+50,limits[3]])
    axis("off")
    plt.show_screen()
    points=[[]]
    lines=[[]]
    textes=[[]]
    xmin,xmax,ymin,ymax=0,1,0,1
    fenetre=[0,1,0,1]
    axis_display='on'
    win_scaling='init'
    color_count=0

def bar(val,eff,lar=0.8):
    val=list(val)
    eff=list(eff)
    global color_count
    if isinstance(val,(list,tuple)) and isinstance(eff,(list,tuple)):
        if len(val)==len(eff):
            for i in range(len(val)):
                plot([val[i]-lar/2,val[i]-lar/2],[0,eff[i]],color_auto[color_count%7])
                plot([val[i]+lar/2,val[i]+lar/2],[0,eff[i]],color_auto[color_count%7])
                plot([val[i]-lar/2,val[i]+lar/2],[eff[i],eff[i]],color_auto[color_count%7])
            color_count+=1
        else:
            raise ValueError('function bar() : lists must have same dimension')
    elif isinstance(val,(int,float)) and isinstance(eff,(int,float)):
        for i in range(len(val)):
            plot([val[i]-lar/2,val[i]-lar/2],[0,eff[i]],color_auto[color_count%7])
            plot([val[i]+lar/2,val[i]+lar/2],[0,eff[i]],color_auto[color_count%7])
            plot([val[i]-lar/2,val[i]+lar/2],[eff[i],eff[i]],color_auto[color_count%7])
        color_count+=1
    else:
        raise ValueError('function bar() : error using arguments or arguments not available in this version')

def scatter(xlist,ylist):
    xlist=list(xlist)
    ylist=list(ylist)
    global color_count
    if isinstance(xlist,(list,tuple)) and isinstance(ylist,(list,tuple)):
        if len(xlist)==len(ylist):
            for i in range(len(xlist)):
                plot(xlist[i],ylist[i],color_auto[color_count%7])
            color_count+=1
        else:
            raise ValueError('function scatter() : x and y must have same dimension')

    elif isinstance(xlist,(int,float)) and isinstance(ylist,(int,float)):
        plot(xlist,ylist,color_auto[color_count%7])
        color_count+=1
    else:
        raise ValueError('function scatter() : error using arguments or arguments not available in this version')

def boxplotFR(L):
    L=list(L)
    global fenetre,color_count,nbre_boite, axis_display,win_scaling
    print("boxplotFR:definition \nfrancaise du \ndiagramme en boite")
    axis_display='boxplot'
    n=len(L)
    if type(L[0])==int or type(L[0])==float:
        n=1
    nbre_boite=n
    largeur=0.3/n

    def mediane(l):
      l=sorted(l)
      r=len(l)
      if r%2==0:
         return (l[r//2]+l[r//2-1])/2
      else:
         return l[r//2]

    def quartiles(l):
      l=sorted(l)
      r=len(l)
      return (l[r//4],l[(3*r)//4])

    def deciles(l):
      l=sorted(l)
      r=len(l)
      return (l[r//10],l[(9*r)//10])

    for i in range(n):
        if n==1:
            if type(L[0])==int or type(L[0])==float:
              K=L
            else:
                K=L[0]
        else :
            K=L[i]
        if type(K)==int or type(K)==float:
            plot([i+1-largeur,i+1+largeur],[K,K],'r')
        elif type(K[0])==int or type(K[0])==float:
            K=sorted(K)
            p=len(K)
            Q1=quartiles(K)[0]
            Q3=quartiles(K)[1]
            D1=deciles(K)[0]
            D9=deciles(K)[1]
            plot([i+1-largeur,i+1+largeur,i+1+largeur,i+1-largeur,i+1-largeur],[Q1,Q1,Q3,Q3,Q1],'k')
            plot([i+1,i+1],[Q1,D1],'k')
            plot([i+1,i+1],[Q3,D9],'k')
            plot([i+1-largeur/2,i+1+largeur/2],[D1,D1],'k')
            plot([i+1-largeur/2,i+1+largeur/2],[D9,D9],'k')
            plot(i+1,K[0],'k')
            plot(i+1,K[p-1],'k')
            plot([i+1-largeur,i+1+largeur],[mediane(K),mediane(K)],'r')
        elif type(min(L[0]))!=int and type(min(L[0]))!=float:
            raise ValueError('wrong type of argument')
    if type(L[0])==int or type(L[0])==float:
        fenetre=[0,2,min(L)-1,max(L)+1]
        Max=max(L)
    else:
        Min=min(L[0])
        Max=max(L[0])
        for i in range(len(L)):
            if type(L[i])==int or type(L[i])==float:
                if L[i]<Min:
                    Min=L[i]
                if L[i]>Max:
                    Max=L[i]
            else:
                if min(L[i])<Min:
                  Min=min(L[i])
                if max(L[i])>Max:
                  Max=max(L[i])
        fenetre=[0,len(L)+1,Min-1,Max+1]
    win_scaling='fixed'
    text(len(L)+1/4,Max+1/2,"boxplotFR")

def boxplot(L,**kwargs):
    L=list(L)
    global fenetre,color_count,nbre_boite, axis_display,win_scaling
    whis=kwargs.get('whis',1.5)
    axis_display='boxplot'
    n=len(L)
    if type(L[0])==int or type(L[0])==float:
        n=1
    nbre_boite=n
    largeur=0.3/n
    def mediane(l):
        r=1
        if type(l)!=int and type(l)!=float:
            l=sorted(l)
            r=len(l)
            if r%2==0 and r//2>0:
                return (l[r//2]+l[r//2-1])/2,l[:r//2],l[r//2:]
            else:
                return l[r//2],l[:r//2],l[r//2+1:]
        return l,l,l
    if type(L[0])==int or type(L[0])==float:
        if  min(L)==max(L):
            ampl=1
        else:
            ampl=max(L)-min(L)
        fenetre=[0,2,min(L)-ampl/20,max(L)+ampl/20]
    else:
        Min=min(L[0])
        Max=max(L[0])
        for i in range(len(L)):
            if type(L[i])==int or type(L[i])==float:
                if L[i]<Min:
                    Min=L[i]
                if L[i]>Max:
                    Max=L[i]
            else:
                if min(L[i])<Min:
                  Min=min(L[i])
                if max(L[i])>Max:
                  Max=max(L[i])
        if  Min==Max:
            ampl=1
        else:
            ampl=Max-Min
        fenetre=[0,len(L)+1,Min-ampl/20,Max+ampl/20]
    win_scaling='fixed'
    for i in range(n):
        if n==1:
            if type(L[0])==int or type(L[0])==float:
              K=L
            else:
                K=L[0]
        else :
            K=L[i]
        if type(K)==int or type(K)==float:
            plot([i+1-largeur,i+1+largeur],[K,K],'r')
        elif type(K[0])==int or type(K[0])==float:
            K=sorted(K)
            p=len(K)
            Q1,Q3=mediane(mediane(K)[1])[0],mediane(mediane(K)[2])[0]
            down=0
            if Q1-whis*(Q3-Q1)<=K[0]:
                down=0
            else :
                while Q1-whis*(Q3-Q1)>K[down]:
                    down+=1
            up=p-1
            if Q3+whis*(Q3-Q1)>=K[p-1]:
                up=p-1
            else :
                while Q3+whis*(Q3-Q1)<K[up]:
                    up-=1
            plot([i+1-largeur,i+1+largeur,i+1+largeur,i+1-largeur,i+1-largeur],[Q1,Q1,Q3,Q3,Q1],'k')
            plot([i+1,i+1],[Q1,K[down]],'k')
            plot([i+1,i+1],[Q3,K[up]],'k')
            plot([i+1-largeur/2,i+1+largeur/2],[K[down],K[down]],'k')
            plot([i+1-largeur/2,i+1+largeur/2],[K[up],K[up]],'k')
            from math import pi
            from math import cos
            from math import sin
            if down>0:
             for t in range(down):
                x=[i+1+0.05*(fenetre[1])/3*cos(2*j*pi/50) for j in range(50)]
                y=[K[t]+0.05*(fenetre[3]-fenetre[2])/3*sin(2*j*pi/50) for j in range(50)]
                plot(x,y,'k')
            if up<p-1:
                for t in range(p-1-up):
                    x=[i+1+0.05*(fenetre[1])/3*cos(2*j*pi/50) for j in range(50)]
                    y=[K[p-1-t]+0.05*(fenetre[3]-fenetre[2])/3*sin(2*j*pi/50) for j in range(50)]
                    plot(x,y,'k')
            plot([i+1-largeur,i+1+largeur],[mediane(K)[0],mediane(K)[0]],'r')
        elif type(min(L[0]))!=int and type(min(L[0]))!=float:
            raise ValueError('wrong type of argument')

def arrow(x,y,dx,dy,**kwargs):
    global win_scaling
    a=x+dx
    b=y+dy
    win_scaling='fixed'
    color=kwargs.get('ec','k')
    color=kwargs.get('edgecolor',color)
    headcolor=kwargs.get('fc',color)
    headcolor=kwargs.get('facecolor',headcolor)
    L=kwargs.get('head_width',0.003)
    l=kwargs.get('head_length',1.5*L)
    plot((x,a),(y,b),color)

    def resol(A,B,C):
        D=B**2-4*A*C
        if D>0:
            return((-B-D**0.5)/(2*A),(-B+D**0.5)/(2*A))
    if dx==0:
        if dy>=0:
            c=1
        else:
            c=-1
        plot((a-L/2,a+L/2,a,a-L/2),(b,b,b+c*l,b),color)
    elif dy==0:
        if dx>=0:
            c=1
        else:
            c=-1
        plot((a,a,a+c*l,a),(b-L/2,b+L/2,b,b-L/2),color)
    else:
        m=dy/dx
        p=y-m*x
        S=resol(m**2+1,2*(-a-b*m+m*p),p**2+a**2+b**2-l**2-2*b*p)
        if S[0]*dx<0:
            X=S[0]
        else:
            X=S[1]
        Y=m*X+p
        k=b+a/m
        T=resol(1+1/m**2,2*(-a-k/m+b/m),a**2+k**2-2*b*k+b**2-(L**2)/4)
        plot((T[0],T[1],X,T[0]),(-T[0]/m+k,-T[1]/m+k,Y,-T[0]/m+k),headcolor)
Code: Select all
import casioplot as plt
limits=[40,165,384,0]
fenetre=[0,1,0,1]
points=[[]]
lines=[[]]
textes=[[]]
extrem=[0,1,0,1]
win_scaling='init'
axis_display='on'
color_auto=['b','r','g','m','k','c','y']
color_count=0
grid_display='off'
color_grid='grey'
available_colors=['b','r','g','k','m','c','y','w','blue','red','green','black','magenta','cyan','yellow','white','grey','orange','purple','brown','pink']

def axis(*L):
    global fenetre,win_scaling,axis_display
    if len(L)==1 and L[0]=='auto':
        win_scaling='auto'
    if L==() or L[0]=='auto':
        if win_scaling=='auto':
            for i in [0,2]:
                if extrem[i]==extrem[i+1]:
                    if extrem[i]==0:
                        fenetre[i:i+2]=[-0.05,0.05]
                    else:
                        fenetre[i:i+2]=[extrem[i]-0.05*abs(extrem[i]),extrem[i]+0.05*abs(extrem[i])]
                else:
                    fenetre[i:i+2]=[1.05*extrem[i]-0.05*extrem[i+1],1.05*extrem[i+1]-0.05*extrem[i]]
        return fenetre
    elif isinstance(L[0],(list,tuple)) and len(L[0])==4:
        fenetre=list(L[0])
        if fenetre[0]==fenetre[1]:
            if fenetre[0]==0:
                fenetre[0:2]=[-0.05,0.05]
            else:
                fenetre[0:2]=[0.95*fenetre[0],1.05*fenetre[0]]
            print('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
        if fenetre[2]==fenetre[3]:
            if fenetre[2]==0:
                fenetre[2:4]=[-0.05,0.05]
            else:
                fenetre[2:4]=[0.95*fenetre[2],1.05*fenetre[2]]
            print('Userwarning: attempting to set identical bottom == top in function axis(); automatically expanding.')
        win_scaling='fixed'
        axis_display='on'
        return fenetre
    elif L[0]=='off':
        axis_display='off'
    elif L[0]=='on':
        axis_display='on'
    else:
        raise Exception('function axis() : error using arguments')

def text(x,y,txt):
    global textes
    txt=str(txt)
    if textes==[[]]:
        textes[0]=[x,y,txt]
    else:
        if [x,y,txt] not in textes :
            textes+=[[x,y,txt]]

def plot(*L,**kwargs):
    global color_count,win_scaling
    def plotpoint(x,y,c):
        global points,extrem,win_scaling
        if points==[[]] and lines==[[]]:
            points[0]=[x,y,c]
            extrem=[x,x,y,y]
        else:
            if [x,y,c] not in points :
                points+=[[x,y,c]]
                extrem=[min(x,extrem[0]),max(x,extrem[1]),min(y,extrem[2]),max(y,extrem[3])]
        if win_scaling=='init':
            win_scaling='auto'

    def plotline(x1,y1,x2,y2,c):
        global lines,extrem,win_scaling
        if lines==[[]] and points==[[]]:
            lines[0]=[x1,y1,x2,y2,c]
            extrem=[min(x1,x2),max(x1,x2),min(y1,y2),max(y1,y2)]
        else:
            if [x1,y1,x2,y2,c] not in lines :
                lines+=[[x1,y1,x2,y2,c]]
                extrem=[min(x1,x2,extrem[0]),max(x1,x2,extrem[1]),min(y1,y2,extrem[2]),max(y1,y2,extrem[3])]
        if win_scaling=='init':
            win_scaling='auto'

    def auto(c):
        global color_count
        if (c != None and len(c)==2 and c[0] in available_colors and c[1] in ['o','.','+','*','-']):
            c=c[0]
        if c in [None,'o','.','+','*','-']:
            color=color_auto[color_count%7]
            color_count+=1
            return color
        else:
            return c

    def testcolor(c):
        if (len(c)==2 and c[0] in available_colors and c[1] in ['o','.','+','*','-']) or (c in available_colors+['o','.','+','*','-']) :
            return True
        else:
            raise ValueError('function plot() : unknown color code')

    color=kwargs.get('color',None)
    if color!=None and not color in available_colors:
        raise ValueError('function plot() : unknown color code')
    if len(L)==2 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)):
        plotpoint(L[0],L[1],auto(color))
    elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)):
        if (len(L[0])==len(L[1])):
            c=auto(color)
            for i in range(len(L[0])-1):
                plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],c)
        else:
            raise ValueError('function plot() : x and y must have same dimension')
    elif len(L)==1 and isinstance(L[0],(list,tuple)):
        c=auto(color)
        for i in range(len(L[0])-1):
            plotline(i,L[0][i],i+1,L[0][i+1],c)
    elif len(L)==3 and isinstance(L[0],(int,float)) and isinstance(L[1],(int,float)) and isinstance(L[2],(str)):
        if testcolor(L[2])==True:
            plotpoint(L[0],L[1],auto(L[2]))
    elif len(L)==3 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(list,tuple)) and isinstance(L[2],(str)):
        if (len(L[0])==len(L[1])):
            if testcolor(L[2])==True :
                c=auto(L[2])
                for i in range(len(L[0])-1):
                    plotline(L[0][i],L[1][i],L[0][i+1],L[1][i+1],c)
        else:
            raise ValueError('function plot() : x and y must have same dimension')
    elif len(L)==2 and isinstance(L[0],(list,tuple)) and isinstance(L[1],(str)):
        if testcolor(L[1])==True :
            c=auto(L[1])
            for i in range(len(L[0])-1):
                plotline(i,L[0][i],i+1,L[0][i+1],c)
    else:
        raise Exception('function plot() : error using arguments')
def show():
    global fenetre, limits, points, lines, textes, extrem, win_scaling, axis_display, color_count, color_grid, grid_display
    def RGB(c):
        colornames={"black":(0,0,0),"k":(0,0,0),"blue":(0,0,255),"b":(0,0,255),"green":(0,255,0),"g":(0,255,0),"red":(255,0,0),"r":(255,0,0),"cyan":(0,255,255),"c":(0,255,255),"yellow":(255,255,0),"y":(255,255,0),"magenta":(255,0,255),"m":(255,0,255),"white":(255,255,255),"w":(255,255,255),"orange":(255,166,0),"purple":(128,0,128),"brown":(166,42,42),"pink":(255,192,202),"grey":(215,215,215)}
        if c in colornames:
            return colornames[c]
        else:
            raise ValueError("invalid color code")

    def printable(X):
        global limits
        return(limits[0]<=X[0]<=limits[2] and limits[3]<=X[1]<=limits[1])
    def echelle(a,b):
        k=0
        e=abs(b-a)
        while e>=10 :
            e/=10
            k+=1
        while e<1 :
            e*=10
            k-=1
        return k
    def pas(a,b):
        pas=10**echelle(a,b)
        while (abs(b-a))//pas<4:
            pas/=2
        return pas
    def converttopixel(X):
        global fenetre,limits
        ax=(limits[2]-limits[0])/(fenetre[1]-fenetre[0])
        bx=limits[0]-ax*fenetre[0]
        xpixel=round(ax*X[0]+bx)
        ay=(limits[3]-limits[1])/(fenetre[3]-fenetre[2])
        by=limits[1]-ay*fenetre[2]
        ypixel=round(ay*X[1]+by)
        return [xpixel,ypixel]
    color_count=0
    plt.clear_screen()
    if win_scaling=='auto':
        for i in [0,2]:
            if extrem[i]==extrem[i+1]:
                if extrem[i]==0:
                    fenetre[i:i+2]=[-0.05,0.05]
                else:
                    fenetre[i:i+2]=[extrem[i]-0.05*abs(extrem[i]),extrem[i]+0.05*abs(extrem[i])]
            else:
                fenetre[i:i+2]=[1.05*extrem[i]-0.05*extrem[i+1],1.05*extrem[i+1]-0.05*extrem[i]]
    if axis_display=='on' or axis_display=='boxplot':
        for i in range(limits[0],limits[2]+1):
            plt.set_pixel(i,limits[1],RGB("k"))
        for j in range(limits[3],limits[1]+1):
            plt.set_pixel(limits[0],j,RGB("k"))
        fenetreb=sorted([fenetre[0],fenetre[1]])+sorted([fenetre[2],fenetre[3]])
        pasx=pas(fenetreb[0],fenetreb[1])
        pasy=pas(fenetreb[2],fenetreb[3])
        gx=round(fenetreb[0],-echelle(fenetreb[0],fenetreb[1]))
        gy=round(fenetreb[2],-echelle(fenetreb[2],fenetreb[3]))
        if axis_display=='boxplot':
            for i in range(nbre_boite):
                pix=converttopixel((i+1,fenetre[2]))
                plt.set_pixel(pix[0],pix[1]+1,RGB("k"))
                plt.set_pixel(pix[0],pix[1]+2,RGB("k"))
                plt.set_pixel(pix[0],pix[1]+3,RGB("k"))
                plt.draw_string(pix[0],pix[1]+13,str(i+1),[0,0,0],"small")
        else :
            for i in range(-10,10):
                x=gx+i*pasx
                pix=converttopixel((x,fenetre[2]))
                if printable(pix):
                    plt.set_pixel(pix[0],pix[1]+1,RGB("k"))
                    plt.set_pixel(pix[0],pix[1]+2,RGB("k"))
                    plt.set_pixel(pix[0],pix[1]+3,RGB("k"))
                    plt.set_pixel(pix[0],pix[1]+1,(1,1,1))
                    if grid_display=='on':
                        for z in range(1,165):
                            if pix[0]!=limits[0]:
                              plt.set_pixel(pix[0],pix[1]-z,RGB(color_grid))
                    plt.draw_string(pix[0],pix[1]+13,'{:.4g}'.format(x),[0,0,0],"small")
        for j in range(-10,10):
            y=gy+j*pasy
            pix=converttopixel((fenetre[0],y))
            if printable(pix):
                plt.set_pixel(pix[0]-1,pix[1],RGB("k"))
                plt.set_pixel(pix[0]-2,pix[1],RGB("k"))
                plt.set_pixel(pix[0]-3,pix[1],RGB("k"))
                if grid_display=='on':
                    for z in range(1,340):
                        if pix[1]!=limits[1]:
                          plt.set_pixel(pix[0]+z,pix[1],RGB(color_grid))
                plt.draw_string(pix[0]-40,pix[1],'{:.4g}'.format(y),[0,0,0],"small")
    if points!=[[]]:
        if points[0]==[]:
            del points[0]
        for i in range(len(points)):
            pix=converttopixel((points[i][0],points[i][1]))
            if printable(pix) and points[i][2]!=None:
                for j in range(-2,3):
                    plt.set_pixel(pix[0]+j,pix[1],RGB(points[i][2]))
                    plt.set_pixel(pix[0],pix[1]+j,RGB(points[i][2]))
    if textes!=[[]]:
        if textes[0]==[]:
            del textes[0]
        for i in range(len(textes)):
            pix=converttopixel((textes[i][0],textes[i][1]))
            if printable(pix):
                plt.draw_string(pix[0],pix[1],textes[i][2],[0,0,0],"small")
    if lines!=[[]]:
        if lines[0]==[]:
            del lines[0]
        for i in range(len(lines)):
            pixels=[converttopixel((lines[i][j],lines[i][j+1])) for j in [0,2]]
            deltax=abs(pixels[1][0]-pixels[0][0])
            deltay=abs(pixels[1][1]-pixels[0][1])
            if deltax<=1 and deltay<=1:
                if printable((pixels[0][0],pixels[0][1])):
                    plt.set_pixel(pixels[0][0],pixels[0][1],RGB(lines[i][4]))
                    plt.set_pixel(pixels[1][0],pixels[1][1],RGB(lines[i][4]))
            else:
                if deltax>=deltay:
                    j=0
                else:
                    j=1
                m=(pixels[1][1-j]-pixels[0][1-j])/(pixels[1][j]-pixels[0][j])
                p=pixels[0][1-j]-m*pixels[0][j]
                pix_extrem=(max(limits[0],min(pixels[0][0],pixels[1][0])),min(limits[2],max(pixels[0][0],pixels[1][0])),max(limits[3],min(pixels[0][1],pixels[1][1])),min(limits[1],max(pixels[0][1],pixels[1][1])))
                if pix_extrem[2*j]<=limits[2-j] and pix_extrem[2*j+1]>=limits[-j]:
                    pix=[0,0]
                    for pix[j] in range(pix_extrem[2*j],pix_extrem[2*j+1]+1):
                        pix[1-j]=round(m*pix[j]+p)
                        if printable(pix):
                            plt.set_pixel(pix[0],pix[1],RGB(lines[i][4]))
    axis([limits[0]-50,limits[2],limits[1]+50,limits[3]])
    axis("off")
    plt.show_screen()
    points=[[]]
    lines=[[]]
    textes=[[]]
    extrem=[0,1,0,1]
    fenetre=[0,1,0,1]
    axis_display='on'
    win_scaling='init'
    color_count=0
    grid_display='off'

def bar(val,eff,width=0.8):
    global color_count
    if isinstance(val,(tuple)):
        val=list(val)
    if isinstance(eff,(tuple)):
        eff=list(eff)
    if isinstance(val,(int,float)):
        val=[val]
    if isinstance(eff,(int,float)):
        eff=[eff]
    if isinstance(val,(list)) and isinstance(eff,(list)):
        if len(val)==len(eff):
            for i in range(len(val)):
                plot([val[i]-width/2,val[i]-width/2],[0,eff[i]],color_auto[color_count%7])
                plot([val[i]+width/2,val[i]+width/2],[0,eff[i]],color_auto[color_count%7])
                plot([val[i]-width/2,val[i]+width/2],[eff[i],eff[i]],color_auto[color_count%7])
            color_count+=1
        else:
            raise ValueError('function bar() : lists must have same dimension')
    else:
        raise ValueError('function bar() : error using arguments')

def scatter(xlist,ylist):
    global color_count
    if isinstance(xlist,(tuple)):
        xlist=list(xlist)
    if isinstance(ylist,(tuple)):
        ylist=list(ylist)
    if isinstance(xlist,(int,float)):
        xlist=[xlist]
    if isinstance(ylist,(int,float)):
        ylist=[ylist]
    if isinstance(xlist,(list)) and isinstance(ylist,(list)):
        if len(xlist)==len(ylist):
            for i in range(len(xlist)):
                plot(xlist[i],ylist[i],color_auto[color_count%7])
            color_count+=1
        else:
            raise ValueError('function scatter() : x and y lists must have same dimension')
    else:
        raise ValueError('function scatter() : error using arguments')

def hist(x,bins=10,**kwargs):
    global color_count
    hist_type=kwargs.get('hist_type','std')
    if hist_type not in ['fr','std']:
        raise ValueError('function hist() : hist_type must be std or fr')
    if isinstance(x,(tuple,list)):
        x=sorted(list(x))
    if isinstance(bins,(tuple)):
        bins=list(bins)
    if isinstance(x,(int,float)):
        x=[x]
    if isinstance(bins,(int)) and bins>=1:
        if x[-1]!=x[0]:
            bins=[round(x[0]+k*(x[-1]-x[0])/bins,8) for k in range(bins+1)]
        else :
            bins=[round(x[0]-0.5+k/bins,8) for k in range(bins+1)]
    if isinstance(bins,(list)) and bins!=[]:
        bins=sorted(bins)
        qt=[]
        for i in range(len(bins)-1):
            if i==len(bins)-2:
                eff=len([val for val in x if bins[i]<=val<=bins[i+1]])
            else:
                eff=len([val for val in x if bins[i]<=val<bins[i+1]])
            if hist_type=='fr':
                if abs(bins[i+1]-bins[i])>1e-8:
                    eff=eff/(bins[i+1]-bins[i])
                else :
                    raise ValueError('function hist(,hist_type=''fr'') : bins cannot contain 2 identical values')
            qt+=[eff]
            plot([bins[i],bins[i],bins[i+1],bins[i+1]],[0,eff,eff,0],color_auto[color_count%7])
        color_count+=1
    else:
        raise ValueError('function hist() : error using arguments')
    return qt,bins

def boxplot(L,**kwargs):
    L=list(L)
    global fenetre,nbre_boite,color_count,axis_display,win_scaling
    boxplot_type=kwargs.get('boxplot_type','std')
    if boxplot_type not in ['fr','std']:
        raise ValueError('function boxplot() : boxplot_type must be std or fr')
    def mediane(l,p):
        if p%2==0:
            return (l[p//2]+l[p//2-1])/2
        else:
            return l[p//2]
    def quantiles(l,p,r):
        if boxplot_type=='fr':
            if p%r==0:
                return (l[p//r-1],l[((r-1)*p)//r-1])
            else:
                return (l[p//r],l[((r-1)*p)//r])
        if boxplot_type=='std':
            def percentile(N, q):
                k = (len(N)-1) * q
                f = int(k)
                c = int(k)+1
                if f == k:
                    return N[int(k)]
                d0 = N[f] * (c-k)
                d1 = N[c] * (k-f)
                return d0+d1
            return (percentile(l,0.25),percentile(l,0.75))
    whis=kwargs.get('whis',1.5)
    if whis<0:
        whis=0
    axis_display='boxplot'
    n=len(L)
    if isinstance(L[0],(int,float)):
        n=1
        Max,Min=max(L),min(L)
        if  Max==Min:
            ampl=1
        else:
            ampl=Max-Min
        fenetre=[0,2,Min-ampl/20,Max+ampl/20]
    else:
        Max,Min=max([max(L[i]) for i in range(len(L))]),min([min(L[i]) for i in range(len(L))])
        if  Min==Max:
            ampl=1
        else:
            ampl=Max-Min
        fenetre=[0,len(L)+1,Min-ampl/20,Max+ampl/20]
    nbre_boite,largeur=n,0.3/n
    win_scaling='fixed'
    for i in range(n):
        if n==1:
            if isinstance(L[0],(int,float)):
                K=L
            else:
                K=L[0]
        else :
            K=L[i]
        if isinstance(K,(int,float)):
            plot([i+1-largeur,i+1+largeur],[K,K],'r')
        elif isinstance(K[0],(int,float)):
            K,p=sorted(K),len(K)
            med=mediane(K,p)
            Q1,Q3=quantiles(K,p,4)
            if boxplot_type=='std':
                down,up=0,p-1
                while Q1-whis*(Q3-Q1)>K[down]:
                    down+=1
                while Q3+whis*(Q3-Q1)<K[up]:
                    up-=1
                left_whis,right_whis=K[down],K[up]
                if Q1<K[down]:
                    left_whis=Q1
                if Q3>K[up]:
                    right_whis=Q3
            if boxplot_type=='fr':
                D1,D9=quantiles(K,p,10)
                down=K.index(D1)
                up=K.index(D9)
                left_whis,right_whis=K[down],K[up]
                while(up<p-1 and K[up]==K[up+1]):
                  up=up+1
                  right_whis=K[up]
            plot([i+1-largeur,i+1+largeur,i+1+largeur,i+1-largeur,i+1-largeur],[Q1,Q1,Q3,Q3,Q1],'k')
            plot([i+1,i+1],[Q1,left_whis],'k')
            plot([i+1,i+1],[Q3,right_whis],'k')
            plot([i+1-largeur/2,i+1+largeur/2],[left_whis,left_whis],'k')
            plot([i+1-largeur/2,i+1+largeur/2],[right_whis,right_whis],'k')
            if down>0 or up<p-1:
                from math import pi,cos,sin
                Z=[i for i in range(down)]+[j for j in range(up+1,p)]
                for t in Z:
                    x=[i+1+0.05*(fenetre[1])/3*cos(2*j*pi/50) for j in range(50)]
                    y=[K[t]+0.05*(fenetre[3]-fenetre[2])/3*sin(2*j*pi/50) for j in range(50)]
                    plot(x,y,'k')
            plot([i+1-largeur,i+1+largeur],[med,med],'r')
        else:
            raise ValueError('wrong type of argument')

def arrow(x,y,dx,dy,**kwargs):
    global win_scaling
    a,b=x+dx,y+dy
    win_scaling='fixed'
    color=kwargs.get('ec','k')
    color=kwargs.get('edgecolor',color)
    headcolor=kwargs.get('fc','b')
    headcolor=kwargs.get('facecolor',headcolor)
    L=kwargs.get('head_width',0.003)
    l=kwargs.get('head_length',1.5*L)
    plot((x,a),(y,b),color)

    def resol(A,B,C):
        D=B**2-4*A*C
        if D>0:
            return((-B-D**0.5)/(2*A),(-B+D**0.5)/(2*A))
    if abs(dx)<0.00001:
        dx=0
    if dx==0:
        if dy>=0:
            c=1
        else:
            c=-1
        plot((a-L/2,a+L/2,a,a-L/2),(b,b,b+c*l,b),color)
        for i in range(15):
            plot((a-(i/15)*L/2,a-(i/15)*L/2),(b,b+(15-i)/15*c*l),headcolor)
            plot((a+i/15*L/2,a+i/15*L/2),(b,b+(15-i)/15*c*l),headcolor)
    elif dy==0:
        if dx>=0:
            c=1
        else:
            c=-1
        plot((a,a,a+c*l,a),(b-L/2,b+L/2,b,b-L/2),color)
        for i in range(15):
            plot((a,a+(15-i)/15*c*l),(b-i/15*L/2,b-i/15*L/2),headcolor)
            plot((a,a+(15-i)/15*c*l),(b+i/15*L/2,b+i/15*L/2),headcolor)
    else:
        m=dy/dx
        p=y-m*x
        S=resol(m**2+1,2*(-a-b*m+m*p),p**2+a**2+b**2-l**2-2*b*p)
        if (a-S[0])*dx<0:
            X=S[0]
        else:
            X=S[1]
        Y=m*X+p
        k=b+a/m
        T=resol(1+1/m**2,2*(-a-k/m+b/m),a**2+k**2-2*b*k+b**2-(L**2)/4)
        plot((T[0],T[1],X,T[0]),(-T[0]/m+k,-T[1]/m+k,Y,-T[0]/m+k),color)
        plot((a,X),(b,Y),headcolor)
        listeX=[]
        listeY=[]
        if abs(X-T[0])<0.000001:
            for i in range(15):
                listeX+=[T[0]+i*(a-T[0])/15]+[T[0]]
                listeY+=[-listeX[2*i]/m+k]+[-T[0]/m+k+i*(Y+T[0]/m-k)/15]
        else:
            M=(Y+T[0]/m-k)/(X-T[0])
            P=Y-M*X
            for i in range(15):
                listeX+=[T[0]+i*(a-T[0])/15]+[T[0]+i*(X-T[0])/15]
                listeY+=[-listeX[2*i]/m+k]+[listeX[2*i+1]*M+P]
        plot(listeX,listeY,headcolor)
        listeX=[]
        listeY=[]
        if abs(X-T[1])<0.000001:
            for i in range(15):
                listeX+=[T[1]+i*(a-T[1])/15]+[T[1]]
                listeY+=[-listeX[2*i]/m+k]+[-T[1]/m+k+i*(Y+T[1]/m-k)/15]
        else:
            M=(Y+T[1]/m-k)/(X-T[1])
            P=Y-M*X
            for i in range(15):
                listeX+=[T[1]+i*(a-T[1])/15]+[T[1]+i*(X-T[1])/15]
                listeY+=[-listeX[2*i]/m+k]+[listeX[2*i+1]*M+P]
        plot(listeX,listeY,headcolor)

def grid(*a,**kwargs):
    global color_grid,grid_display
    color=kwargs.get('color',None)
    if a==():
        affichage=a
    else:
        affichage=a[0]
    if color!=None:
        color_grid=color
        affichage='on'
    if color not in available_colors:
        color_grid='grey'
    if affichage==():
        if grid_display=='on':
            grid_display='off'
        else:
            grid_display='on'
    elif affichage=='on' or affichage=='True' or affichage==True or affichage=='true':
        grid_display='on'
    elif affichage=='off' or affichage=='False' or affichage==False or affichage=='false':
        grid_display='off'
    else:
        raise ValueError('string must be one of : "on","off","True",or "False"')


Donc quelles nouveautés dans tout ça ? Revenons sur le tracé de diagrammes en boîte à l'aide de la fonction boxplot() :
ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
try:
  from matplotlib.pyplot import *
except ImportError:
  from matplotl import *

Val=[1,2,2,11,8,9,15,18,20,9,2,5,6,7,8,9,5,9]

boxplot(Val)
show()

Petit problème concernant donc la fonction boxplot() standard de matplotlib.pyplot, les diagrammes en boîte qu'elle trace ne sont pas conformes à ceux enseignés au lycée français.
Afin d'y remédier, Casio avait ajouté avec sa propre fonction boxplotFR().
On pouvait toutefois regretter un écart par rapport au standard.

Dans le nouveau matplotlib.pyplot intégré, Casio fait un effort sur ce dernier point. La fonction boxplotFR() est supprimée, remplacée par un paramètre nommé boxplot_type pouvant être passé à la fonction boxplot(), pouvant prendre les valeurs "std" ou "fr". :)
L'appel équivalent à boxplotFR(l) est donc boxplot(l, boxplot_type="fr") avec la nouvelle version.

Nous avons donc vu plus haut le diagramme en barres à l'aide de la fonction bar(). Et bien grosse nouveauté du matplotlib.pyplot intégré, nous avons droit à une nouvelle fonction cette fois-ci pour les histogrammes, hist() : :bj:
ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
from matplotlib.pyplot import *

x = [119.1, 119.3, 119.5, 119.6, 119.9, 120.0, 120.1, 120.3, 120.4]
y = [1, 3, 4, 3, 1, 3, 1, 3, 1]

l = []
for i in range(len(x)):
  for j in range(y[i]):
    l.append(x[i])

hist(l)
show()

Si tu regardes bien, tu noteras que la fonction hist() de matplotlib.pyplot ne respecte pas la définition française des histogrammes, à savoir que c'est l'aire des bandes qui indique la valeur.

Et bien nouvel effort remarquable de Casio pour concilier le standard matplotlib.pyplot et l'enseignement français, il te suffira ici encore de passer le paramètre nommé hist_type="fr" pour obtenir le bon histogramme. :)

Autre ajout, la fonction grid() pour tracer un quadrillage : :)
ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
from matplotlib.pyplot import *

x = [1, 2, 3, 4, 5, 6, 7]
y = [12, 17, 35, 29, 13, 9, 5]
bar(x, y, 0.5)
grid()
show()

Peut-être serait-il bon de remplir les barres afin d'en faciliter la lecture graphique, notamment sur Graph 90+E.

Nous avons également plusieurs corrections de bugs, sur les fonctions axis(), boxplot() et arrow() entre autres.

Intéressons-nous à la fonction arrow() :
ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
from matplotlib.pyplot import *

arrow(0,0,.6,.6,head_width=.4,head_length=.5)
show()

Casio nous offrait donc déjà le tracé de pointes de flèches de vecteurs le plus proche du standard.

Toutefois, Casio a quand même souhaité améliorer la chose. Avec le nouveau matplotlib.pyplot intégré de la Graph 90+E, ces pointes font l'objet d'un remplissage.

Ce n'est pas le plus embêtant, nous allons y venir, mais cet ajout est assez gourmand en temps d'exécution. Le tracé de notre exemple de vecteur nécessite dans les 2,5s avec l'ancien matplotl.py additionnel, et désormais 7s avec le nouveau matplotlib.pyplot intégré.

Nous avions déjà noté plusieurs bugs concernant la fonction arrow() :
  • pointe de flèche tracée de la mauvaise couleur dans certains cas
  • pointe de flèche tracée à l'envers dans certains cas
ordi
Graph 90+E
Graph 35+E II
NumWorks


Code: Select all
try:
  from matplotlib.pyplot import *
except ImportError:
  from matplotl import *
from math import cos, sin, pi, sqrt

def radians(x):
  return x * pi / 180

def autoround(x):
  xr = round(x, 0)
  if abs(x - xr) < 10 ** -15:
    x = xr
  return x

def rotarrow(x0, y0, rx, ry, ts, ec, fc):
  hw = sqrt(rx * ry) * ts / 100
  hl = hw * 2
  for k in range(0, 360, ts):
    kr = radians(k)
    w, h = autoround(rx * cos(kr)), autoround(ry * sin(kr))
    arrow(x0, y0, w, h, head_width=hw, head_length=hl, edgecolor=ec, facecolor=fc)

rotarrow(.25, 0, .7, .7, 15, 'r', 'b')
axis([-.65,1.15,-1,1])
show()

La nouvelle version matplotlib.pyplot intégrée corrige ces problèmes ! :bj:

Quelque chose de bien embêtant par contre, et que ce changement sur arrow() met en évidence, c'est que malgré les 1 Mio de heap (tas) de la Graph 90+E nous ne sommes pas loin d'une erreur de mémoire à l'exécution.

Réduisons progressivement le pas angulaire dans notre appel de rotarrow(), 15, 14, 13... 12 pour le tracé d'un champ radial de
$mathjax$\frac{360}{12}=30$mathjax$
vecteurs marche encore.
Et puis soudainement avec 11 pour le tracé d'un champ de 32 vecteurs, ça ne marche plus avec le nouveau matplotlib.pyplot intégré, alors que cela fonctionnait parfaitement avec l'ancien matplotl.py additionnel. :o

Un champ d'une 30aine de vecteurs, ce n'est pas inimaginable en Physique-Chimie, c'est bien embêtant.

Et ce n'est pas juste une légère variation de la limite, avec l'ancien matplotl.py additionnel aucun problème pour 180 vecteurs.

Mais que se passe-t-il ?

Selon notre analyse rapide du code Python de matplotlib.pyplot, tout vient du fait que les tracés sont différés, uniquement effectués à l'appel de show().
Tous nos appels rajoutent à des listes globales de primitives à tracer (points, lines, textes...).
Et avec le nouveau matplotlib.pyplot intégré viennent plein d'éléments supplémentaires dans la liste lines afin de remplir les différentes pointes de flèches de vecteurs.

Or comme matplotlib.pyplot est écrit en Python, ces listes globales sont des objets Python, et par conséquent comme nous l'avons déjà vu maintes fois ils sont très gourmands en mémoire.

Casio gagnerait sans doute soit à optimiser ce stockage global, soit à passer à une implémentation native de matplotlib.pyplot maintenant que c'est de toutes façons intégré au système. Ce sera certes dommage pour nous de ne plus avoir accès au code source, mais si cela peut arranger les utilisateurs c'est l'essentiel.




8) Bilan modules Python

Go to top

Suite à ces ajouts Python majeurs, petit bilan de la richesse des solutions Python disponibles sur calculatrices.

Nous compterons les éléments offerts par chaque module à l'aide des scripts suivants :
Code: Select all
from autopfrm import *

pf = get_pf()
sh_inf = shell_infos(pf)

unsafe = ()
if pf == 4: #HP Prime
  unsafe = ('count','encode','endswith','find','format','index','islower','lstrip','replace','rfind','rindex','rsplit','rstrip','split','splitlines','startswith','strip','from_bytes','to_bytes','fromkeys','get','pop','setdefault','update','values','sort','__enter__','__exit__','read','readinto','readline','seek','write')
if pf == 5 or pf == 7 or pf == 9: #CasioPython / Nspire+NumWorks KhiCAS MicroPython
  unsafe = ('sys.argv', 'sys.path')

if pf >= 0:
  curline=0
  _p = print
  def print(*ls):
    global curline
    st=""
    for s in ls:
      if not(isinstance(s,str)):
        s=str(s)
      st=st+s
    stlines=1
    if sh_inf[1]:
        stlines += sh_inf[2]*int(len(st)/sh_inf[1])
    if curline+stlines>=sh_inf[0]:
      input("Input to continue:")
      curline=0
    _p(st)
    curline+=stlines

def sstr(obj):
  try:
    s=obj.__name__
  except:
    s=str(obj)
    a=s.find("'")
    b=s.rfind("'")
    if a>=0 and b!=a:
      s=s[a+1:b]
  return s

def isExplorable(obj):
  if str(obj).startswith("<module"): return False
  l = ()
  try: l = dir(obj)
  except: pass
  return len(l)

def explmodr(pitm, pitm_name_l=[], pitm_str_l=[], pitm_val_l=[], reset=True):
  global curline, found
  pitm_name=sstr(pitm)
  if(reset):
    curline=0
    found = []
    pitm_name_l=[pitm_name]
    pitm_str_l=[str(pitm)]
    pitm_val_l=[pitm]
  hd="."*(len(pitm_name_l)-1)
  c = 0
  l = sorted(dir(pitm))
  for i in range(len(l)):
    l[i] = (l[i], getattr(pitm, l[i]), str(l[i]))
  try:
    if not isinstanceof(pitm, str):
      for i in range(len(pitm)):
        l.append((pitm_name+'['+str(i)+']',pitm[i],str(pitm[i])))
  except: pass
  for itm in l:
    isFound = itm[0] in found
    c += not isFound
    isUnsafe = '.'.join(pitm_name_l + [itm[0]]) in unsafe or itm[0] in unsafe
    try:
      if isUnsafe: raise Exception
      print(hd+itm[0]+"="+str(itm[1]))
    except:
      print(hd+itm[0])
    if not isFound:
      found.append(itm[0])
    if not isUnsafe and isExplorable(itm[1]) and itm[1] not in pitm_val_l and itm[2] not in pitm_str_l:
      pitm_name_l2, pitm_val_l2, pitm_str_l2 = pitm_name_l.copy(), pitm_val_l.copy(), pitm_str_l.copy()
      pitm_name_l2.append(itm[0])
      pitm_val_l2.append(itm[1])
      pitm_str_l2.append(itm[2])
      c += explmodr(itm[1], pitm_name_l2, pitm_str_l2, pitm_val_l2, False)
  return c

def explmod(s):
  global found
  module = __import__(s)
  found = []
  return explmodr(module)
Code: Select all
# detects calculator Python platform
def get_pf():
  c256 = True
  try:
    if chr(256)==chr(0):
      # Xcas/KhiCAS Python compatibility
      if "HP" in version():
        return 13 # HP Prime
      else:
        if not white:
          return 12 # Graph 35+E II
        elif "Numworks" in version():
          return 10 # NumWorks
        elif "Nspire" in version():
          return 8 # Nspire
        else: # Graph 90+E
          return 11
  except:
    c256 = False
  try:
    import sys
    try:
      if sys.platform == "nspire":
        try: # Nspire Ndless
          import graphic
          return 7 # KhiCAS Micropython
        except: # MicroPython
          return 6
      elif sys.platform == "TI-Nspire":
        return 3 # Nspire CX II
      elif sys.platform == "numworks":
        return 9 # NumWorks KhiCAS Micropython
      elif sys.platform.startswith('TI-Python'):
        return 2 # 83P/84+ CE
    except: # Graph 35+E/USB / 75/85/95
      return 5
  except:
    pass
  if not c256:
    return 1 # Graph 90/35+E II
  try:
    import kandinsky
    return 0 # NumWorks
  except:
    try: # HP Prime
      import hpprime
      return 4
    except:
      pass
  return -1

#return get_pixel and set_pixel functions for the platform
gp_prime = lambda x, y: GETPIX_P(x, y)
sp_prime = lambda x, y, c: PIXON_P(x, y, c)
def get_pixel_functions(pf):
  gp, sp = lambda: None, lambda: None
  if pf == 0: # NumWorks
    import kandinsky
    gp, sp = kandinsky.get_pixel, kandinsky.set_pixel
  elif pf == 1: # Graph 90/35+E II
    import casioplot
    gp, sp = casioplot.get_pixel, casioplot.set_pixel
  elif pf == 2: # 83P/84+ CE
    import ti_graphics
    gp, sp = ti_graphics.getPixel, ti_graphics.setPixel
  elif pf == 3: # Nspire CX II
    pass
  elif pf == 4: # HP Prime
    import hpprime
    sp = hpprime.pixon
  elif pf == 6: # Nspire: Ndless MicroPython
    from nsp import Texture
    canvas = Texture(320, 240, 0)
    gp, sp = canvas.getPx, canvas.setPx
  elif pf == 7 or pf == 9: # Nspire/NumWorks: KhiCAS-MicroPython
    import graphic
    gp, sp = graphic.get_pixel, graphic.set_pixel
  elif pf == 13: # HP Prime
    gp, sp = gp_prime, sp_prime
  return gp, sp

#returns platform shell infos : visible lines, visible columns, if larger strings are displayed on several lines or not
def shell_infos(pf):
  #NW small: [00] 12.5x30 -> 16   x 42
  #HP small: [03] 11.5x39 -> 15.5 x 45 [12] 14  x39 -> 18.5 x 45
  #HP big  : [03] 11.5x39 -> 09   x 35 [12] 14  x39 -> 11   x 35
  #                                       uPy     uPy
  #               G352            CPy uPy KhiCAS--------------->  CAS
  #           NW  G90 CE  CX2 HP  GXX NS  NS  NS  NW  NW  G90 G352HP
  l_vlines = (12, 07, 11, 11, 12, 09, 29, 11, 11, 11, 11, 09, 07, 14)
  l_vcols =  (30, 21, 32, 00, 39, 32, 53, 32, 32, 29, 29, 30, 19, 39)
  b_vcr = 0b1111100
  if pf >= 0:
    return l_vlines[pf], l_vcols[pf], b_vcr // 2**pf % 2
  else:
    return max(l_vlines), max(l_vcols), 1


L'appel explmod('nom_module') explore le module en question et en compte les différents éléments internes, en évitant les doublons. Nous noterons en rouge les modules inaccessibles en mode examen :
TI-
83PCE
TI-
Python
TI-
83PCE
Edition
Python
TI-
84+CE-T
Python
Edition
TI-
Nspire
CX II
Casio
Graph
90+E
35+E II
Num
Works
HP
Prime

α
TI-
83PCE
TI-
Python

tiers
TI-
Nspire
CX

Ndless
χCAS
Casio
Graph
35/75+E
35+E II

CasioPython
Num
Works

Ω
Num
Works

Ω
χCAS
builtins
array
(u)binascii
board
cmath
(u)collections
(u)ctypes
(u)errno
gc
(u)hashlib
(u)heapq
(u)io
(u)json
linalg
math
matplotlib
.pyplot
micropython
numpy
os
(u)random
(u)re
storage
(u)struct
sys
time
(u)timeq
turtle
(u)zlib
TOTAL
152
26
.
.
.
24
.
.
29
.
.
.
.
.
50
.
.
.
.
.
30
.
.
.
68
26
.
.
.
405
153
26
.
.
.
24
.
.
29
.
.
.
.
.
50
.
.
.
.
.
30
.
.
.
68
26
.
.
.
406
153
26
.
.
.
24
.
.
29
.
.
.
.
.
50
.
.
.
.
.
30
.
.
.
68
28
.
.
.
406
166
33
33
.
40
48
60
68
36
32
32
.
.
.
69
.
.
41
.
.
36
35
.
.
80
40
.
.
.
849
141
.
.
.
.
.
.
.
.
.
.
.
.
.
47
24
59
.
.
.
30
.
.
.
.
.
.
114
.
391
146
.
.
.
34
.
.
.
.
.
.
.
.
.
63
25
22
29
.
.
31
.
.
.
.
25
.
62
.
437
165
32
.
.
40
.
.
68
36
.
.
.
.
.
69
.
.
37
.
.
.
.
.
.
80
.
.
.
.
527
154
27
.
22
35
25
.
.
30
.
.
.
.
.
64
.
.
29
.
38
31
.
45
.
71
31
.
.
.
602
160
30
.
.
38
.
.
.
33
.
.
.
.
.
67
.
.
29
.
.
.
.
.
.
62
.
.
.
.
419
165
.
31
.
38
46
66
66
34
30
30
45
31
67
69
.
44
34
81
28
34
34
.
32
73
.
.
82
32
1192
155
30
.
.
38
.
.
.
33
.
.
.
.
.
67
.
.
32
.
.
34
.
.
.
55
.
.
.
.
444
146
.
.
.
34
.
.
.
.
.
.
.
.
.
63
25
22
29
.
27
31
.
.
.
.
25
.
62
.
472
168
.
34
.
41
49
69
.
37
30
33
48
34
70
72
.
47
38
46
31
37
37
.
35
77
.
34
85
35
1187
TI-
83PCE
Edition
Python
TI-
84+CE-T
Python
Edition
TI-
Nspire
CX II
Casio
Graph
90+E
35+E II
Num
Works
HP
Prime

α
TI-
Nspire
CX

Ndless
χCAS
Num
Works

Ω
Num
Works

Ω
χCAS
analogin:44
analogout:46
bbport:40
brightns:29
ce_box:32
ce_chart:58
ce_quivr:41
ce_turtl:65

color:30
colorinp:39
conservo:45
dht:45
digital:46
led:45
light:30
lightlvl:44
loudness:44
magnetic:46
mb_butns:38
mb_disp:40
mb_grove:51
mb_music:37
mb_neopx:54
mb_pins:48
mb_radio:40
mb_sensr:54
microbit:28

moisture:44
potentio:44
power:45
ranger:43
relay:45
rgb:45
rgb_arr:51
sound:29
squarewv:44
temperat:43
thermist:44
ti_graphics:67
ti_hub:42
ti_plotlib:78
ti_rover:79
ti_system:34
speaker:35
timer:35
vernier:44
vibmotor:45
analogin:44
analogout:46
bbport:40
brightns:29
ce_box:32
ce_chart:58
ce_quivr:41
ce_turtl:65
color:30
colorinp:39
conservo:45
dht:45
digital:46
led:45
light:30
lightlvl:44
loudness:44
magnetic:46
mb_butns:38
mb_disp:40
mb_grove:51
mb_music:37
mb_neopx:54
mb_pins:48
mb_radio:40
mb_sensr:54
microbit:28
moisture:44
potentio:44
power:45
ranger:43
relay:45
rgb:45
rgb_arr:51
sound:29
squarewv:44
temperat:43
thermist:44
ti_graphics:67
ti_hub:42
ti_plotlib:78
ti_rover:79
ti_system:34
speaker:35
timer:35
vernier:44
vibmotor:45
ti_draw:54
ti_hub:193
ti_image:53
ti_innovator:48
ti_picture:35
ti_plotlib:90
ti_rover:142
ti_st:41
ti_system:83
casioplot
ion:72
kandinsky:28
prime:30
nsp:10
arit:38
cas:28
graphic:55
nsp:37
ion:72
kandinsky:28
arit:41
cas:31
graphic:58
nsp:32
1509-2095
2095
739
28
100
30
10
158
100
162


D'où notre bilan :
  1. 1915 éléments + (dont 406 éléments standard) : TI-83 Premium CE Edition Python
  2. 1588 éléments + (dont 849 éléments standard) : TI-Nspire CX II
  3. 557 éléments + (dont 527 éléments standard) : HP Prime (version alpha)
  4. 537 éléments + (dont 437 éléments standard) : NumWorks
  5. 419 éléments + (dont 391 éléments standard) : Casio Graph 90+E / 35+E II
  6. 246 éléments + (dont 218 éléments standard) : Casio Graph 90+E / 35+E II
  1. 1915 éléments + (dont 406 éléments standard) : TI-83 Premium CE Edition Python
  2. 1588 éléments + (dont 849 éléments standard) : TI-Nspire CX II
  3. 1349 éléments + (dont 1187 éléments standard) : NumWorks (firmware Omega + appli KhiCAS)
  4. 578 éléments + (dont 472 éléments standard) : NumWorks (firmware Omega)
  5. 557 éléments + (dont 527 éléments standard) : HP Prime (version alpha)
  6. 537 éléments + (dont 437 éléments standard) : NumWorks
  7. 419 éléments + (dont 391 éléments standard) : Casio Graph 90+E / 35+E II
  8. 246 éléments + (dont 218 éléments standard) : Casio Graph 90+E / 35+E II
  1. 2501 éléments + (dont 406 éléments standard) : TI-83 Premium CE Edition Python / TI-84 Plus CE-T Python Edition
  2. 1588 éléments + (dont 849 éléments standard) : TI-Nspire CX II
  3. 557 éléments + (dont 527 éléments standard) : HP Prime (version alpha)
  4. 537 éléments + (dont 437 éléments standard) : NumWorks
  5. 419 éléments + (dont 391 éléments standard) : Casio Graph 90+E / 35+E II
  6. 416 éléments + (dont 388 éléments standard) : Casio Graph 90+E / 35+E II
  7. 405 éléments : TI-83 Premium CE + TI-Python
  1. 2501 éléments + (dont 406 éléments standard) : TI-83 Premium CE Edition Python / TI-84 Plus CE-T Python Edition
  2. 1588 éléments + (dont 849 éléments standard) : TI-Nspire CX II
  3. 1350 éléments + (dont 1192 éléments standard) : TI-Nspire CX (Ndless + KhiCAS CX)
  4. 1349 éléments + (dont 1187 éléments standard) : NumWorks (firmware Omega + appli KhiCAS)
  5. 602 éléments : TI-83 Premium CE + TI-Python (tiers)
  6. 578 éléments + (dont 472 éléments standard) : NumWorks (firmware Omega)
  7. 557 éléments + (dont 527 éléments standard) : HP Prime (version alpha)
  8. 537 éléments + (dont 437 éléments standard) : NumWorks
  9. 429 éléments + (dont 419 éléments standard) : TI-Nspire (Ndless + MicroPython)
  10. 419 éléments + (dont 391 éléments standard) : Casio Graph 90+E / 35+E II
  11. 416 éléments + (dont 388 éléments standard) : Casio Graph 90+E / 35+E II
  12. 405 éléments : TI-83 Premium CE + TI-Python + Casio Graph 35/75+E (appli CasioPython)

Un net progrès même si cela ne renverse pas la tendance, la solution Python de Casio est désormais intégralement disponible en mode examen ! :bj:

Casio n'a sans doute pas la solution Python la plus riche, mais on peut quand même noter un soin méticuleux à rester aussi proche que possible du standard et donc faciliter la vie des élèves et des enseignants en ne leur rajoutant pas de travail, préoccupation que l'on ne trouve pas chez tout-le-monde. :D




9) Nouveaux modes examens

Go to top

Nous abordons maintenant l'autre grosse nouveauté, et la raison pour laquelle la mise à jour de Casio est ici globale, concernant également des modèles d'avant-dernière génération.
Les changements dont il est question ici ne concernent pas les modèles spécifiques à la France, uniquement les fx-9860GII, fx-9750GIII, fx-9860GIII, fx-CG10, fx-CG20 et fx-CG50.

Sur ces modèles, lorsque l'on demande l'accès au mode examen, l'écran confirmant le succès de l'opération affiche désormais le numéro de version du système de la calculatrice.
Particulièrement utile hors de France dans les pays où ce sont les surveillants qui activent le mode examen des candidats, ou encore pour les examens qui exigent d'installer la dernière version système, une version système récente ou encore une version système spécifique.
Cela permet de s'assurer que le candidat n'utilise pas une version interdite, plus ancienne ou même obsolète qui présenterait des failles dans le mode examen.

Mais bien évidemment, lorsque ce sont les candidats qui activent le mode examen en début d'épreuve, impossible d'avoir les yeux sur tous les écrans.

Casio avait également prévu quelque chose pour ça, un écran d'information sur le mode examen accessible via
ALPHA
(-)
, non fonctionnel sur les modèles français.
Cet écran indiquait déjà le temps écoulé depuis l'activation du mode examen, permettant ainsi de repérer certaines tentatives de fraude. Notamment les candidats qui auraient activé le mode examen avant l'épreuve et donc potentiellement réinjecté toutes les données de leur choix, et d'une façon ou d'une autre trompé le surveillant sur l'état de la calculatrice en arrivant à leur épreuve (en dissimulant le clignotement de la diode et faisant mine d'appuyer sur les touches ou peu importe).

Et bien nouveauté, cet écran d'information indique dorénavement lui aussi la version de système d'exploitation utilisé. Le surveillant peut donc désormais tout vérifier à n'importe quel moment de l'épreuve en seulement 2 touches. :bj:

Mais ce n'est pas tout. Historiquement chez Casio nous avions 2 modes examen aux comportements différents répartis sur différents modèles :
  • mode examen français (Graph 35+E II, Graph 75+E, Graph 90+E)
  • mode examen international (fx-9860GII, fx-9750GIII, fx-9860GIII, fx-CG10, fx-CG20, fx-CG50)

Avec la mise à jour 3.30, Casio avait rajouté un 2ème mode examen sur la fx-CG50 (mais pas sur la Graph 90+E), portant donc le nombre total de modes examens différents à 3.
Le mode examen historique de la fx-CG50 était renommé "mode examen 1", et le nouveau "mode examen 2".
  • mode examen français (Graph 35+E II, Graph 75+E, Graph 90+E)
  • mode examen international / mode examen 1 (fx-9860GII, fx-9750GIII, fx-9860GIII, fx-CG10, fx-CG20, fx-CG50)
  • mode examen 2 (fx-CG50) qui avait l'avantage d'autoriser l'usage de l'appli additionnelle officielle Graphe 3D

Avec les dernières mises à jour traitées aujourd'hui, c'est un festival :
  • 2 nouveaux modes examen sont rajoutés, portant le total à 5 modes examen différents :
    • un pour les Pays-Bas qui a la particularité d'interdire le calcul exact sur les irrationnels
    • un pour le Texas qui a la particularité d'interdire les représentations graphiques d'inéquations, et oui Casio va chasser sur les terres de TI ;)
  • un même modèle peut désormais gérer jusqu'à un maximum de 4 modes examen différents
  • sur les modèles qui proposent plusieurs modes examens, le mode examen international historique ou mode examen 1 sur la fx-CG50 est renommé en tant que mode examen pour le Baccalauréat International
  • le mode examen 2 de la fx-CG50 est renommé en tant que mode examen pour le Royaume-Uni

Voici le détail des modes examens présents sur chaque modèle après la dernière mise à jour :
Graph 35+E II
Graph 75+E
Graph 90+E
fx-9860G AU+
fx-9860GIIs
fx-9860GIII
Graph 75/95
fx-9750GIII
fx-9860GII
fx-CG10/20
fx-CG50
France
Baccalauréat
international
Pays-Bas
Royaume-Uni
Texas
Total
1
1
2
2
4


Sur les modèles qui offrent plusieurs modes examens les combinaisons d'activation sont différentes. Dans ce cas le type de mode examen invoqué est désormais précisé à l'écran de confirmation.

Une deuxième confirmation est de plus demandée dans le cas où le mode examen invoqué ne convient pas au Baccalauréat International.


Une fois le mode examen activé, il reste quand même identifiable à tout moment par le drapeau clignotant en haut à droite de l'écran, ainsi que sur les modèles couleur par la bordure de l'écran qui utilise une couleur différente.

Voici ci-dessous résumé en un seul coup d'œil tout ce qui concerne les désormais 5 modes examens de Casio :
France
Baccalauréat International
Pays-Bas
Royaume-Uni
Texas
Modèles
Graph 35+E II
Graph 75+E
Graph 90+E
fx-9750GIII
fx-9860GIIs
Graph 75/95
fx-9860G AU+
fx-9860GII/GIII
fx-CG10/20/50
fx-9860GII
fx-CG10/20/50
fx-CG50
fx-9750GIII
fx-CG50
Activation
cos
7
cos
7
cos
7
8
,
1
+
÷
Drapeau
R
R
R
N
R
T
Bordure
Verte
Verte
Jaune
Magenta
Cyan
Calcul exact
irrationnels
Autorisé
Interdit
Autorisé
Interdit
Autorisé
Autorisé
Calcul
vectoriel
Interdit
Interdit
Interdit
Interdit
Autorisé
Interdit
Graphes
inégalités
Autorisé
Autorisé
Autorisé
Autorisé
Autorisé
Interdit
Appli intégrée
Programme
Autorisé
Interdit
Interdit
Interdit
Interdit
Interdit
Appli intégrée
Python
Autorisé
Interdit
Interdit
Interdit
Interdit
Interdit
Appli
additionnelle
officielle
Graphe 3D
Interdit
Interdit
Interdit
Interdit
Autorisé
Interdit
Autres applis
additionnelles
officielles
Interdit
Interdit
Interdit
Interdit
Interdit
Interdit
Applis
additionnelles
non officielles
Interdit
Interdit
Interdit
Interdit
Interdit
Interdit
Contenu
mémoire
préexistant
Interdit
Interdit
Interdit
Interdit
Interdit
Interdit




10) Modifications d'interfaces

Go to top

Même si c'est moins essentiel ici, terminons en regardant les modifications apportées aux menus et messages de l'interface, habitude que nous avons prise pour découvrir les nouveautés puisque Casio ne publie pas de changelog détaillé.

Sur Graph 90+E et fx-CG50, lorsque l'on réalise un backup de la calculatrice dans l'application Système, nous avons un message d'alerte contre l'écrasement si l'opération a déjà été réalisée. En français sa formulation avait changé lors de la mise à jour 3.20.
Avec la mise à jour 3.12, les fx-CG10 et fx-CG20 passent à leur tour à la nouvelle formulation, rattrapant leur retard.

Autre rattrapage, en Italien la formulation "Elemento aggiuntivo" pour les applications additionnelles dans les applications Mémoire et Système avait été remplacée par "Add-In" sur Graph 90+E et fx-CG50 lors de la mise à jour 3.30, ce qui évitait d'avoir à l'abréger à toutes les sauces dans les différents messages et menus.
Avec la mise à jour 3.12, les fx-CG10 et fx-CG20 profitent elles aussi désormais de cette nouvelle formulation.

De façon similaire, sur les Graph 90+E et fx-CG50 dès la mise à jour 3.30, une abrévation isolée avait été supprimée dans l'aide en ligne à l'activation du mode examen.
Avec la mise à jour 3.12, même changement dorénavant sur les fx-CG10 et fx-CG20.

Toujours dans l'aide en ligne au mode examen mais cette fois-ci en italien, la dernière mise à jour passe les mentions de restrictions concernant la mémoire et les programmes au pluriel.


13172Petit bug d'interface, lorsque dans l'application Système on choisissait de supprimer les applications additionnelles, dans toutes les langes le message d'avertissement mentionnait en anglais un MAIN MENU.
En effet c'était un héritage lors de l'adaptation pour l'écran couleur du système Casio Graph monochrome en 2012, le titre du menu principal n'étant pas traduit sur les modèles monochromes.
Les Graph 90+E et fx-CG50 avaient enfin bénéficié d'une correction pertinente de ce message pour la mise à jour 3.40, et avec la mise à jour 3.12 les fx-CG10 et fx-CG20 en bénéficient à leur tour.

13173Toujours sur ce même message, les fx-CG10 et fx-CG20 mentionnaient en anglais une application SYSTEM, héritage là encore des modèles monochromes où les noms d'applications ne sont pas traduits.
Si on peut certes deviner l'application dont il est question dans la plupart des langues, c'était moins évident en Italien où l'application Système s'appelle Set-Up.
Quoiqu'il en soit avec la mise à jour 3.12 le message est désormais correct dans toutes les langues.

Casio fait visiblement attention au moindre petit détail d'intuitivité. ;)




11) Conclusion

Go to top

Une très belle mise à jour. La solution Python de Casio est maintenant intégralement disponible en mode examen, le constructeur semble être fort à l'écoute de sa communauté d'utilisateurs et avoir traité la moindre des critiques bienveillantes formulées lors de notre annonce de la version précédente. :D

Nous louons le soin méticuleux que Casio semble apporter au respect d'un standard Python préexistant avec les modules de tracé par coordonnées matplotlib.pyplot et tracé relatif turtle, évitant de réinventer la roue, et épargnant donc double travail aux élèves et enseignants ! :bj:
Un exemple à suivre ! ;)

Même si cela ne concerne pas la France pour le moment, nous sommes heureux de voir que les choses commencent à bouger niveau mode examen, que Casio a enfin accepté l'idée d'avoir plusieurs modes examens plutôt qu'un unique mode examen avec la somme des restrictions réclamées par chaque institution ou pays concerné.
Le mode examen de Casio a en effet le défaut (du point de vue utilisateur en tous cas) d'être le plus restrictif tous constructeurs confondus, allant même jusqu'à bloquer ses propres applications additionnelles officielles alors que de telles applications ou fonctionnalités équivalentes restent parfaitement disponibles chez les modes examens concurrents.
Nous apprécierions donc si le mode examen français de Casio pouvait également être affiné à son tour pour mieux coller aux seuls interdits réclamés par la réglementation (infos personnelles préchargées), autorisant donc l'usage des applications additionnelles officielles (Conversions sur Graph 90E+, Graphe 3D, Physium, ProbSim, Géométrie), voir même d'applications additionnelles tierces comme KhiCAS. ;)




12) Téléchargements et liens

Go to top

Téléchargements :

Référence : https://www.planet-casio.com/Fr/forums/ ... t-350.html

Envie d'en découvrir davantage sur le nouveau Python ? Casio vient d'annoncer plusieurs vidéoconférences traitant de cette dernière mise à jour :
  • Lundi 19 octobre 14h-14h45 : Python sur les calculatrices Graph 35+E II et Graph 90+E
  • Mardi 27 octobre 14h-14h45 : Les bibliothèques graphiques Python : Turtle & Matplotlib
Pour t'inscrire et participer, c'est par ici : https://www.casio-education.fr/formations-en-ligne/
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51%
 
Posts: 42191
Images: 16671
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby critor » 19 Oct 2020, 12:58

Une analyse complémentaire spécifique au Python est maintenant disponible sur Planète Casio :
https://www.planet-casio.com/Fr/forums/ ... t-350.html
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51%
 
Posts: 42191
Images: 16671
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby parisse » 19 Oct 2020, 13:26

Je serais curieux de savoir si Casio France a fait suivre a la R&D au Japon la methode que j'utilise sur les Nspire et Numworks pour rendre persistant en mode examen des modules ecrits en langage Python, ou s'ils etaient arrives independamment a la meme astuce. La deuxieme hypothese me parait la plus vraissemblable, car sinon ca veut dire qu'en une dizaine de jours ils sont capables de faire une maj, ce qui ressemble plus a la reactivite d'une startup (mais peut-etre que c'est un effet benefique de la concurrence avec Numworks!).
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89%
 
Posts: 3716
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby critor » 19 Oct 2020, 13:34

Les nouveaux modules Python turtle et matplotlib.pyplot sont directement intégrés à l'OS, ils n'apparaissent même plus dans le système de fichiers et ne sont donc a priori pas facilement altérables.

Par contre, la R&D a bien dû faire divers trucs pour que contrairement aux autres l'appli additionnelle Graphe 3D reste utilisable dans le mode examen du Royaume-Uni.
Si le problème a apparemment été traité techniquement, maintenant il reste donc juste à négocier pour les autres applis additionnelles officielles et tierces, dont KhiCAS. ;)

Je précise que c'est le fonctionnement que je devine à la lecture des messages présents dans l'image de l'OS fx-CG50 3.50 et du manuel de cette dernière.
Je n'ai hélas pas de fx-CG50 pour tester, et le mode examen ne marche pas sur les émulateurs.

De façon générale c'est le fait que je ne dispose que de très peu de modèles non français fortement concernés ici, et rarement en plusieurs exemplaires pour pouvoir comparer ancienne et nouvelle versions, qui a beaucoup retardé cette annonce.

Heureusement qu'Adriweb m'a pris et envoyé une fx-9750GIII, ça a sensiblement allégé la charge de travail, et m'a bien aidé à comprendre nombre de subtilités autour du mode examen des modèles non français. :)
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51%
 
Posts: 42191
Images: 16671
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby parisse » 19 Oct 2020, 15:21

critor wrote:Les nouveaux modules Python turtle et matplotlib.pyplot sont directement intégrés à l'OS, ils n'apparaissent même plus dans le système de fichiers et ne sont donc a priori pas facilement altérables.

Oui, c'est exactement ce que je fais sur Numworks/Nspire. Lorsqu'on fait un import dans MicroPython, MicroPython teste la presence du fichier dans le systeme de fichier et le cas echeant il lit le fichier. Ca se fait par l'intermediaire de 2 fonctions C
Code: Select all
mp_import_stat_t mp_import_stat(const char *path) ;
mp_lexer_t * mp_lexer_new_from_file(const char * filename);

Il suffit de modifier import_stat : si un des noms de modules codes en Python apparait, on renvoie MP_IMPORT_STAT_FILE (meme si le fichier n'existe pas). Pour l'autre fonction, on utilise alors une chaine de caracteres fixe qui est le code source Python. Ca remplace juste la lecture sur le systeme de fichiers.
Sur Numworks/Nspire, je laisse la possibilite a l'utilisateur de remplacer le code fige par son propre code (si un fichier du meme nom existe c'est lui qui est utilise). A voir si Casio fait la meme chose ou pas.
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89%
 
Posts: 3716
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby parisse » 19 Oct 2020, 15:32

critor wrote:Par contre, la R&D a bien dû faire divers trucs pour que contrairement aux autres l'appli additionnelle Graphe 3D reste utilisable dans le mode examen du Royaume-Uni.
Si le problème a apparemment été traité techniquement, maintenant il reste donc juste à négocier pour les autres applis additionnelles officielles et tierces, dont KhiCAS. ;)

Je fais ce que je peux pour convaincre Casio, mais ca ne semble pas suffisant pour le moment. Peut-etre que si d'autres enseignants le demandent a Casio, ca aidera. Ou alors la bonne vieille concurrence, car cela donne un avantage net a Numworks ou KhiCAS est non seulement plus complet mais surtout utilisable en mode examen. Il faudrait peut-etre faire une mise a jour de l'article KhiCAS sur Numworks (avec l'inclusion de MicroPython et du tableur). Plus de publicite = probablement plus de telechargements et ca pourrait influencer Casio...
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89%
 
Posts: 3716
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby romsor » 20 Oct 2020, 05:50

tout vient du faire que les tracés sont différés,


=> tout vient du _fait_ que les tracés....
User avatar
romsorProgrammeur
Niveau 3: MH (Membre Habitué)
Niveau 3: MH (Membre Habitué)
Level up: 12%
 
Posts: 14
Joined: 08 Jun 2012, 15:45
Gender: Male
Calculator(s):
MyCalcs profile

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby critor » 20 Oct 2020, 08:31

Merci beaucoup pour ta lecture attentive. C'est corrigé. :)
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51%
 
Posts: 42191
Images: 16671
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby Thom986 » 21 Oct 2020, 14:00

Sacré mise à jour et superbe article.

Elles donnent bien envie ces casio. Je vais essayer de m'en dégoter une pour me faire un avis plus précis.
La réalité, c'est ce qui refuse de disparaître quand on cesse d'y croire. - Philip K. Dick
User avatar
Thom986Premium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Level up: 60.7%
 
Posts: 369
Joined: 21 Feb 2018, 19:11
Gender: Male
Calculator(s):
MyCalcs profile
GitHub: homeostasie

Re: Maj Graph 90/35+E II 3.50/3.40: Python turtle + matplotl

Unread postby critor » 21 Oct 2020, 22:22

Merci. :)

La page de Casio Pays-Bas est maintenant à jour avec ce qui concerne le nouveau mode examen désormais obligatoire :
https://casio-educatie.nl/examenstand/

D'ailleurs je n'avais pas percuté mais les différentes combinaisons d'activation sont super faciles à retenir :
  • 8
    , en mode alphabétique ça fait NL, NederLand. :)
  • ÷
    +
    , ça fait TX, TeXas. :)
  • 1
    ,
    , UK, United Kingdom :)
  • et notre
    cos
    7
    donne EM, pour Exam Mode :)
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 51%
 
Posts: 42191
Images: 16671
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor


Return to News Casio

Who is online

Users browsing this forum: No registered users and 9 guests

-
Search
-
Social TI-Planet
-
Featured topics
Grand Concours 2024-2025 - Programmation Python
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
12345
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1169 utilisateurs:
>1146 invités
>17 membres
>6 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)