-
Notifications
You must be signed in to change notification settings - Fork 0
/
figury.py
50 lines (38 loc) · 1.2 KB
/
figury.py
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
from math import sqrt, cos, sin, pi
class Wielokat:
wiercholki: list[tuple[float, float]]
nazwa: str
def __init__(self, liczbaWierzcholkow, nowaNazwa: str):
self.nazwa = nowaNazwa
self.wierzcholki = [(0.0, 0.0)] * liczbaWierzcholkow
def drukuj(self):
print("Nazwa figury: ")
print(self.nazwa)
print("Wierzcholki wielokata to: ")
for wierzcholek in self.wierzcholki:
print(round(wierzcholek[0], 4), round(wierzcholek[1], 4))
class Szesciokat(Wielokat):
bok: float
def __init__(self, bok: float):
super().__init__(6, "Szesciokat")
self.bok = bok
self.oblicz_punkty()
def oblicz_punkty(self):
srodek = (self.wierzcholki[0][0] + self.bok, self.wierzcholki[0][1])
for i in range(6):
self.wierzcholki[i] = (srodek[0] + self.bok * cos(i * pi / 3), srodek[1] + self.bok * sin(i * pi / 3))
@property
def pole(self):
return 3 * sqrt(3) * (self.bok ** 2) / 2
def drukuj(self):
super().drukuj()
print("Pole szesciokata to: ")
print(round(self.pole, 4))
def wysrodkuj(self):
srodek = (0, 0)
self.wierzcholki[0] = (srodek[0] - self.bok, srodek[1])
self.oblicz_punkty()
a = Szesciokat(2.0)
a.drukuj()
a.wysrodkuj()
a.drukuj()