Guest User

Picture_rotary.lua

a guest
May 15th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Picture = {}
  2.  
  3. function Picture.load(path, rho) -- path : chemin de l'image, rho : rayon du cercle de rotation
  4.     --- Création d'une table self
  5.         local self = {}
  6.     self.img = Image.load(path) -- image
  7.     self.rotation = {}
  8.     self.rotation.rho = rho -- on stock le rayon
  9.     self.rotation.theta = 0 -- on stock l'angle theta
  10.     self.x = 0 -- on initialise le centre de rotation en X
  11.     self.y = 0 -- on initialise le centre de rotation en Y
  12.     -- Note: les valeurs changerons.
  13.    
  14.     return(self) -- on retourne la table pour utiliser la fonction comme cela : tab = Picture.load("img.png", 50)
  15. end
  16.  
  17. function Picture.start(self, x, y, vitesse)
  18.         -- self table déclarer : tab = Picture.load(...) ;
  19.     -- x et y sont les coordonnées du centre de rotation.
  20.     -- Vitesse : valeur de 1 à 10, plus c'est proche de 1 plus c'est rapide et inversement pour une vitesse égal à 10.
  21.         self.rotation.theta = self.rotation.theta + 1-- iteration de theta
  22.     self.x = x+self.rotation.rho*math.cos(self.rotation.theta) -- Détermination de la nouvelle valeur de x;
  23.     self.y = y+self.rotation.rho*math.sin(self.rotation.theta) -- Détermination de la nouvelle valeur de y;
  24.     -- Ainsi le point aura pour trajectoire un cercle, et l'image aura un mouvement circulaire.
  25.         ---
  26.     screen:blit(self.x, self.y, self.img) -- On affiche l'image qui sera en rotation :)
  27. end
  28.  
  29.  
  30. -- Exemple D'utilisation
  31. local Background = Image.load("background.png")
  32. local self = Picture.load("cible.png", 80)
  33.  
  34. while true do
  35.         screen:clear()
  36.     screen:blit(0,0, Background)
  37.         Picture.start(self, 160, 156, 10)
  38.     screen.waitVblankStart()
  39.     screen.flip()
  40. end
Advertisement
Add Comment
Please, Sign In to add comment