Skip to content

Commit 1abba0b

Browse files
committed
ADD:givemecolor
0 parents  commit 1abba0b

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Giveme Color
2+
3+
Giveme Color is a simple Python package that generates a random color and copies it to the clipboard. It’s a handy tool for quickly obtaining a random color code for your projects.
4+
5+
## Features
6+
7+
- Generates a random color.
8+
- Automatically copies the color code to your clipboard.
9+
10+
## Installation
11+
12+
You can install Giveme Color via pip:
13+
14+
```bash
15+
pip install givemecolor
16+
```
17+
18+
## Usage
19+
20+
### Method 1: Directly from Python
21+
22+
First, import the package in your Python script:
23+
24+
```python
25+
import givemecolor
26+
```
27+
28+
Then, call the function to generate a random color:
29+
30+
```python
31+
givemecolor.givemecolor()
32+
```
33+
34+
### Method 2: Using an Alias
35+
36+
Alternatively, you can import the function directly:
37+
38+
```python
39+
from givemecolor import givemecolor
40+
```
41+
42+
And call it the same way:
43+
44+
```python
45+
givemecolor()
46+
```
47+
48+
The color code will be copied to your clipboard automatically, so you can easily paste it wherever needed.
49+
50+
### Command Line Usage
51+
52+
After installation, you can also use `givemecolor` directly from the command line:
53+
54+
```bash
55+
givemecolor
56+
```
57+
58+
This command will generate a random color and copy the color code to your clipboard.
59+
60+
## Example
61+
62+
Here’s a quick example of using Giveme Color in a Python script:
63+
64+
```python
65+
from givemecolor import givemecolor
66+
67+
# Generate a random color and copy it to the clipboard
68+
givemecolor()
69+
```
70+
71+
## About the Author
72+
73+
Giveme Color is created by Parth Dudhatra (imParth), a passionate software engineer, developer advocate, and content creator known for his contributions to the tech community. Parth is dedicated to frontend development, Python programming, open-source software, and sharing knowledge with others.
74+
75+
Parth is active on various social media platforms, where he shares insights, tutorials, and tips related to programming, web development, and software engineering. Parth's dedication to sharing his expertise and fostering a supportive environment for developers has earned him recognition and respect within the tech community.
76+
77+
You can connect with Parth on social media:
78+
79+
- [Portfolio](https://imparth.me)
80+
- [X/Twitter](https://x.com/imparth73)
81+
- [Instagram](https://instagram.com/imparth.dev)
82+
- [GitHub](https://github.com/imparth7)
83+
- [LinkedIn](https://linkedin.com/in/imparth7)
84+
- [Medium](https://imparth7.medium.com)
85+
- [Dev.to](https://dev.to/imparth)
86+
87+
If you have any questions, feedback, or suggestions, feel free to reach out on any platform!

givemecolor/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .main import givemecolor

givemecolor/main.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import random
2+
import sys
3+
import subprocess
4+
5+
6+
def givemecolor():
7+
# Generate random values for red, green, and blue components
8+
red = random.randint(0, 255)
9+
green = random.randint(0, 255)
10+
blue = random.randint(0, 255)
11+
12+
# Convert decimal to hexadecimal format
13+
red_hex = f"{red:02x}"
14+
green_hex = f"{green:02x}"
15+
blue_hex = f"{blue:02x}"
16+
17+
# Calculate luminance
18+
luminance = (0.299 * red + 0.587 * green + 0.114 * blue) / 255
19+
20+
# Determine luminance color
21+
lum_color = "0;0;0" if luminance > 0.5 else "255;255;255"
22+
23+
# Concatenate the components to form the color code
24+
color = f"#{red_hex}{green_hex}{blue_hex}"
25+
26+
# Copy to clipboard
27+
copy_to_clipboard(color)
28+
29+
# Print the color
30+
print(f"\033[48;2;{red};{green};{blue}m\033[38;2;{lum_color}m{color}\033[0m")
31+
32+
33+
def copy_to_clipboard(color):
34+
# Determine the platform
35+
if sys.platform == "win32":
36+
# Windows
37+
subprocess.run(f"echo {color.strip()} | clip", shell=True)
38+
else:
39+
# macOS and Linux
40+
subprocess.run(f"echo -n {color.strip()} | pbcopy", shell=True)
41+
42+
43+
if __name__ == "__main__":
44+
givemecolor()

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name="givemecolor",
5+
version="1.0.1",
6+
description="Giveme Color is a random color generator package. Every time it returns a new random color and copies it to your clipboard.",
7+
long_description=open("README.md").read(),
8+
long_description_content_type="text/markdown",
9+
author="imparth",
10+
url="https://github.com/imparth7/giveme-color-py",
11+
packages=find_packages(),
12+
classifiers=[
13+
"Programming Language :: Python :: 3",
14+
"License :: OSI Approved :: MIT License",
15+
"Operating System :: OS Independent",
16+
],
17+
keywords=["random", "color"],
18+
python_requires=">=3.6",
19+
entry_points={
20+
"console_scripts": [
21+
"givemecolor=givemecolor:givemecolor",
22+
],
23+
},
24+
project_urls={
25+
"Bug Reports": "https://github.com/imparth7/giveme-color-py/issues",
26+
"Homepage": "https://github.com/imparth7/giveme-color-py#readme",
27+
},
28+
)

0 commit comments

Comments
 (0)