-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1
More file actions
91 lines (75 loc) · 2.57 KB
/
1
File metadata and controls
91 lines (75 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import random
import json
import os
try:
import pyperclip
clipboard_enabled = True
except ImportError:
clipboard_enabled = False
PALETTES_FILE = "color_palettes.json"
def generate_color():
return "#{:06x}".format(random.randint(0, 0xFFFFFF)).upper()
def generate_palette(n=5):
return [generate_color() for _ in range(n)]
def save_palette(palette, name):
if not os.path.exists(PALETTES_FILE):
palettes = {}
else:
with open(PALETTES_FILE, "r") as f:
palettes = json.load(f)
palettes[name] = palette
with open(PALETTES_FILE, "w") as f:
json.dump(palettes, f, indent=4)
print(f"✅ Palette '{name}' saved.")
def list_palettes():
if not os.path.exists(PALETTES_FILE):
print("📭 No saved palettes yet.")
return
with open(PALETTES_FILE, "r") as f:
palettes = json.load(f)
print("\n🎨 Saved Palettes:")
for name, colors in palettes.items():
print(f"{name}: {', '.join(colors)}")
def copy_to_clipboard(palette):
if clipboard_enabled:
pyperclip.copy(", ".join(palette))
print("📋 Palette copied to clipboard!")
else:
print("⚠️ pyperclip not installed. Can't copy to clipboard.")
def main():
while True:
print("\n=== ColorCraft: Color Palette Generator ===")
print("1 - Generate new palette")
print("2 - Save current palette")
print("3 - View saved palettes")
print("4 - Copy palette to clipboard")
print("5 - Exit")
choice = input("Choose an option: ").strip()
if choice == "1":
try:
count = int(input("How many colors? (default 5): ") or 5)
palette = generate_palette(count)
print("🎨 Generated Palette:", ", ".join(palette))
except ValueError:
print("❌ Please enter a valid number.")
elif choice == "2":
if not palette:
print("⚠️ No palette generated yet.")
continue
name = input("Enter a name for this palette: ")
save_palette(palette, name)
elif choice == "3":
list_palettes()
elif choice == "4":
if not palette:
print("⚠️ No palette generated yet.")
continue
copy_to_clipboard(palette)
elif choice == "5":
print("👋 Goodbye, creative soul!")
break
else:
print("❌ Invalid choice.")
if __name__ == "__main__":
palette = [] # Global for current session
main()