Script MicroPython pour KhiCAS
# 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()