teaching:exos:simulations_random_walks_codes

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révisionLes deux révisions suivantes
teaching:exos:simulations_random_walks_codes [2018/11/05 11:40] – [Représenter le déplacement d'un objet] villersdteaching:exos:simulations_random_walks_codes [2018/11/05 11:47] – [Représenter le déplacement de nombreux points] villersd
Ligne 111: Ligne 111:
  
 ===== Représenter le déplacement de nombreux points ===== ===== Représenter le déplacement de nombreux points =====
-<sxh python; title : 04_tkinter_many_moves.py>+<code python 04_tkinter_many_moves.py>
 #!/usr/bin/python #!/usr/bin/python
 # -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
  
-from Tkinter import *+from tkinter import *
 import time import time
 +from random import * 
  
 window = Tk() window = Tk()
-sizex=400 +sizex = 400 
-sizey=600+sizey = 600
 canvas = Canvas(window, width = sizex, height = sizey) canvas = Canvas(window, width = sizex, height = sizey)
 canvas.pack() canvas.pack()
 x = 100 # initial left-most edge of first ball x = 100 # initial left-most edge of first ball
 y = 30 # initial top-most edge of first ball y = 30 # initial top-most edge of first ball
-r=20                  # ball diameter  +r = 16                  # ball diameter  
-depx=2            # displacement at each move in x direction +depx = 2            # displacement at each move in x direction 
-depy=0            # displacement at each move in y direction+depy = 0            # displacement at each move in y direction
  
 # create balls: # create balls:
-no_particles= 20 +no_particles = 20 
-dy = (sizey-2.)/(no_particles+1)       # y initial separation between balls +dy = (sizey-2.*y)/(no_particles+1)       # y initial separation between balls 
-print dy +print(dy) 
-ball_list=[]+ball_list = []
 for i in range(no_particles): for i in range(no_particles):
-    ball=canvas.create_oval(x,y,x+r,y+r,fill="blue")+    ball = canvas.create_oval(x,y,x+r,y+r,fill="blue")
     y = y+dy     y = y+dy
     ball_list.append(ball)     ball_list.append(ball)
  
 #moves #moves
-no_moves=100+no_moves = 100
 for j in range(no_moves): for j in range(no_moves):
     for ball in ball_list:     for ball in ball_list:
-        canvas.move(ball, depx, depy)+        canvas.move(ball, depx, choice([-2, 2]) ) 
 +#        canvas.move(ball, depx, depy)
     canvas.after(10)     canvas.after(10)
     canvas.update()     canvas.update()
Ligne 149: Ligne 151:
 time.sleep(5) # on attend quelques secondes time.sleep(5) # on attend quelques secondes
 window.destroy() window.destroy()
-</sxh>+</code>
  
 ===== Marche aléatoire d'un petit nombre de pas ===== ===== Marche aléatoire d'un petit nombre de pas =====
  • teaching/exos/simulations_random_walks_codes.txt
  • Dernière modification : 2018/11/05 12:09
  • de villersd