rich/examples/bars.py

22 lines
417 B
Python
Raw Normal View History

2020-10-16 09:56:08 +00:00
"""
2020-10-16 14:58:46 +00:00
Use Bar to renderer a sort-of circle.
2020-10-16 09:56:08 +00:00
"""
import math
2020-10-16 14:58:46 +00:00
from rich.align import Align
2020-10-16 09:56:08 +00:00
from rich.bar import Bar
2020-10-16 11:32:15 +00:00
from rich.color import Color
2020-10-16 09:56:08 +00:00
from rich import print
SIZE = 40
for row in range(SIZE):
2020-10-16 14:58:46 +00:00
y = (row / (SIZE - 1)) * 2 - 1
2020-10-16 09:56:08 +00:00
x = math.sqrt(1 - y * y)
2020-10-17 14:54:00 +00:00
color = Color.from_rgb((1 + y) * 127.5, 0, 0)
2020-10-16 14:58:46 +00:00
bar = Bar(2, width=SIZE * 2, begin=1 - x, end=1 + x, color=color)
print(Align.center(bar))