Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

MaxGradient
PyPI - MaxGradient PyPI - MaxGradient Version 0.3.1
MaxGradient

MaxGradient automates printing gradient colored text to the console. It's built upon the great rich library. It contains two new Rich Renderables that can be printed by a rich.console.Console object:

  • Gradient - A Rich Renderable that prints Text with a gradient of colors to the console.
  • GradientRule - A Rich Renderable that prints a horizontal rule to the console in gradient color.

MaxGradient also expands the rich.color.Color class to include generating colors from CSS3 named colors, as well as 3 digit hex color codes.

MaxGradient is a work in progress. It is currently in version 0.3.1. It is not yet feature complete, but it is usable. I am currently working on adding more features and improving the code. If you have any suggestions, please feel free to open an issue on GitHub.

Installation

MaxGradient can be installed from PyPi using your favorite python package manager:

PDM (Recommended)

pdm add maxgradient

PIP

pip install maxgradient

Usage

Quick Start

The basic usage of MaxGradient is as a RichRenderable. Like any other RichRenderable, it can be printed to the console using the print() method of a rich.console.Console() object.

Example

#imports
from rich.console import Console
from maxgradient import Gradient

console = Console() # Initialize a console
console.print(
    Gradient("Hello, World!", justify="center") # Print a gradient
)
Hello, World!

Gradient with Color

MaxGradient easily make random gradients that require no more than the text you wish to color, it can also be used to make gradients with specific colors. The gradient() method takes a string of text as well as a list of colors. The number of colors in the list determines the number of colors in the gradient. The gradient will be evenly distributed between the colors in the list. The gradient will be applied to the text in the order it is given in the list.

MaxGradient accepts the following as

  • color names (magenta, purple, violet, blue, dogerblue, deepskyblue, lightskyblue, cyan, springgreen, lime, greenyellow, yellow, orange, darkorange, red, deeppink, hotpink)
  • hex color codes (3-digit -> #f0f, 6-digit -> #ff00ff)
  • rgb color codes
  • CSS3 named colors
  • as well as any colors from rich's standard library.

Let's take a look at some examples:

Example 1

from rich.conosle import Console
from maxgradient import Gradient

console = Console()

console.print(
    Gradient(
        "This gradient contains the colors: magenta, violet, and purple.",
        colors = [
            "magenta",
            "violet",
            "purple"
        ]
    )
)
Gradient with Color 1


Example 2

You are not just stuck with ROY G BIV colors, you can use any colors you want. Let's make a gradient with the colors: magenta, violet, purple, dodgerblue, deepskyblue, lightskyblue, and cyan.

console.print(
    Gradient(
        "This gradient contains the colors: magenta, violet, purple, blue, dodgerblue, and cyan.",
        colors = [
            "rgb(255,0,255)", # rgb | magenta
            "violet", # named (#af00ff)
            "#5f00ff", # hex | purple
            "blue", # another named
            "rgb(0,85,255)", # rgb | dodWilWgerblue
            "cyan" # and another
        ]
    )
)

Gradient with Color 2

Gradient Rule

MaxGradient also includes a GradientRule. The GradientRule is a Rich Renderable that prints a horizontal rule to the console in gradient color. It can be used to separate sections of text in a gradient colored console output.

The GradientRule is currently initialized with random colors and does not at the momement allow for custimization of these colors.

It does however allow the user to specify the thickness of the rule. The thickness is specified by the thickness keyword argument. The thickeness can be specified as the 'thin', 'medium', or 'thick'. The default thickness is 'medium'.

from rich.console import Console
from maxgradient import GradientRule

console = Console()
console.print("[u b #ffffff]Rule Examples[/]", justify="center")
console.line()
console.print(GradientRule(title=f"{title}", thickness="thin", align="left"))
console.line()
console.print(
    GradientRule(
        title="Thin Gradient Rule",
        gradient=True,
        thickness="thin",
        align="center",
    )
)
console.line()
console.print(
    GradientRule(title="Medium Gradient Rule", gradient=True, align="right")
)
console.line()
console.print(
    GradientRule(
        title="Medium Left-aligned Non-gradient Rule",
        gradient=False,
        thickness="medium",
        align="left",
    )
)
console.line()
console.print(
    GradientRule(title="Medium Right-aligned Gradient Rule", align="right")
)
console.line()
console.print(GradientRule("Thick Gradient Rule", thickness="thick"))
Gradient Rule Examples
Created by
Max Ludden's Logo
Max Ludden

Metadata

Release files for maxgradient 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maxgradient 0.3.1
File Size Uploaded
maxgradient-0.3.1.tar.gz 2.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for maxgradient 0.3.1
File Interpreter ABI Platform
maxgradient-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.3 MB

Release files / maxgradient-0.3.1.tar.gz

Download URL maxgradient-0.3.1.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
8d2fcfb001e7f1b57acc8193c7c0591ef8f403e8874c123f016895b70c0b6440
BLAKE2b-256 checksum
How to use checksums
0e07cef5ea00391fe9095758485fc51e254befeef7136ffc3eefeaad73808d98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.12.4 CPython/3.12.1

Release files / maxgradient-0.3.1-py3-none-any.whl

Download URL maxgradient-0.3.1-py3-none-any.whl
Size 3.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
d0dc8b20d8aa52acd0246ad2120bf6b017cc6b22c6556f0fa085ba5829a902dc
BLAKE2b-256 checksum
How to use checksums
e1aaff41e8a4155047f993d51608d45090d4453c45800656174a9334fe3c6221
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.12.4 CPython/3.12.1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page