diff --git a/Chapter_2/ex5_sol1.py b/Chapter_2/ex5_sol1.py new file mode 100644 index 0000000000000000000000000000000000000000..30c1586f7f4f269e66df9a5440840804a350eba2 --- /dev/null +++ b/Chapter_2/ex5_sol1.py @@ -0,0 +1,38 @@ +import math + +v0 = float(input("Vitesse initiale ?")) +alpha = float(input("Angle initial ?")) + +v0_x = v0*math.cos(alpha*math.pi/180) +v0_y = v0*math.sin(alpha*math.pi/180) +g = 9.81 + +# Paramètres A et B tels que y = A*x + B*x² +A = v0_y / v0_x +B = 0.5*g/v0_x**2 + +n_lines = 50 +n_col = 100 + +print(" "+n_col*"-") +lineId = 0 +while lineId < n_lines: + colId = 0 + txt_to_print = "|" + while colId < n_col: + t = 0 + filled = False + x = colId - 0.5 + while x < colId + 0.5: # Boucle sur x pour avoir une ligne continue + y = A*x - B*x**2 + if abs(n_lines-y-lineId)<0.5: + filled = True # S'assurer qu'on ne remplisse qu'une fois une case + txt_to_print+="x" + break + x+=0.1 + if not filled: + txt_to_print += " " # Case non remplie + colId+=1 + lineId+=1 + print txt_to_print+"|" +print(" "+n_col*"-") diff --git a/Chapter_2/ex5_sol2.py b/Chapter_2/ex5_sol2.py new file mode 100644 index 0000000000000000000000000000000000000000..6a28481e3c64e88b215cf5e7317d007ea90a0966 --- /dev/null +++ b/Chapter_2/ex5_sol2.py @@ -0,0 +1,39 @@ +import math + +v0 = float(input("Vitesse initiale ?")) +alpha = float(input("Angle initial ?")) + +v0_x = v0*math.cos(alpha*math.pi/180) +v0_y = v0*math.sin(alpha*math.pi/180) +g = 9.81 + + +n_lines = 50 +n_col = 100 + +print(" "+n_col*"-") +lineId = 0 +while lineId < n_lines: + colId = 0 + txt_to_print = "|" + while colId < n_col: + t = 0 + filled = False + while t < 10000: # On évalue toute la trajectoire pour chaque case du tableau... + x = v0_x*t + y = v0_y*t - 0.5*g*t**2 + t+=0.01 + if abs(x - colId ) < 0.5 and abs(n_lines-y-lineId)<0.5: + txt_to_print+="x" + filled = True + break + if y < 0 or x < 0 or x > n_col: + break + if filled == False: + txt_to_print += " " + + colId+=1 + + lineId+=1 + print txt_to_print+"|" +print(" "+n_col*"-")