π
<-
Chat plein-écran
[^]

Solar, le système Solaire en Python sur NumWorks, TI, Casio

Re: Solar, le système Solaire en Python sur NumWorks, TI, Ca

Unread postby parisse » 11 Nov 2020, 17:33

J'ai adapte pour KhiCAS en mode Xcas, sans utiliser polycalc, l'objectif : etre compatible entre calculatrices supportees par KhiCAS, et viser une acceleration sur la Casio Graph 90, comme sur la Numworks (ou il faut moins de 2 secondes pour tout tracer en MicroPython KhiCAS).

Resultat : ca marche bien sur Nspire CX ou j'ai une version compatible KhiCAS Xcas et KhiCAS MicroPython (cf. ci-dessous), mais sur Numworks, il n'y a pas assez de ressources et donc sur Casio ce sera pareil. Enfin, en grattant de partout, on y arrive tout juste, mais KhiCAS devient alors instable, donc je ne mets en ligne que la version MicroPython KhICAS
https://workshop.numworks.com/python/parisseb/solaire, elle n'a pas besoin du script de compatibilite de critor.
Attention, pour la compatibilite, j'ai du faire une mise a jour de KhiCAS pour TI et pour Numworks pour y ajouter la commande draw_filled_circle (cote Xcas) et accepter un parametre de couleur de fonds pour la commande draw_string (cote MicroPython).

Donc voila le code KhiCAS compatible MicroPython/Xcas pour ti nspire (fonctionne aussi sur Numworks MicroPython)
Code: Select all
# Solar v.1.01 NW 23/10/2020
# d'apres https://nsi.xyz/solar
# Jil Saint-Martin et Emmy Vadon

from math import *
from random import *
from kandinsky import *
from cas import *

screen_w=320
screen_h=222
font_h=16
systeme = [["Soleil",'centre du syteme solaire','0','1,989 × 10^30','696340', '0'],
           ["Mercure",'88','57','3,285 × 10^23','2439.7', '0'],
           ["Venus",'225','104','4,867 × 10^24','6051.8', '0'],
           ["Terre",'365','150','5,972 × 10^24','6371', 'Lune'],
           ["Mars",'687','220 ','6.39 × 10^23 ','3389,5','2'],
           ["Jupiter",'12','780 ','1.898 × 10^27','69911','3'],
           ["Saturne",'29','1,493','5.683 × 10^26','58232','~ 200'],
           ["Uranus",'84','2,9592','8.681 × 10^25','25362','27'],
           ["Neptune",'165','4,4762','1.024 × 10^26','24622','14']
           ]
coord = [[160,111,16], [180,110,6], [185,95,8], [120,100,9], [160,160,9], [115,150,15], [200,50,12], [170,20,9], [55,80,8]]
for k in range(len(coord)):
  coord[k][0] = coord[k][0]*screen_w//320
  coord[k][1] = coord[k][1]*screen_h//222
  coord[k][2] = coord[k][2]*screen_w//320

couleur1 = [[255,255,0], [251,136,7], [190,183,150], [30,160,173], [245,0,0], [162,125,105], [200,169,133], [191,209,232], [0,33,240]]
couleur2 = [[235,128,0], [106,73,32], [121,104,83], [6,67,29], [101,12,12], [134,56,32], [189,138,80], [117,163,224], [5,15,81]]
c_blanc=65535

def anneau(x0,y0,r,c,E):
  for i in range(2*E):
    rt = max(0,r-i*0.5)
    if rt:
      draw_circle(x0,y0,int(rt),c)

def degrade(c1,c2,k):
  return [c1[0]+int(k*(c2[0]-c1[0])),c1[1]+int(k*(c2[1]-c1[1])),c1[2]+int(k*(c2[2]-c1[2]))]

def cercle_degrade(x0,y0,R,c1,c2,E):
  for i in range(R):
    anneau(x0,y0,i,degrade(c1,c2,i/R),1)

def RGB(r,g,b):
  return (((r*32)//256)*2^11) + (((g*64)//256)*2^5)  + ((b*32)//256)

def tirage(n):
  c=[RGB(235,128,0),RGB(13,89,175),RGB(13,89,175),RGB(44,122,211),RGB(207,230,230),RGB(207,230,230)]
  c.append(c[0])
  sw2=screen_w/2.0
  sh2=screen_h/2.0
  Coeff=1.0/(screen_w/10.0+.5)
  for i in range(n):
    x=randint(0,screen_w)
    y=randint(0,screen_h)
    d=sqrt((x-sw2)**2+(y-sh2)**2)*Coeff
    di=int(d)
    fill_rect(x,y,2,2,c[di]+int((d-di)*(c[di+1]-c[di])))

def drawstring(s, x, y, cf,cb=0):
    print(s)
    draw_string(x,y,s,cf,cb)

def solar_systeme_dessine(n, Degrade=1):
  # Affiche un corps du sytème solaire, numéro du corps dans systeme[], degradé
  if Degrade:
    cercle_degrade(coord[n][0], coord[n][1], coord[n][2], couleur1[n], couleur2[n],2 + 9 * (n != 0))
  else:
    draw_filled_circle(coord[n][0], coord[n][1], coord[n][2], c_blanc)

def solar_systeme_texte(n=42, t=0): #affichage du texte en bas, de couleur associée à omega, avec les diverse infos
  os=RGB(255,183,52)
  if n == 42 :
    fill_rect(1,screen_h-font_h,screen_w,font_h,os)
    drawstring("nsi.xyz/solar par Emmy & Jil ",2,screen_h-font_h,c_blanc,os)
  else:
    fill_rect(1,screen_h-font_h,screen_w,font_h,os)
    s = systeme[n][t]
    if t==1 and n:
      s = "periode de revo: " + s + ((n <=4 ) and " jours" or " ans")
    elif t==2:
      s = "dis soleil: " + s + " milli" + ((n <= 5 ) and "on" or "ard") + "s km"
    elif t==3:
      s = "masse: " + s + " kg"
    elif t==4:
      s = "rayon: " + str(s) + " km"
    elif t==5:
      s = "satellites connus: " + str(s)
    drawstring(s,2,screen_h-font_h,c_blanc,os)

def navigation(): #navigation grâce aux flèches
  Position = 0
  texte = 0 

  key = 0
  while key != 9 and key!=5 :

    show()
    key = get_key()

    if key>=0 and key<=3:
      if key==0 or key==3: #Gauche Droite
        avant = Position
        Position = min(max(Position+2*(key==3)-1, 0), 8) # le soleil [0] + 8 planète
        if avant != Position:
          solar_systeme_dessine(avant)
        solar_systeme_dessine(Position, 0)

      elif  key==1 or key==2:  #haut bas
        texte = max(min(texte + 2*(key==2) - 1, 5), 0) # Il faut donc avoir 5 données en plus du nom dans systeme[]

      solar_systeme_texte(Position,texte)
      #sleep(0.120)
     
def main():
  fill_rect(0,0,screen_w,screen_h,0)
  cercle_degrade(screen_w//2,screen_h//2,197*screen_w//320,[0,35,143],[0,0,0],10)
  cercle_degrade(screen_w//2,screen_h//2,40*screen_w//320,couleur2[0],[0,35,143],2)
  cercle_degrade(screen_w//2,screen_h//2,coord[0][2],couleur1[0],couleur2[0],2)
  tirage(250)
  set_pixel()

  r_orb = (22,32,42,52,62,76,92,109)
  for i in range(8):
    anneau(screen_w//2,screen_h//2,r_orb[i],[119,135,135],1)

  solar_systeme_texte()
  solar_systeme_dessine(0,0)
  set_pixel()
  #sleep(0.1)
  solar_systeme_dessine(0)

  for k in range(1,9):
    cercle_degrade(coord[k][0],coord[k][1],coord[k][2],couleur1[k],couleur2[k],10)

  navigation()

main()


(Edit: correction de coeff en Coeff, car coeff est une commande interne Xcas)
Last edited by parisse on 13 Nov 2020, 16:32, edited 1 time in total.
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 78%
 
Posts: 3511
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Solar, le système Solaire en Python sur NumWorks, TI, Ca

Unread postby Lionel Debroux » 11 Nov 2020, 20:55

Waouh... qu'elles sont belles, ces ellipses. Félicitations ? :)
Membre de la TI-Chess Team.
Co-mainteneur de GCC4TI (documentation en ligne de GCC4TI), TIEmu et TILP.
User avatar
Lionel DebrouxSuper Modo
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 11.2%
 
Posts: 6859
Joined: 23 Dec 2009, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Class: -
GitHub: debrouxl

Re: Solar, le système Solaire en Python sur NumWorks, TI, Ca

Unread postby parisse » 13 Nov 2020, 17:49

J'ai finalement reussi le portage sur Casio/KhiCAS en utilisant la syntaxe native Xcas. C'est un peu juste en memoire mais si on ne touche pas au script ca passe.
Il faut une dizaine de secondes pour afficher le systeme solaire, la navigation fonctionne comme sur les autres calcs et est fluide.
J'ai du faire quelques modifs, en particulier pour que les planetes soient sur leurs orbites (ce n'est pas le cas avec le script de critor a cause du facteur d'echelle different de 320x240 sur les Casio).
Code: Select all
// Solar v.1.01 NW 23/10/2020

sw:=384;sh:=192;font_h:=10;
systeme := [["Soleil","centre du syteme solaire",0,1.989e30,696340, 0],
    ["Mercure",88,57,3.285e23,2439.7, 0],
    ["Venus",225,104,4.867e24,6051.8, 0],
    ["Terre",365,150,5.972e24,6371, "Lune"],
    ["Mars",687,220 ,6.39e23 ,3389,5,2],
    ["Jupiter",12,780 ,1.898e27,69911,3],
    ["Saturne",29.1,493,5.683e26,58232,"~ 200"],
    ["Uranus",84.2,9592,8.681e25,25362,27],
    ["Neptune",165.4,4762,1.024e26,24622,14]]:;
rayons:=[22,32,42,52,62,76,92,109];
coord := [[160,116,16], [180,115,6], [185,100,8], [120,105,9], [160,165,9],
    [115,155,15], [200,55,12], [170,25,9], [55,85,8]]:;
couleur1 := [[255,255,0], [251,136,7], [190,183,150],
    [30,160,173], [245,0,0], [162,125,105], [200,169,133],
    [191,209,232], [0,33,240]]:;
couleur2 := [[235,128,0], [106,73,32], [121,104,83],
    [6,67,29], [101,12,12], [134,56,32], [189,138,80],
    [117,163,224], [5,15,81]]:;
c_blanc:=65535:;

anneau(x0,y0,r,c,E):={
  local j,rt;
  for j in range(2*E) do
    rt := max(0,r-j*0.5);
    draw_circle(x0,y0,floor(rt),c);
  od;
}:;

degrade(c1,c2,k):=rgb(c1[0]+floor(k*c2[0]),
    c1[1]+floor(k*c2[1]),c1[2]+floor(k*c2[2])):;

cercled(x0,y0,R,c1,c2):={
  local j;
  for j in range(R) do anneau(x0,y0,j,degrade(c1,c2-c1,j/R),1); od;
  set_pixel();
}:;

tirage(n):={
  local j,c,x,y,d,di,Coeff;
  c:=[rgb(235,128,0),rgb(13,89,175),rgb(13,89,175),
      rgb(44,122,211),rgb(207,230,230),rgb(207,230,230)];
  c.append(c[0]);
  Coeff:=1.0/(sw/10.0+.5);
  for j in range(n) do
    x:=randint(0,sw);
    y:=randint(0,sh);
    d:=sqrt((x-sw/2.0)**2+(y-sh/2.0)**2)*Coeff;
    di:=floor(d);
    fill_rect(x,y,2,2,c[di]+floor((d-di)*(c[di+1]-c[di])));
  od;
}:;

solar_systeme_dessine(n, Degrade=1):={
  local cn:=coord[n];
  if Degrade then
    cercled(cn[0], cn[1], cn[2], couleur1[n], couleur2[n]);
  else
    draw_circle(cn[0], cn[1], cn[2], rempli+c_blanc);
  fi;
}:;

solar_systeme_texte(n=42, t=0):={
  local s;
  fill_rect(0,sh+24-font_h,sw,font_h+1,c_blanc);
  if n == 42 then
    return draw_string("nsi.xyz/solar par Emmy & Jil ",2,sh-font_h);
  fi;
  s := systeme[n,t];
  if t==1 and n then
    s := "periode de revo: " + s + ((n <=4)?" jours":" ans");
  elif t==2 then
    s := "dis soleil: " + s + " milli" + ((n <= 5 )?"on":"ard") + "s km";
  elif t==3 then
    s := "masse: " + s + " kg";
  elif t==4 then
    s := "rayon: " + str(s) + " km";
  elif t==5 then
    s := "satellites connus: " + str(s);
  fi;
  draw_string(s,2,sh-font_h);
}:;

navigation():={
  local Position,avant,texte,key;
  Position := 0;
  texte := 0  ;
  key := 0;
  while key != 30002 do
    key := getKey();
    if key>=30018 and key<=30023 then
      if key==30020 or key==30021 then
        avant := Position;
        Position := min(max(Position+2*(key==30021)-1, 0), 8);
        if avant != Position then solar_systeme_dessine(avant); fi;
        solar_systeme_dessine(Position, 0);
      elif key==30018 or key==30023 then 
        texte := max(min(texte + 2*(key==30023) - 1, 5), 0);
      fi;
      solar_systeme_texte(Position,texte);
    fi;
  od;
}:;
     
main():={
  local j,k,ck,c0,c1;
  fill_rect(0,0,sw,sh+24,0);
  c0:=coord[0,0]; c1:=coord[0,1];
  cercled(c0,c1,197,[0,35,143],[0,0,0])
  cercled(c0,c1,40,couleur2[0],[0,35,143])
  cercled(c0,c1,coord[0,2],couleur1[0],couleur2[0]);
  tirage(250);
  for j in rayons do
    anneau(c0,c1,j,rgb([119,135,135]),1);
  od;
  solar_systeme_texte();
  solar_systeme_dessine(0,0);
  solar_systeme_dessine(0);
  for k in range(1,9) do
    ck:=coord[k];
    cercled(ck[0],ck[1],ck[2],couleur1[k],couleur2[k]);
  od;
  navigation();
}:;

main():;

User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 78%
 
Posts: 3511
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Solar, le système Solaire en Python sur NumWorks, TI, Ca

Unread postby critor » 13 Nov 2020, 18:33

Merci pour le signalement de l'erreur, je regarde ça.

Je regarde surtout si la correction peut marcher sur TI-83/84 sans version spécifique incompatible avec les autres modèles.
Image
User avatar
critorAdmin
Niveau 19: CU (Créateur Universel)
Niveau 19: CU (Créateur Universel)
Level up: 42.4%
 
Posts: 41497
Images: 14640
Joined: 25 Oct 2008, 00:00
Location: Montpellier
Gender: Male
Calculator(s):
MyCalcs profile
YouTube: critor3000
Twitter: critor2000
GitHub: critor

Re: Solar, le système Solaire en Python sur NumWorks, TI, Ca

Unread postby parisse » 13 Nov 2020, 19:25

Il suffit de faire comme j'ai fait, centrer les orbites et les cercles de main() sur coord[0,0] et coord[0,1] et ne pas re-scaler les rayons.
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 78%
 
Posts: 3511
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Previous

Return to News NumWorks

Who is online

Users browsing this forum: No registered users and 38 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
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.
1095 utilisateurs:
>1051 invités
>40 membres
>4 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)