1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
from visual import *
#------Arriere plan-----
scene.background =(1,1,1)
#-----Table et trous-----
board = shapes.rectangle(pos=(0,0), width=2.96, height=1.68)
extraBoard = shapes.rectangle(pos=(0,0), width=3.20, height=1.85)
trou1 = shapes.circle(pos=(-1.45,0.80), radius=0.095)
trou2 = shapes.circle(pos=(1.45,0.80), radius=0.095)
trou3= shapes.circle(pos=(-1.45,-0.80), radius=0.095)
trou4= shapes.circle(pos=(1.45,-0.80), radius=0.095)
trou5= shapes.circle(pos=(0,-0.80), radius=0.095)
trou6= shapes.circle(pos=(0,0.80), radius=0.095)
extrusion(pos=[(0,0,0),(0,0,0.20)], shape=board-trou1-trou2-trou3-trou4-trou5-trou6, material=materials.rough)
extrusion(pos=[(0,0,0),(0,0,0.20)], shape=extraBoard-board-trou1-trou2-trou3-trou4-trou5-trou6 , material=materials.wood)
#-----Bords de la table-----
edge1 = box(size=(1.27,0.05,0.07), pos =(0.72,-0.87,0.20),material=materials.wood)
edge2 = box(size=(1.27,0.05,0.07), pos =(-0.72,-0.87,0.20),material=materials.wood)
edge3 = box(size=(1.27,0.05,0.07), pos =(0.72,0.87,0.20),material=materials.wood)
edge4 = box(size=(1.27,0.05,0.07), pos =(-0.72,0.87,0.20),material=materials.wood)
edge5 = box(size=(0.05,1.40,0.07), pos =(1.50,0,0.20),material=materials.wood)
edge6 = box(size=(0.05,1.40,0.07), pos =(-1.50,0,0.20),material=materials.wood)
#-----pattes de la table-----
patte1 = cylinder(pos=(1.00,0.60,0), axis=(0,0,-1.00), radius=0.10,material=materials.marble)
patte2 = cylinder(pos=(-1.00,0.60,0), axis=(0,0,-1.00), radius=0.10,material=materials.marble)
patte3 = cylinder(pos=(1.00,-0.60,0), axis=(0,0,-1.00), radius=0.10,material=materials.marble)
patte4 = cylinder(pos=(-1.00,-0.60,0), axis=(0,0,-1.00), radius=0.10,material=materials.marble)
#-----Plancher-----
plancher = box(size=(6.00,4.00,0.10), material=materials.bricks, pos =(0,0,-1.00))
#-----Ligne-----
ligne = shapes.rectangle(pos=(0.863,0), width=0.05, height=1.68)
extrusion(pos=[(0,0,0),(0,0,0.20)], shape=ligne, color=color.white)
#-----balles-----
ballBlanche=sphere(pos=vector(-0.855,0,0.255),radius=0.06,color=color.white)
ballEarth=sphere(pos=vector(0.855,0,0.255),radius=0.06,material=materials.BlueMarble)
# Attributs des variables
mBallBlanche= 1.6
mBallEarth=1.6
rBalles=0.06
dt=0.01
vitesse2 = vector(0,0,0)
vitesse=vector(3,3,0)
s= vector(ballEarth.pos.x,ballEarth.pos.y,0)
teta2=diff_angle(vitesse,s)
g=9.8
teta1=pi/2 -teta2
#Boucle du mouvement
while 1:
rate(100)
ballBlanche.pos= ballBlanche.pos + vitesse*dt
ballEarth.pos= ballEarth.pos + vitesse2*dt
# Condition si les balles entrent en collision avec les bordures
if ballEarth.pos.x>1.45:
vitesse2.x= -vitesse2.x
if ballEarth.pos.x<=-1.45:
vitesse2.x= -vitesse2.x
if ballEarth.pos.y>0.87:
vitesse2.y= -vitesse2.y
if ballEarth.pos.y<=-0.87:
vitesse2.y= -vitesse2.y
if ballBlanche.pos.x>1.45:
vitesse.x= -vitesse.x
if ballBlanche.pos.x<=-1.45:
vitesse.x= -vitesse.x
if ballBlanche.pos.y>0.87:
vitesse.y= -vitesse.y
if ballBlanche.pos.y<=-0.87:
vitesse.y= -vitesse.y
#Condition si les deux balles entrent en collision l'une vers l'autre
#mBallBlanche*vitesse=mBallBlanche*v1*cos*angle1+ mBallEarth*vitesse2*cos*angle2
if mag(ballBlanche.pos - ballEarth.pos) < ((ballEarth.radius + ballEarth.radius) ):
#vitesseF2=vitesse/((cos(teta2)-sin(teta2)*cos(teta1))
#vitesse=(vitesseF2*sin(teta2))/sin(teta1)
#ballEarth.pos= ballEarth.pos+ vitesseF2*dtCONDITION QUAND UN BALLE RENTRE DANS UN TROU.
vitesse2=(mBallBlanche/mBallEarth)*vitesse
vitesse2.x= -vitesse2.x
if mag(ballEarth.pos-vector(1.465,0.815,0))<=0.258:
vitesse2.x=0
vitesse2.y=0
vitesse2.z=0-g*dt
if mag(ballEarth.pos-vector(-1.465,0.815,0))<=0.258:
vitesse2.x=0
vitesse2.y=0
vitesse2.z=-0-g*dt
if mag(ballEarth.pos-vector(-1.465,-0.815,0))<=0.258:
vitesse2.x=0
vitesse2.y=0
vitesse2.z=0-g*dt
if mag(ballEarth.pos-vector(1.465,-0.815,0))<=0.258:
vitesse2.x=0
vitesse2.y=0
vitesse2.z=0-g*dt
if mag(ballEarth.pos-vector(0,-0.815,0))<=0.26:
vitesse2.x=0
vitesse2.y=0
vitesse2.z=0-g*dt
if mag(ballEarth.pos-vector(0,0.815,0))<=0.26:
vitesse2.x=0
vitesse2.y=0
vitesse2.z=0-g*dt
if ballEarth.pos.z<-0.895:
vitesse2 = vector(0,0,0) |
Partager