Skip to content

Commit ece71ed

Browse files
authoredOct 13, 2024
Merge pull request #992 from ExPl0iT-29/main
Added Color Palette Generator
2 parents a1068d9 + 64a1bae commit ece71ed

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed
 

‎color_palette_generator/Readme.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Color Palette Generator
2+
3+
## Short Description
4+
This is a simple web application built with Flask that generates a random color palette. Users can specify the number of colors in the palette (between 1 and 10), and the app will display the corresponding colors in a visually appealing way.
5+
6+
## Functionality
7+
- Generate random color palettes with customizable color count.
8+
- Display color hex codes for each generated color.
9+
- Interactive UI to adjust the number of colors displayed.
10+
11+
## Folder Structure
12+
13+
color_palette_generator/
14+
15+
├── app.py # Main Flask application file
16+
├── templates/
17+
│ └── index.html # HTML template for the app
18+
├── requirements.txt # Python dependencies file
19+
└── README.md # Instructions for the program
20+
21+
22+
## Instructions for Each File:
23+
1. app.py:
24+
The main Flask application script, which generates random color palettes and serves them via a web interface.
25+
26+
2. templates/index.html:
27+
HTML file that displays the color palette on the front end and allows the user to input the number of colors.
28+
29+
3. requirements.txt:
30+
List of dependencies required to run the project.
31+
32+
## Setup Instructions
33+
1. Clone the repository or download the project files.
34+
2. Navigate to the project folder in your terminal:
35+
```bash
36+
cd color_palette_generator
37+
```
38+
3. Install the required dependencies using pip:
39+
```bash
40+
pip install -r requirements.txt
41+
```
42+
4. Run the Flask app:
43+
```bash
44+
python app.py
45+
```
46+
5. Open your browser and go to http://127.0.0.1:5000/ to use the app.
47+
48+
49+
## Detailed Explanation
50+
- The app.py script creates a Flask web server that serves an HTML page (index.html) where users can generate color palettes.
51+
- The generate_color_palette() function in app.py generates a list of random hexadecimal colors using the random module.
52+
- The front-end (index.html) uses a form to capture the user's input for the number of colors, and the results are displayed using a simple CSS grid for visualization.
53+
- Each color is displayed as a square with its corresponding hex code.
54+
55+
## Output
56+
57+
![Output](image.png)
58+
59+
## Author(s)
60+
explooit
61+
https://github.com/ExPl0iT-29
62+
63+
## Disclaimers
64+
- The project uses random color generation and does not guarantee aesthetically balanced palettes.

‎color_palette_generator/image.png

18.1 KB
Loading

‎color_palette_generator/main.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from flask import Flask, render_template, request
2+
import random
3+
4+
app = Flask(__name__)
5+
6+
7+
# Function to generate random color palette
8+
def generate_color_palette(num_colors=5):
9+
"""Generate a list of random hex color codes."""
10+
colors = []
11+
for _ in range(num_colors):
12+
color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
13+
colors.append(color)
14+
return colors
15+
16+
17+
# Home route to display the color palette generator
18+
@app.route('/', methods=['GET', 'POST'])
19+
def home():
20+
if request.method == 'POST':
21+
num_colors = int(request.form.get('num_colors', 5))
22+
color_palette = generate_color_palette(num_colors)
23+
else:
24+
color_palette = generate_color_palette()
25+
return render_template('index.html', color_palette=color_palette)
26+
27+
28+
if __name__ == '__main__':
29+
app.run(debug=True)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flask==2.2.3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Color Palette Generator</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
text-align: center;
11+
margin-top: 50px;
12+
}
13+
.palette {
14+
display: flex;
15+
justify-content: center;
16+
margin-top: 20px;
17+
}
18+
.color-box {
19+
width: 100px;
20+
height: 100px;
21+
margin: 5px;
22+
border-radius: 10px;
23+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
24+
}
25+
</style>
26+
</head>
27+
<body>
28+
<h1>Random Color Palette Generator</h1>
29+
<form method="POST">
30+
<label for="num_colors">Number of Colors:</label>
31+
<input type="number" id="num_colors" name="num_colors" min="1" max="10" value="5">
32+
<button type="submit">Generate Palette</button>
33+
</form>
34+
35+
<div class="palette">
36+
{% for color in color_palette %}
37+
<div class="color-box" style="background-color: {{ color }};" title="{{ color }}"></div>
38+
{% endfor %}
39+
</div>
40+
</body>
41+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.