-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy-precious_goal_tracker.py
More file actions
241 lines (198 loc) · 10.1 KB
/
py-precious_goal_tracker.py
File metadata and controls
241 lines (198 loc) · 10.1 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import tkinter as tk
from tkinter import font
import random
import math
import os
# Archivo de guardado
ARCHIVO_DATOS = "anillo_data.txt"
class AnilloPerfeccionado:
def __init__(self, root):
self.root = root
self.registro = 0
self.particulas = []
self.timer_mensaje = None
self.anim_step = 0 # Para la animación del ojo
# --- 1. CARGAR DATOS ---
self.cargar_registro()
# --- 2. CONFIGURACIÓN DE VENTANA ---
self.width = 340
self.height = 340
self.cx = self.width // 2
self.cy = self.height // 2
screen_w = self.root.winfo_screenwidth()
screen_h = self.root.winfo_screenheight()
x_pos = (screen_w - self.width) // 2
y_pos = (screen_h - self.height) // 2
self.root.geometry(f"{self.width}x{self.height}+{x_pos}+{y_pos}")
self.bg_color = "#000001"
self.root.configure(bg=self.bg_color)
self.root.overrideredirect(True)
self.root.wm_attributes("-topmost", True)
self.root.wm_attributes("-transparentcolor", self.bg_color)
self.root.update_idletasks()
self.root.lift()
self.canvas = tk.Canvas(self.root, width=self.width, height=self.height,
bg=self.bg_color, highlightthickness=0)
self.canvas.pack()
# --- 5. DIBUJAR ELEMENTOS ---
self.dibujar_anillo()
self.dibujar_ojo_detalle()
self.dibujar_botones_discretos()
# Paso 1: Números en la parte inferior DENTRO del cuerpo del anillo
self.fuente_num = font.Font(family="Georgia", size=14, weight="bold")
pos_y_numero = self.cy + 58
self.canvas.create_text(self.cx + 1, pos_y_numero + 1,
text=str(self.registro), fill="black",
font=self.fuente_num, tags="num_shadow")
self.texto_id = self.canvas.create_text(self.cx, pos_y_numero,
text=str(self.registro), fill="#FFD700",
font=self.fuente_num, tags="num_main")
# Paso 5: Texto modificado
fuente_precious = font.Font(family="Gabriola", size=20, weight="bold", slant="italic")
if "Gabriola" not in font.families():
fuente_precious = font.Font(family="Arial", size=14, weight="bold", slant="italic")
self.txt_precious = self.canvas.create_text(self.cx, self.cy + 95,
text="My precious goal!", fill="#FF4500",
font=fuente_precious, state="hidden")
# --- EVENTOS ---
self.canvas.tag_bind("arrastrable", "<ButtonPress-1>", self.guardar_posicion)
self.canvas.tag_bind("arrastrable", "<B1-Motion>", self.mover_ventana)
self.canvas.bind("<Button-3>", self.cerrar_app)
self.animar_particulas()
self.animar_ojo()
def cargar_registro(self):
if os.path.exists(ARCHIVO_DATOS):
try:
with open(ARCHIVO_DATOS, "r") as f:
self.registro = int(f.read())
except: self.registro = 0
else: self.registro = 0
def guardar_registro(self):
try:
with open(ARCHIVO_DATOS, "w") as f:
f.write(str(self.registro))
except: pass
def cerrar_app(self, event=None):
self.guardar_registro()
self.root.destroy()
def dibujar_anillo(self):
r_outer = 68
r_inner = 48
self.canvas.create_oval(self.cx-r_outer+2, self.cy-r_outer+2, self.cx+r_outer+2, self.cy+r_outer+2,
fill="#1a1a1a", outline="", tags="arrastrable")
self.canvas.create_oval(self.cx-r_outer, self.cy-r_outer, self.cx+r_outer, self.cy+r_outer,
fill="#6d4c41", outline="#3e2723", width=1, tags="arrastrable")
self.canvas.create_oval(self.cx-r_outer+2, self.cy-r_outer+2, self.cx+r_outer-2, self.cy+r_outer-2,
fill="#B8860B", outline="", tags="arrastrable")
self.canvas.create_oval(self.cx-r_outer+5, self.cy-r_outer+5, self.cx+r_outer-5, self.cy+r_outer-5,
fill="#FFD700", outline="", tags="arrastrable")
self.canvas.create_oval(self.cx-r_outer+10, self.cy-r_outer+10, self.cx+r_outer-10, self.cy+r_outer-10,
outline="#FFEC8B", width=2, tags="arrastrable")
self.canvas.create_arc(self.cx-r_outer+7, self.cy-r_outer+7, self.cx+r_outer-7, self.cy+r_outer-7,
start=135, extent=45, style=tk.ARC, outline="#FFFFFF", width=5, tags="arrastrable")
self.canvas.create_oval(self.cx-r_inner, self.cy-r_inner, self.cx+r_inner, self.cy+r_inner,
fill=self.bg_color, outline="#5d4037", width=2, tags="arrastrable")
def dibujar_ojo_detalle(self):
self.eye_y = self.cy - 10
eye_w = 28
eye_h = 16
# Efecto de volumen (Sombras profundas)
self.canvas.create_oval(self.cx-eye_w-4, self.eye_y-eye_h-4, self.cx+eye_w+4, self.eye_y+eye_h+4,
fill="#420000", outline="", tags="ojo_aura")
# Iris con brillo
self.canvas.create_oval(self.cx-eye_w, self.eye_y-eye_h, self.cx+eye_w, self.eye_y+eye_h,
fill="#FF4500", outline="#8B0000", width=1, tags="ojo_iris")
# Brillo superior del ojo para volumen
self.canvas.create_arc(self.cx-eye_w+5, self.eye_y-eye_h+2, self.cx+eye_w-5, self.eye_y+eye_h-2,
start=40, extent=100, style=tk.ARC, outline="#FFD700", width=2, tags="ojo_brillo")
# Pupila
self.canvas.create_oval(self.cx-2, self.eye_y-eye_h+2, self.cx+2, self.eye_y+eye_h-2,
fill="black", outline="", tags="ojo_pupila")
self.canvas.tag_bind("ojo_aura", "<Button-1>", lambda e: self.reset_conteo())
self.canvas.tag_bind("ojo_iris", "<Button-1>", lambda e: self.reset_conteo())
self.canvas.tag_bind("ojo_pupila", "<Button-1>", lambda e: self.reset_conteo())
def animar_ojo(self):
self.anim_step += 0.2
scale = math.sin(self.anim_step) * 3
self.canvas.itemconfig("ojo_aura", width=scale if scale > 0 else 0)
# Movimiento sutil de la pupila
move_x = math.sin(self.anim_step * 0.5) * 4
self.canvas.coords("ojo_pupila", self.cx-2+move_x, self.eye_y-14, self.cx+2+move_x, self.eye_y+14)
self.root.after(50, self.animar_ojo)
def dibujar_botones_discretos(self):
color_btn = "#996515"
# Usamos Courier para que el "-" tenga el mismo grosor que el "+"
font_btn = ("Courier", 14, "bold")
self.canvas.create_text(self.cx - 56, self.cy, text="-", fill=color_btn, font=font_btn, tags="btn_menos")
self.canvas.create_text(self.cx + 56, self.cy, text="+", fill=color_btn, font=font_btn, tags="btn_mas")
self.canvas.tag_bind("btn_menos", "<Button-1>", lambda e: self.restar())
self.canvas.tag_bind("btn_mas", "<Button-1>", lambda e: self.sumar())
def reset_conteo(self):
self.registro = 0
self.actualizar_texto()
self.guardar_registro()
def guardar_posicion(self, event):
self._x = event.x
self._y = event.y
def mover_ventana(self, event):
deltax = event.x - self._x
deltay = event.y - self._y
x = self.root.winfo_x() + deltax
y = self.root.winfo_y() + deltay
self.root.geometry(f"+{x}+{y}")
def restar(self):
self.registro -= 1
self.actualizar_texto()
self.guardar_registro()
def sumar(self):
self.registro += 1
self.actualizar_texto()
self.guardar_registro()
self.efecto_click()
def actualizar_texto(self):
self.canvas.itemconfig("num_shadow", text=str(self.registro))
self.canvas.itemconfig("num_main", text=str(self.registro))
def efecto_click(self):
self.canvas.itemconfig(self.txt_precious, state="normal")
if self.timer_mensaje: self.root.after_cancel(self.timer_mensaje)
self.timer_mensaje = self.root.after(1500, lambda: self.canvas.itemconfig(self.txt_precious, state="hidden"))
self.lanzar_estrellas()
def lanzar_estrellas(self):
colores = ["#FFD700", "#FFFFFF", "#FF8C00"]
cx, cy = self.cx, self.cy
for _ in range(25):
angle = random.uniform(0, 2 * math.pi)
radio = 60
sx = cx + math.cos(angle) * radio
sy = cy + math.sin(angle) * radio
size = random.randint(3, 7)
color = random.choice(colores)
pts = [sx, sy-size, sx+size/3, sy, sx, sy+size, sx-size/3, sy]
p_id = self.canvas.create_polygon(pts, fill=color, outline="")
speed = random.uniform(2, 6)
vx = math.cos(angle) * speed
vy = math.sin(angle) * speed
self.particulas.append([p_id, vx, vy, 40])
def animar_particulas(self):
radio_limite = 160
for i in range(len(self.particulas)-1, -1, -1):
p_id, vx, vy, vida = self.particulas[i]
self.canvas.move(p_id, vx, vy)
vida -= 1
coords = self.canvas.coords(p_id)
if coords:
px = (coords[0] + coords[4]) / 2
py = (coords[1] + coords[5]) / 2
dist = math.hypot(px - self.cx, py - self.cy)
if dist > radio_limite:
vida = 0
if vida <= 0:
self.canvas.delete(p_id)
self.particulas.pop(i)
else:
self.particulas[i][3] = vida
self.root.after(30, self.animar_particulas)
if __name__ == "__main__":
root = tk.Tk()
app = AnilloPerfeccionado(root)
root.mainloop()