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
| class Point(object):
def __init__ (self, xx=0, yy=0):
self.x=xx
self.y=yy
def coord(self) :
return ("({}, {})".format (self.x,self.y))
class Rect (object):
"rectangle défini avec long, larg et coord du sommet (haut gauche)"
def __init__ (self, L,l,x,y):
Point.__init__(self,x,y)
self.long=L
self.larg=l
self.sommet=Point(x,y)
self.centr=Point (0,0)
def centre (self,centr):
x1=self.sommet.x+self.long /2
y1=self.sommet.y+self.larg /2
centr=Point(x1,y1)
return centr
A, B = Point(3, 5), Point (2,6)
r1 = Rect(50,35,12,27)
print ('Le rectangle : L x l =',r1.long,'x',r1.larg,'de sommet ',\
r1.sommet.coord(),' a pour centre ???',r1.centr.coord()) |
Partager