solar.py

Created by jilsaint90

Created on November 01, 2020

5.94 KB

Naviguez au cœur du système solaire, et découvrez les caractéristiques de chaque planètes qui le composent, soit, la période de révolution, la distance au soleil, la masse, le rayon et enfin les satellites connus (leur nombre) …


# Solar v.1.01 NW 23/10/2020
# https://nsi.xyz/solar
# par Jil Saint-Martin et Emmy Vadon


from math import *
from kandinsky import *
from random import *
from time import *
from ion import *

def cercle(x0,y0,r,c,e):
 for i in range(2*e):
   xd=x0-int((r-i*0.5)/sqrt(2))
   xf=x0+int((r-i*0.5)/sqrt(2))
   for x in range(xd,xf+1):
     x1=x
     y1=y0+int(sqrt((r-i*0.5)**2-(x-x0)**2))
     set_pixel(x,y1,c)
     for j in range(3):
       x2=x0+y1-y0
       y2=y0+x0-x1
       set_pixel(x2,y2,c)
       x1,y1=x2,y2

def cercle_plein(x0,y0,r,c1,e,c2):
 cercle(x0,y0,r,c1,e)
 cercle(x0,y0,r-e,c2,r-e)

def cercle_grade(x0,y0,R,c1,e,c2):
 for i in range(R):
   r=c1[0]+i*(c2[0]-c1[0])//R
   g=c1[1]+i*(c2[1]-c1[1])//R
   b=c1[2]+i*(c2[2]-c1[2])//R
   cercle(x0,y0,i,color(r,g,b),1)
  
c_noir=[0,0,0] #fond étoilé avec le soleil
c_bleu=[0,35,143]
c_soleil=[255,255,0]
c_soleil2=[235,128,0]
cercle_grade(160,111,197,c_bleu,10,c_noir)
cercle_grade(160,111,40,c_soleil2,2,c_bleu)
cercle_grade(160,111,16,c_soleil,2,c_soleil2)

def degrade(c1,c2,k):
 dr=c2[0]-c1[0]
 dg=c2[1]-c1[1]
 db=c2[2]-c1[2]
 return color(c1[0]+int(k*dr),c1[1]+int(k*dg),c1[2]+int(k*db))

def tirage(n):
 for i in range(n):
   x=randint(0,320)
   y=randint(0,222)
   c=couleur(x,y)
   set_pixel(x,y,c)
   set_pixel(x+1,y,c)
   set_pixel(x,y+1,c)
   set_pixel(x+1,y+1,c)

def couleur(x,y):
 d=sqrt((x-160)**2+(y-111)**2)/32.5
 return degrade(c[int(d)],c[(int(d)+1)%6],d-int(d))
c=[[235,128,0],[13,89,175],[13,89,175],[44,122,211],[207,230,230],[207,230,230]]

tirage(250)

c_blanc=[119,135,135]
r_orb = [22,32,42,52,62,76,92,109]
for i in range(8):
   cercle(160,111,r_orb[i],c_blanc,1)

#periode de revolution
#distance soleil
#masse
#taille
#composition
position = [0] 
systeme = [("Soleil",'centre du syteme solaire','dis soleil: 0','masse: 1,989 × 10^30 kg','rayon: 696340 km', 'satellites connus: 0'),
           ("Venus",'periode de revo: 225 jours','dis soleil: 104 millions km','masse: 4,867 × 10^24 kg','rayon: 6051.8 km', 'satellites connus: 0'),
           ("Mercure",'periode de revo: 88 jours','dis soleil: 57 millions km','masse: 3,285 × 10^23 kg','rayon: 2439.7 km', 'satellites connus: 0'),
           ("Terre",'periode de revo: 365 jours','dis soleil: 150 millions km','masse: 5,972 × 10^24 kg','rayon: 6371 km', 'satellites connus: Lune'),
           ("Mars",'periode de revo: 687 jours','dis soleil: 220 millions km ','masse: 6.39 × 10^23 kg ','rayon: 3389,5 km','satellites connus: 2'),
           ("Jupiter",'periode de revo: 12 ans','dis soleil: 780 millions km ','masse: 1.898 × 10^27 kg','rayon: 69911 km','satellites connus: 3 '),
           ("Saturne",'periode de revo: 29 ans','dis soleil: 1,493 milliard km','masse: 5.683 × 10^26 kg','rayon: 58232 km','satellites connus: ~ 200 '),
           ("Uranus",'periode de revo: 84 ans','dis soleil: 2,9592 milliards km','masse: 8.681 × 10^25 kg','rayon: 25362 km','satellites connus: 27'),
           ("Neptune",'periode de revo: 165 ans','dis soleil: 4,4762 milliards km','masse: 1.024 × 10^26 kg','rayon: 24622 km ','satellites connus: 14 '),
           ]
coord = [(160,111,16), (185,95,8), (180,110,6), (120,100,9), (160,160,9), (115,150,15), (200,50,12), (170,20,9), (55,80,8)]
couleur1 = [[255,255,0], [190,183,150], [251,136,7], [30,160,173], [245,0,0], [162,125,105], [200,169,133], [191,209,232], [0,33,240]]
couleur2 = [[235,128,0], [121,104,83], [106,73,32], [6,67,29], [101,12,12], [134,56,32], [189,138,80], [117,163,224], [5,15,81]]
 
 
 
def solar_systeme_dessine(n, degrade=1):
 # Affiche un corps du sytème solaire, numéro du corps dans systeme[], degradé
 p = 2 + 9 * (n != 0)
 if degrade == 1:
   cercle_grade(coord[n][0], coord[n][1], coord[n][2], couleur1[n], p, couleur2[n])
 else:
   cercle_grade(coord[n][0], coord[n][1], coord[n][2], [255,255,255], p, [255,255,255])
 
def solar_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) 
 if n == 42 :
   fill_rect(1,204,320,18,os)
   draw_string("nsi.xyz/solar par Emmy & Jil ",2,204,(255,255,255),os)
 else:
   fill_rect(1,204,320,18,os)
   draw_string(systeme[n][t],2,204,(255,255,255),os)
 pass
 
solar_systeme_texte()
 
def navigation(): #navigation grâce aux flèches

  texte = 0  
  
  while not keydown(5):



    if keydown(0): #Gauche
      avant = position[0]
      position[0] = max(position[0]-1, 0)
      if avant != position[0]:
        solar_systeme_dessine(avant, degrade=1)
      solar_systeme_dessine(position[0], degrade=0)
      solar_systeme_texte(position[0],texte)
      sleep(0.120)

    elif keydown(3): #Droite
      avant = position[0]
      position[0] = min(position[0]+1, 8) # le soleil [0] + 8 planète
      if avant != position[0]:
        solar_systeme_dessine(avant, degrade=1)
      solar_systeme_dessine(position[0], degrade=0)
      solar_systeme_texte(position[0],texte)
      sleep(0.120)

    elif  keydown(1):  #haut
      texte = min(texte + 1, 5) # Il faut donc avoir 5 données en plus du nom dans systeme[]
      solar_systeme_texte(position[0],texte)
      sleep(0.120)

    elif keydown(2): #bas
      texte = max(texte - 1, 0)
      solar_systeme_texte(position[0],texte)
      sleep(0.120) 
      

solar_systeme_dessine(0, degrade=0)
'''for i in range(1000000):
  pass'''
sleep(1)
solar_systeme_dessine(0, degrade=1)


#Mercure
cExt=[190,183,150]
cInt= [121,104,83]
cercle_grade(180,110,6,cExt,10,cInt)

#Venus
cExt=[251,136,7]
cInt= [106,73,32]
cercle_grade(185,95,8,cExt,10,cInt)
 
#Terre
cExt=[30,160,173]
cInt=[6,67,29]
cercle_grade(120,100,9,cExt,10,cInt)
 
#Mars
cExt=[245,0,0]
cInt=[101,12,12]
cercle_grade(160,160,9,cExt,10,cInt)

#Jupiter
cExt=[162,125,105]
cInt=[134,56,32]
cercle_grade(115,150,15,cExt,10,cInt)

#Saturne
cExt=[200,169,133]
cInt=[189,138,80]
cercle_grade(200,50,12,cExt,10,cInt)

#Uranus
cExt=[191,209,232]
cInt=[117,163,224]
cercle_grade(170,20,9,cExt,10,cInt)

#Neptune
cExt=[0,33,240]
cInt=[5,15,81]
cercle_grade(55,80,8,cExt,10,cInt)

navigation()

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

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