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
| #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from math import *
from tkinter import *
class pigeon:
"""Canvas, coordonnée y, coordonnée x, degré
Fonctions : __init__, left, right, forward, find_point, up, down, del_pointeur, pointeur"""
def __init__(self, canvas, coy = 250, cox = 250, degree = 0):
print(pigeon.__doc__)
if (degree < 0):
degree = -degree
degree = degree - degree//360 * 360
self.can = canvas
self.degree = degree
self.cox = cox
self.coy = coy
self.pointeur()
self.up = down
def find_point(self, pxl):
dir = self.degree // 90
tri = self.degree - dir * 90
cibley = pxl * cos(radians(self.degree))
ciblex = sqrt(pxl**2 - cibley**2)
if (tri % 4 == 0):
a = [-cibley, ciblex]
if (tri % 4 == 1):
a = [ciblex, cibley]
if (tri % 4 == 2):
a = [cibley, -ciblex]
if (tri % 4 == 3):
a = [-ciblex, -cibley]
return a
def left(self, d):
self.degree = self.degree + d
if (self.degree < 0):
self.degree = -self.degree
self.degree = self.degree - self.degree//360 * 360
def right(self, d):
self.degree = self.degree - d
if (self.degree < 0):
self.degree = -self.degree
self.degree = self.degree - self.degree//360 * 360
def forward(self, pxl):
a = self.find_point(pxl)
if (self.up == down):
self.can.create_line(self.coy, self.cox, self.coy+a[0], self.cox+a[1])
self.coy, self.cox = self.coy+a[0], self.cox+a[1]
self.pointeur()
def up(self):
self.up = up
def down(self):
self.up = down
def pointeur(self):
za = self.find_point(sqrt(10**2*2))
self.degree = self.degree + 135
zb = self.find_point(10)
self.degree = self.degree + 90
zc = self.find_point(10)
self.degree = self.degree + 135
self.point = self.can.create_polygon(za[0], za[1], zb[0], zb[1], zc[0], zc[1])
def del_pointeur(self):
del self.point
fen.delete(can, self.point |
Partager