-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit.py
114 lines (100 loc) · 4.68 KB
/
streamlit.py
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
import streamlit as st
from datetime import datetime
import math
import pytz
class RelojApp:
def __init__(self):
st.set_page_config(page_title="Reloj Analógico y Digital", layout="centered")
self.zonas_horarias = pytz.all_timezones
self.zona_horaria = st.selectbox("Selecciona tu zona horaria:", self.zonas_horarias, index=18) # Establecer la zona horaria predeterminada
self.actualizar_reloj()
def obtener_estacion(self, now):
mes = now.month
if 3 <= mes <= 5:
return "Primavera"
elif 6 <= mes <= 8:
return "Verano"
elif 9 <= mes <= 11:
return "Otoño"
else:
return "Invierno"
def actualizar_reloj(self):
tz = pytz.timezone(self.zona_horaria) # Obtener la zona horaria seleccionada
now = datetime.now(tz)
hora_actual = now.strftime("%H:%M:%S")
fecha_actual = now.strftime("%A, %d de %B de %Y")
estacion_actual = self.obtener_estacion(now)
st.markdown(
"""
<style>
.titulo {
font-size: 48px;
color: #FF00FF;
text-align: center;
font-weight: bold;
margin-bottom: 20px;
}
.descripcion {
font-size: 28px;
color: #00FFFF;
text-align: center;
font-weight: bold;
margin-bottom: 20px;
}
.texto {
font-size: 36px;
color: #000000;
text-align: center;
font-weight: bold;
margin-bottom: 10px;
}
.reloj-container {
display: flex;
justify-content: center;
align-items: center;
}
</style>
""",
unsafe_allow_html=True
)
st.markdown('<p class="titulo">VAPORWAVE CLOCK</p>', unsafe_allow_html=True)
st.markdown('<p class="descripcion">Reloj Analógico</p>', unsafe_allow_html=True)
self.dibujar_reloj_analogico(now)
st.markdown('<p class="texto">Hora actual: ' + hora_actual + '</p>', unsafe_allow_html=True)
st.markdown('<p class="texto">Fecha actual: ' + fecha_actual + '</p>', unsafe_allow_html=True)
st.markdown('<p class="texto">Estación: ' + estacion_actual + '</p>', unsafe_allow_html=True)
# Programar la actualización cada 1000 ms (1 segundo)
st.experimental_rerun()
def dibujar_reloj_analogico(self, now):
centro_x = 200
centro_y = 200
radio = 150
with st.container():
st.markdown(
f'<div class="reloj-container"><svg height="400" width="400"> \
<circle cx="{centro_x}" cy="{centro_y}" r="{radio}" stroke="#FFFFFF" stroke-width="2" fill="transparent" /> \
{"".join([self.dibujar_marcador(i, centro_x, centro_y, radio) for i in range(60)])} \
{"".join([self.dibujar_numero(i, centro_x, centro_y, radio) for i in range(12)])} \
{self.dibujar_mano(now.second, 60, centro_x, centro_y, radio, 0.7, "#FF0000")} \
{self.dibujar_mano(now.minute, 60, centro_x, centro_y, radio, 0.6, "#00FFFF")} \
{self.dibujar_mano(now.hour % 12 * 5 + now.minute / 12, 60, centro_x, centro_y, radio, 0.4, "#FF00FF")} \
</svg></div>',
unsafe_allow_html=True
)
def dibujar_marcador(self, indice, centro_x, centro_y, radio):
angulo_marcador = math.radians(90 - indice * 6)
x_marcador = centro_x + (radio - 10) * math.cos(angulo_marcador)
y_marcador = centro_y - (radio - 10) * math.sin(angulo_marcador)
return f'<circle cx="{x_marcador}" cy="{y_marcador}" r="2" fill="#000000" />'
def dibujar_numero(self, indice, centro_x, centro_y, radio):
angulo_numero = math.radians(90 - indice * 30)
x_numero = centro_x + (radio - 30) * math.cos(angulo_numero)
y_numero = centro_y - (radio - 30) * math.sin(angulo_numero)
return f'<text x="{x_numero}" y="{y_numero}" font-family="Helvetica" font-size="16" fill="#000000" text-anchor="middle">{12 if indice == 0 else indice}</text>'
def dibujar_mano(self, valor, max_valor, centro_x, centro_y, radio, largo, color):
angulo = math.radians(90 - valor / max_valor * 360)
x_final = centro_x + radio * largo * math.cos(angulo)
y_final = centro_y - radio * largo * math.sin(angulo)
return f'<line x1="{centro_x}" y1="{centro_y}" x2="{x_final}" y2="{y_final}" stroke="{color}" stroke-width="4" />'
if __name__ == "__main__":
app = RelojApp()