A simple Python application that generates random RGB colours and displays colourful text directly in the terminal. This project demonstrates the practical use of Python's built-in random module and the third-party sty library.
The Random Color Generator generates three random RGB values (Red, Green, Blue) and uses them to create a randomly coloured terminal message.
Every time the program runs, it generates a different colour, making the terminal output dynamic and entertaining.
Example message:
I am randomly changing color muahhahahahahahahaha
The text colour changes every time the program executes.
- Generates random RGB colour values.
- Uses Python's built-in
randommodule. - Applies terminal foreground colours using the
stylibrary. - Uses reusable user-defined functions.
- Demonstrates tuple returning and unpacking.
- Displays randomly coloured terminal text.
- Lightweight and easy to execute.
| Technology | Purpose |
|---|---|
| Python | Core programming language |
random |
Generates random RGB values |
sty |
Applies terminal text colours |
Random-Color-Generator/
│
├── README.md
├── app.py
├── app.ipynb
└── requirements.txt
| File | Description |
|---|---|
app.py |
Main executable Python application |
app.ipynb |
Jupyter Notebook containing explanations, examples and implementation |
requirements.txt |
External project dependencies |
README.md |
Project documentation |
git clone <your-repository-url>cd Random-Color-Generatorpython -m venv .venvActivate it on Windows:
.venv\Scripts\activatepip install -r requirements.txtpython app.pyThis project applies several fundamental Python programming concepts:
- Module Importing: Importing and using built-in and third-party modules.
- Random Number Generation: Generating random integers using
random.randint(). - User-Defined Functions: Creating reusable functions to perform specific operations.
- Function Parameters: Passing RGB values between functions.
- Return Statements: Returning multiple values from a function.
- Tuples: Storing multiple RGB values together.
- Tuple Unpacking: Assigning returned tuple values to individual variables.
- Third-Party Libraries: Installing and using external Python packages.
- Terminal Formatting: Applying foreground colours to terminal text.
The application follows a simple execution workflow:
- Import the required modules.
- Generate three random RGB values between 0 and 255.
- Return the RGB values as a tuple.
- Unpack the tuple into separate variables.
- Pass the RGB values to the colour-generation function.
- Use
sty.fg()to generate the terminal foreground colour. - Print the message using the generated colour.
- Reset terminal formatting.
Potential enhancements for this project include:
- Generate multiple random colours in one execution.
- Add random background colour generation.
- Display RGB and HEX colour codes.
- Create a continuous colour-changing mode.
- Allow users to generate colours on demand.
- Build a graphical colour picker interface.
Gursimran Singh
B.Tech Computer Science Engineering (Artificial Intelligence & Machine Learning)
GitHub: @gursimranai
Part of my Python programming and project-based learning journey.
⭐ If you find this project useful, consider giving the repository a star!