-
Notifications
You must be signed in to change notification settings - Fork 4
/
1_bridge.py
45 lines (31 loc) · 1021 Bytes
/
1_bridge.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
# Circles and squares
# Each can be rendered in vector or raster form
class Renderer():
def render_circle(self, radius):
pass
class VectorRenderer(Renderer):
def render_circle(self, radius):
print(f'Drawing a circle of radius {radius}')
class RasterRenderer(Renderer):
def render_circle(self, radius):
print(f'Drawing pixels for circle of radius {radius}')
class Shape:
def __init__(self, renderer):
self.renderer = renderer
def draw(self): pass
def resize(self, factor): pass
class Circle(Shape):
def __init__(self, renderer, radius):
super().__init__(renderer)
self.radius = radius
def draw(self):
self.renderer.render_circle(self.radius)
def resize(self, factor):
self.radius *= factor
if __name__ == '__main__':
raster = RasterRenderer()
vector = VectorRenderer()
circle = Circle(vector, 5)
circle.draw()
circle.resize(2)
circle.draw()