Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Picture = {}
- function Picture.load(path, rho) -- path : chemin de l'image, rho : rayon du cercle de rotation
- --- Création d'une table self
- local self = {}
- self.img = Image.load(path) -- image
- self.rotation = {}
- self.rotation.rho = rho -- on stock le rayon
- self.rotation.theta = 0 -- on stock l'angle theta
- self.x = 0 -- on initialise le centre de rotation en X
- self.y = 0 -- on initialise le centre de rotation en Y
- -- Note: les valeurs changerons.
- return(self) -- on retourne la table pour utiliser la fonction comme cela : tab = Picture.load("img.png", 50)
- end
- function Picture.start(self, x, y, vitesse)
- -- self table déclarer : tab = Picture.load(...) ;
- -- x et y sont les coordonnées du centre de rotation.
- -- Vitesse : valeur de 1 à 10, plus c'est proche de 1 plus c'est rapide et inversement pour une vitesse égal à 10.
- self.rotation.theta = self.rotation.theta + 1-- iteration de theta
- self.x = x+self.rotation.rho*math.cos(self.rotation.theta) -- Détermination de la nouvelle valeur de x;
- self.y = y+self.rotation.rho*math.sin(self.rotation.theta) -- Détermination de la nouvelle valeur de y;
- -- Ainsi le point aura pour trajectoire un cercle, et l'image aura un mouvement circulaire.
- ---
- screen:blit(self.x, self.y, self.img) -- On affiche l'image qui sera en rotation :)
- end
- -- Exemple D'utilisation
- local Background = Image.load("background.png")
- local self = Picture.load("cible.png", 80)
- while true do
- screen:clear()
- screen:blit(0,0, Background)
- Picture.start(self, 160, 156, 10)
- screen.waitVblankStart()
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment