examples/bars.py
raw| 1 | """ |
| 2 | |
| 3 | Use Bar to renderer a sort-of circle. |
| 4 | |
| 5 | """ |
| 6 | import math |
| 7 | |
| 8 | from rich.align import Align |
| 9 | from rich.bar import Bar |
| 10 | from rich.color import Color |
| 11 | from rich import print |
| 12 | |
| 13 | |
| 14 | SIZE = 40 |
| 15 | |
| 16 | for row in range(SIZE): |
| 17 | y = (row / (SIZE - 1)) * 2 - 1 |
| 18 | x = math.sqrt(1 - y * y) |
| 19 | color = Color.from_rgb((1 + y) * 127.5, 0, 0) |
| 20 | bar = Bar(2, width=SIZE * 2, begin=1 - x, end=1 + x, color=color) |
| 21 | print(Align.center(bar)) |