# Solar v.1.01 NW 23/10/2020
# https://nsi.xyz/solar
# par Jil Saint-Martin et Emmy Vadon
defget_infos():fnop=lambda:Nonescreen_w,screen_h,color_bits,font_w,font_h,poly_has_color,poly_set_pixel,poly_show,poly_fill_rect,poly_fill_circle,poly_draw_ellipse,poly_sleep,poly_get_key,poly_draw_string,poly_pause,poly_set_buffer,poly_sleep,show_need_pause_on_exit=320,222,[5,6,5],0,18,1,fnop,fnop,fnop,fnop,fnop,fnop,fnop,fnop,fnop,fnop,fnop,0try:importgraphic,nsp,cas,timedefcol3_2_rgb(c,bits,bgr):returnc[2*bgr]//2**(8-bits[0])+c[1]//2**(8-bits[1])*2**bits[0]+c[2*(not(bgr))]//2**(8-bits[2])*2**(bits[0]+bits[1])defpoly_fill_rect(x1,y1,x2,y2,c):graphic.draw_filled_rectangle(int(x1),int(y1),int(x2),int(y2),c)defpoly_fill_circle(x,y,r,c):graphic.draw_filled_circle(int(x),int(y),int(r),c)defpoly_draw_ellipse(x,y,rx,ry,c):graphic.draw_arc(int(x),int(y),int(rx),int(ry),0,360,c)defpoly_draw_string(s,x,y,cf,cb):st='draw_string("'+s+'", '+str(float(x))+', '+str(float(y))+', '+str(col3_2_rgb(cf,color_bits,1))+', '+str(col3_2_rgb(cb,color_bits,1))+')'print(st)cas.caseval(st)defpoly_get_key():key=int(cas.caseval("get_key()"))# left up down rightenteresc ( )
d={2:0,3:1,4:2,1:3,5:4,9:5,133:40,134:41}forkind:ifkey==d[k]:returnkreturn0defpoly_sleep(d):s=time.monotonic()+d*1000whiletime.monotonic()<s:passfont_w,poly_set_pixel,poly_show,poly_pause=15,graphic.set_pixel,graphic.show_screen,nsp.waitKeypressexcept:try:# NumWorks
importkandinsky,ion,timefrommathimportsqrtfont_w,poly_set_pixel,poly_draw_string,poly_sleep=11,kandinsky.set_pixel,kandinsky.draw_string,time.sleepdefpoly_draw_line(x1,y1,x2,y2,c):m,a1,b1,a2,b2=0,int(x1),int(y1),int(x2),int(y2)if (x2-x1)**2<(y2-y1)**2:m,a1,a2,b1,b2=1,b1,b2,a1,a2ifmin(a1,a2)!=a1:a1,b1,a2,b2=a2,b2,a1,b1forkinrange(a2-a1+1):a,b=a1+k,int(b1+(b2-b1)*k/((a2-a1)or1))poly_set_pixel((a,b)[m],(b,a)[m],c)defpoly_fill_rect(x,y,w,h,c):kandinsky.fill_rect(int(x),int(y),int(w),int(h),c)defpoly_draw_ellipse(x,y,rx,ry,c):forhinrange(-int(ry),int(ry)+1):w=sqrt(max(0,rx*rx*(1-h*h/ry/ry)))x1,x2=int(x-w),int(x+w)yc=y+hpoly_set_pixel(x1,yc,c)poly_set_pixel(x2,yc,c)forwinrange(-int(rx),int(rx)+1):h=sqrt(max(0,ry*ry*(1-w*w/rx/rx)))y1,y2=int(y-h),int(y+h)xc=x+wpoly_set_pixel(xc,y1,c)poly_set_pixel(xc,y2,c)defpoly_fill_circle(x,y,r,c):forhinrange(-int(r),int(r)+1):w=sqrt(max(0,r*r*(1-h*h/r/r)))x1,x2=int(x-w),int(x+w)yc=y+hpoly_draw_line(x1,yc,x2,yc,c)defpoly_pause():defkey_down():forkinrange(53):ifion.keydown(k):return1return0whilekey_down():passwhilenot(key_down()):passdefpoly_draw_string(s,x,y,cf,cb):kandinsky.draw_string(s,x,y,cf,cb)defpoly_get_key():# left up down right enter esc ( )
d={2:0,3:1,4:2,1:3,5:52,9:5,133:33,134:34}forkind:ifion.keydown(d[k]):returnkreturn0except:passreturnscreen_w,screen_h,font_h,poly_set_pixel,poly_fill_rect,poly_fill_circle,poly_draw_ellipse,poly_draw_string,poly_show,poly_pause,poly_get_key,poly_sleepfrommathimportsqrtfromrandomimportrandintscreen_w,screen_h,font_h,set_pixel,fill_rect,fill_circle,draw_ellipse,draw_string,show,pause,get_key,sleep=get_infos()defcercle(x0,y0,r,c,e):foriinrange(2*e):rt=max(0,r-i*0.5)ifrt:draw_ellipse(x0,y0,rt,rt,c)defcercle_plein(x0,y0,r,c1,e,c2):fill_circle(x0,y0,r-e,c2)fill_circle(x0,y0,r,c1)defcercle_grade(x0,y0,R,c1,e,c2):foriinrange(R):cercle(x0,y0,i,(c1[0]+i*(c2[0]-c1[0])//R,c1[1]+i*(c2[1]-c1[1])//R,c1[2]+i*(c2[2]-c1[2])//R),1)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]]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))forkinrange(len(coord)):coord[k][0]=coord[k][0]*screen_w//320coord[k][1]=coord[k][1]*screen_h//222coord[k][2]=coord[k][2]*screen_w//320fill_rect(0,0,screen_w,screen_h,(0,0,0))cercle_grade(screen_w//2,screen_h//2,197*screen_w//320,(0,35,143),10,(0,0,0))cercle_grade(screen_w//2,screen_h//2,40*screen_w//320,couleur2[0],2,(0,35,143))cercle_grade(screen_w//2,screen_h//2,coord[0][2],couleur1[0],2,couleur2[0])defdegrade(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])))deftirage(n):foriinrange(n):x=randint(0,screen_w)y=randint(0,screen_h)fill_rect(x,y,2,2,couleur(x,y))defcouleur(x,y):c=(couleur2[0],(13,89,175),(13,89,175),(44,122,211),(207,230,230),(207,230,230))d=sqrt((x-screen_w//2)**2+(y-screen_h//2)**2)/(screen_w/10+.5)returndegrade(c[int(d)],c[(int(d)+1)%6],d-int(d))tirage(250)couleur,tirage=None,Nonec_blanc=(255,255,255)r_orb=(22,32,42,52,62,76,92,109)foriinrange(8):cercle(screen_w//2,screen_h//2,r_orb[i],(119,135,135),1)r_orb=Nonedefsolar_systeme_dessine(n,degrade=1):# Affiche un corps du sytème solaire, numéro du corps dans systeme[], degradé
cercle_grade(coord[n][0],coord[n][1],coord[n][2],degradeandcouleur1[n]orc_blanc,2+9*(n!=0),degradeandcouleur2[n]orc_blanc)defsolar_systeme_texte(n=42,t=0):#affichage du texte en bas, de couleur associée à omega, avec les diverse infos
try:get_keys()os=(192,53,53)except:os=(255,183,52)ifn==42:fill_rect(1,screen_h-font_h,screen_w,font_h,os)draw_string("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]ift==1andn:s="periode de revo: "+s+((n<=4)and" jours"or" ans")elift==2:s="dis soleil: "+s+" milli"+((n<=5)and"on"or"ard")+"s km"elift==3:s="masse: "+s+" kg"elift==4:s="rayon: "+str(s)+" km"elift==5:s="satellites connus: "+str(s)draw_string(s,2,screen_h-font_h,c_blanc,os)solar_systeme_texte()defnavigation():#navigation grâce aux flèches
position=0texte=0key=0whilekey!=9:show()key=get_key()ifkey>=1andkey<=4:ifkey<=2:#Gauche Droite
avant=positionposition=min(max(position+2*(key==1)-1,0),8)# le soleil [0] + 8 planète
ifavant!=position:solar_systeme_dessine(avant)solar_systeme_dessine(position,0)elifkey>=3:#haut bas
texte=max(min(texte+2*(key==3)-1,5),0)# Il faut donc avoir 5 données en plus du nom dans systeme[]
solar_systeme_texte(position,texte)sleep(0.120)solar_systeme_dessine(0,0)show()sleep(1)solar_systeme_dessine(0)forkinrange(1,9):cercle_grade(coord[k][0],coord[k][1],coord[k][2],couleur1[k],10,couleur2[k])navigation()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.