Evitement

Evitement

_images/titrevideo.PNG_images/blanc1.png
Nuages
html5 video player by EasyHtml5Video.com v3.9.1
_images/titrevideo.PNG _images/blanc1.png smart
html5 video player by EasyHtml5Video.com v3.9.1
Objectif du tutoriel :
OBJECTIF

Construire

  • Afficher une fenêtre, avec un titre .
  • Inclure dans la fenêtre un canevas (Canvas) pour afficher des images qui peuvent se déplacer .
  • Utiliser les listes pour stocker des données.
_images/smartphone.PNG

Télécharger les images téléchager images EVITER .

Le code du programme:

Affichage du code du module image:

#image.py
#module pour les images
#Fabrique une liste d'images
from tkinter import*
def creer_item(tim):
 "creation d'un item "
 #tim+'.png' ="inombre.png" (nombre =1;2; 
 #ou 9 ou 10 ...
 p1=PhotoImage(file=tim+'.png')
 return p1

def liste_image(nombre,dossier):
 # Fonction qui permet de creer un liste qui
 # comporte un nombre de photos
 items=nombre*['']
 for i in range(nombre):
  # le symbole / permet d'aller 
  #chercher les images 
  # dans le dossier images/
  tim=dossier+'/'+str(i+1)
  items[i]=creer_item(tim)
 return items 
 
def taille_photo(photo):
 #Détermine la taille de la photo
 largeur=photo.width()
 hauteur=photo.height()
 return largeur,hauteur 
 

Affichage du code nuage :

#2018ISN animation.py
from tkinter import *
from image import*
import time, threading
from math import * 
def avancer(k,m,n,ka,kb,kc,kd,ke,kf,kg,kh,kj,bouge):
 
 liste_nombre=[2,3,2,4]
 tourne=[12,19,18,17,16,15,14,13,12]
 liste_bouge=[8,9,10,11]
 b=k//200
 a=b%len(liste_bouge)
 nombre=a+1
 st=(k//20)%3-6
 if k%200==0:
  liste_bouge=[8,9,10,11]
  for i in range(nombre):can.itemconfigure(bouge[i],image=images[liste_bouge[a]])
 fin=390+(nombre+1)*102

 if ka>1050:ka=00
 if kb>1000:kb=0
 if kc>1000:kc=0 
 if kd>1000:kd=0
 if ke>1000:ke=0
 if kf>1000:kf=0
 if kg<0:kg=1000
 if m%1000==0:m=1000
 haut=500
 if m<fin and m>400:
  distance=abs(fin-400)
  tours=int((a+1)*distance/(len(tourne)))
  haut=440
  tourne=[12,13,14,15,16,17,18,19,12]
  t=(k)%(len(tourne))
  can.itemconfigure(item3,image=images[tourne[t]])
 if m<400:can.itemconfigure(item3,image=images[12]) 
 if m>fin-1 :can.itemconfigure(item3,image=images[12])
 saut=m
 
 if n%1000==0:n=0
 can.coords(nuage1,1000-(ka),100)
 can.coords(nuage2,1000-(kb),150)
 can.coords(nuage3,1000-(kc),130)
 can.coords(nuage4,1000-(kd),230)
 can.coords(poisson5,(kf),570+st)
 can.coords(poisson6,(kf+500)%1000,580-2*st)
 can.coords(poisson7,(kf+300)%1000,570+st)
 can.coords(poisson8,(kg+800)%1000,580-3*st)
 can.coords(fond,(500-k%1000),320)
 can.coords(fonda,(1500-k%1000),320)
 v,p,p2,p3,p4=5,-4,-6,-5,-8
 for i in range(nombre): can.coords(bouge[i],m-i*50,500)
 can.coords(item3,500,haut)
 fenetre.after(10,lambda:avancer(k+1,m-v,n+v,ka+v,kb+v,kc+v,kd+v,ke+v,kf+p,kg+p2,kh+p3,kj+p4,bouge))         
#------ Programme principal -------
fenetre=Tk()
images=liste_image(21,smart)
bouge=[]
fenetre.geometry("1000x640")
fenetre.title('EVITEMENT')
can = Canvas(fenetre,height=640,width=1000,bg="steel blue")
m,n,k,ka,kb,kc,kd,ke,kf,kg,kh,kj=1000,0,0,0,250,600,500,100,790,850,200,450# coordonnées initiales
can.grid(row =0, column =0, rowspan =3, padx =0, pady =0)
fond=can.create_image(500,320,image=images[0])
fonda=can.create_image(1500,320,image=images[0])
nuage1=can.create_image(1000,100,image=images[4])
nuage2=can.create_image(1200,150,image=images[5])
nuage3=can.create_image(500,130,image=images[6])
nuage4=can.create_image(400,230,image=images[7])
poisson5=can.create_image(100,570,image=images[3])
poisson6=can.create_image(500,580,image=images[3])
poisson7=can.create_image(300,570,image=images[3])
poisson8=can.create_image(800,580,image=images[3])
item3=can.create_image(0,500,image=images[12])
item4=can.create_image(1000,500,image=images[8])
bouge.append(item4)
item5=can.create_image(1050,500,image=images[9])
bouge.append(item5)
item6=can.create_image(1100,500,image=images[10])
bouge.append(item6)
item7=can.create_image(1150,500,image=images[11])
bouge.append(item7)
avancer(k,m,n,ka,kb,kc,kd,ke,kf,kg,kh,kj,bouge)
fenetre.mainloop()  

Affichage du code smart :

#2018ISN smart.py
from tkinter import *
from image import*
import time, threading
from math import * 
def avancer(k,m,n,ka,kb,kc,kd,ke,kf,kg,kh,kj,bouge):
 
 liste_nombre=[2,3,2,4]
 tourne=[12,19,18,17,16,15,14,13,12]
 liste_bouge=[8,9,10,11]
 b=k//200
 a=b%len(liste_bouge)
 nombre=a+1
 st=(k//20)%3-6
 if k%200==0:
  liste_bouge=[8,9,10,11]
  for i in range(nombre):can.itemconfigure(bouge[i],image=images[liste_bouge[a]])
 fin=390+(nombre+1)*102

 if ka>1000:ka=00
 if kb>1000:kb=0
 if kc>1000:kc=0 
 if kd>1000:kd=0
 if ke>1000:ke=0
 if kf>1000:kf=0
 if kg<0:kg=1000
 if m%1000==0:m=1000
 haut=500
 if m<fin and m>400:
  distance=abs(fin-400)
  tours=int((a+1)*distance/(len(tourne)))
  haut=440
  tourne=[12,13,14,15,16,17,18,19,12]
  t=(k)%(len(tourne))
  can.itemconfigure(item3,image=images[tourne[t]])
 if m<400:can.itemconfigure(item3,image=images[12]) 
 if m>fin-1 :can.itemconfigure(item3,image=images[12])
 saut=m
 
 if n%1000==0:n=0
 can.coords(poisson5,500-ka,580)
 can.coords(poisson6,1500-ka,580)
 can.coords(fond,(500-k%1000),320)
 can.coords(fonda,(1500-k%1000),320)
 v,p,p2,p3,p4=5,-4,-6,-5,-8
 for i in range(nombre): can.coords(bouge[i],m-i*50,500)
 can.coords(item3,500,haut)
 fenetre.after(10,lambda:avancer(k+1,m-v,n+v,ka+v,kb+v,kc+v,kd+v,ke+v,kf+p,kg+p2,kh+p3,kj+p4,bouge))         
#------ Programme principal -------
fenetre=Tk()
images=liste_image(25,smart)
bouge=[]
fenetre.geometry("1000x640")
fenetre.title('EVITEMENT')
can = Canvas(fenetre,height=640,width=1000,bg="steel blue")
m,n,k,ka,kb,kc,kd,ke,kf,kg,kh,kj=1000,0,0,0,250,600,500,100,790,850,200,450# coordonnées initiales
can.grid(row =0, column =0, rowspan =3, padx =0, pady =0)
stable=can.create_image(500,320,image=images[21])
fond=can.create_image(500,250,image=images[23])
fonda=can.create_image(1500,250,image=images[23])
poisson5=can.create_image(500,580,image=images[24])
poisson6=can.create_image(1500,580,image=images[24])

item3=can.create_image(0,500,image=images[12])
item4=can.create_image(1000,500,image=images[8])
bouge.append(item4)
item5=can.create_image(1050,500,image=images[9])
bouge.append(item5)
item6=can.create_image(1100,500,image=images[10])
bouge.append(item6)
item7=can.create_image(1150,500,image=images[11])
bouge.append(item7)
avancer(k,m,n,ka,kb,kc,kd,ke,kf,kg,kh,kj,bouge)
fenetre.mainloop()  

Affichage du code smartphone :

#2018ISN smartphone.py
from tkinter import *
from image import*
import time, threading
from random import randrange
from math import *
def eleve():
        global haut,bleu,vert
        haut=haut-20
        bleu=True
        vert=False
        return haut  
def stabler():
  global haut,bleu,vert
  bleu=False
  vert=False 
def baisse():
 global haut,vert,bleu
 haut=haut+20
 vert=True
 bleu=False
 return haut        
def avancer(k,m,n,ka,kb,kc,kd,ke,kf,kg,kh,kj,surprise,elever,baisser,stabilise,bouge):
 global haut
 liste_nombre=[2,3,2,4]
 tourne=[12,19,18,17,16,15,14,13,12]
 liste_bouge=[8,9,10,11]
 b=k//200
 a=b%len(liste_bouge)
 nombre=a+1
 st=(k//20)%3-6
 if k%200==0:
  liste_bouge=[8,9,10,11]
  for i in range(nombre):can.itemconfigure(bouge[i],image=images[liste_bouge[a]])
 fin=390+(nombre+1)*102 
 if ka>1000:ka=00
 if kb>1000:kb=0
 if kc>1000:kc=0 
 if kd>1000:kd=0
 if ke>1000:ke=0
 if kf>1000:kf=0
 if kg<0:kg=1000
 if m%1000==0:
  surprise=randrange(100,420)
  m=1000
 if n%1000==0:n=0
 can.coords(poisson5,500-ka,580)
 can.coords(poisson6,1500-ka,580)
 can.coords(fond,(500-k%1000),320)
 can.coords(fonda,(1500-k%1000),320)
 v,p,p2,p3,p4=5,-4,-6,-5,-8
 for i in range(nombre): can.coords(bouge[i],m-i*50,surprise)
 can.tag_bind("TROIS","<Button-1>",lambda utile:stabler())
 can.tag_bind("UN","<Button-1>",lambda utile:eleve())
 if bleu==True: haut=haut-2 
 can.tag_bind("DEUX","<Button-1>",lambda utile:baisse())
 if vert==True:haut=haut+2 
 can.coords(evite[0],500,haut)
 if m<fin and m>400:
  distance=abs(fin-400)
  tours=int((a+1)*distance/(len(tourne)))  
  tourne=[12,13,14,15,16,17,18,19,12]
  t=(k)%(len(tourne))
  can.itemconfigure(item3,image=images[tourne[t]])
 if m<400:can.itemconfigure(item3,image=images[12]) 
 fenetre.after(10,lambda:avancer(k+1,m-v,n+v,ka+v,kb+v,kc+v,kd+v,ke+v,kf+p,kg+p2,kh+p3,kj+p4,surprise,elever,baisser,stabilise,bouge))         
#------ Programme principal -------
fenetre=Tk()
plus,haut,vert,bleu=0,500,False,False
images=liste_image(28,"smart")
bouge,evite=[],[]
fenetre.geometry("1000x640")
fenetre.title('EVITEMENT')
can = Canvas(fenetre,height=640,width=1000,bg="steel blue")
m,n,k,ka,kb,kc,kd,ke,kf,kg,kh,kj=1000,0,0,0,250,600,500,100,790,850,200,450# coordonnées initiales
can.grid(row =0, column =0, rowspan =6, columnspan=15,padx =0, pady =0)
stable=can.create_image(500,320,image=images[21])
fond=can.create_image(500,250,image=images[23])
fonda=can.create_image(1500,250,image=images[23])
poisson5=can.create_image(500,580,image=images[24])
poisson6=can.create_image(1500,580,image=images[24])
item3=can.create_image(0,500,image=images[12])
evite.append(item3)
item4=can.create_image(1000,500,image=images[8])
bouge.append(item4)
item5=can.create_image(1050,500,image=images[9])
bouge.append(item5)
item6=can.create_image(1100,500,image=images[10])
bouge.append(item6)
item7=can.create_image(1150,500,image=images[11])
elever=can.create_image(50,100,image=images[25],tag="UN")
stabilise=elever=can.create_image(50,250,image=images[27],tag="TROIS")
baisser=can.create_image(50,400,image=images[26],tag="DEUX")
bouge.append(item7)
avancer(k,m,n,ka,kb,kc,kd,ke,kf,kg,kh,kj,500,elever,baisser,stabilise,bouge)
fenetre.mainloop()