Lukeetah commited on
Commit
7b3c46f
verified
1 Parent(s): d929bac

Update helpers.py

Browse files
Files changed (1) hide show
  1. helpers.py +70 -99
helpers.py CHANGED
@@ -4,121 +4,92 @@ import numpy as np
4
  from pydub import AudioSegment
5
  from pydub.generators import Sine
6
  from io import BytesIO
 
7
 
8
- # --- Paleta de Colores Emocionales ---
9
- EMOTION_COLORS = {
10
- "tristeza": [(0, 20, 80), (50, 80, 150), (100, 100, 100)],
11
- "miedo": [(10, 0, 10), (50, 20, 50), (120, 100, 120)],
12
- "rabia": [(100, 0, 10), (200, 50, 20), (255, 100, 0)],
13
- "ansiedad": [(200, 200, 0), (150, 150, 50), (80, 80, 80)],
14
- "culpa": [(80, 50, 20), (50, 30, 10), (100, 100, 100)],
15
- "soledad": [(20, 20, 40), (80, 80, 120), (150, 150, 180)],
16
- "default": [(100, 100, 150), (200, 200, 220), (50, 50, 80)]
17
- }
18
-
19
- def get_color_palette(emotion_text):
20
- emotion_text = emotion_text.lower()
21
- for key, colors in EMOTION_COLORS.items():
22
- if key in emotion_text:
23
- return colors
24
- return EMOTION_COLORS["default"]
25
-
26
- # --- Generaci贸n de Audio Elemental ---
27
- def generate_elemental_audio(element="theta_only", duration_ms=120000):
28
- base_freq = 100
29
- binaural_freq = 6
30
- left_sine = Sine(base_freq).to_audio_segment(duration=duration_ms, volume=-20).set_channels(1)
31
- right_sine = Sine(base_freq + binaural_freq).to_audio_segment(duration=duration_ms, volume=-20).set_channels(1)
32
  binaural_beat = AudioSegment.from_mono_audiosegments(left_sine, right_sine)
33
- final_sound = binaural_beat
34
- #... (el resto de la l贸gica de audio se mantiene igual)
35
- buffer = BytesIO()
36
- final_sound.export(buffer, format="wav")
37
- filename = f"{element}_binaural.wav"
38
- with open(filename, 'wb') as f:
39
- f.write(buffer.getvalue())
40
  return filename
41
 
42
- # --- Generaci贸n de Sigilo Bio-Resonante ---
43
- def generate_bioresonant_sigil(emotion, location, size=512):
44
- if not emotion and not location:
45
- return Image.new('RGB', (size, size), 'black')
46
- text_input = emotion + " " + location
47
  hash_object = hashlib.sha256(text_input.encode('utf-8'))
48
- hex_dig = hash_object.hexdigest()
49
- seed = [int(hex_dig[i:i+2], 16) for i in range(0, len(hex_dig), 2)]
50
- img = Image.new('RGB', (size, size), 'black')
51
  draw = ImageDraw.Draw(img)
52
  center_x, center_y = size // 2, size // 2
53
- palette = get_color_palette(emotion)
54
- location = location.lower()
55
- num_lines = 8 + (seed[0] % 8)
56
- base_radius_factor = 0.2
57
- #... (el resto de la l贸gica del sigilo se mantiene igual)
58
- for i in range(num_lines):
59
- # ... L贸gica de dibujo ...
60
  s_idx = (i * 4) % len(seed)
61
- color = palette[i % len(palette)]
62
- start_angle = (seed[s_idx] / 255) * 360
63
- end_angle = (seed[s_idx+1] / 255) * 360
64
- radius1 = size * base_radius_factor + (seed[s_idx+2] / 255) * (size * 0.2)
65
- radius2 = size * 0.1 + (seed[s_idx+3] / 255) * (size * 0.4)
66
- start_x = center_x + radius1 * np.cos(np.deg2rad(start_angle))
67
- start_y = center_y + radius1 * np.sin(np.deg2rad(start_angle))
68
- end_x = center_x + radius2 * np.cos(np.deg2rad(end_angle))
69
- end_y = center_y + radius2 * np.sin(np.deg2rad(end_angle))
70
- draw.line((start_x, start_y, end_x, end_y), fill=color, width=1)
71
- draw.line((size - start_x, start_y, size - end_x, end_y), fill=color, width=1)
72
- return img.filter(ImageFilter.GaussianBlur(radius=1))
73
 
 
 
 
74
 
75
- # --- NUEVA FUNCI脫N: Generador de GIF Aut贸nomo ---
76
  def create_quantum_tunnel_gif(filename="quantum_tunnel.gif", size=300, num_frames=20):
77
- """
78
- Genera un GIF animado de un t煤nel de part铆culas abstractas.
79
- """
80
  frames = []
81
  for i in range(num_frames):
82
- # Fondo oscuro
83
- img = Image.new('RGB', (size, size), (13, 13, 13))
84
- draw = ImageDraw.Draw(img)
85
  center_x, center_y = size // 2, size // 2
86
-
87
- # Simular part铆culas movi茅ndose
88
- # La semilla cambia con cada frame para la animaci贸n
89
  np.random.seed(i)
90
-
91
- for _ in range(100): # 100 part铆culas por frame
92
- # Posici贸n inicial aleatoria
93
- angle = np.random.uniform(0, 2 * np.pi)
94
- radius = np.random.uniform(0, size / 2)
95
-
96
- # Mover la part铆cula hacia afuera
97
- radius_offset = (i / num_frames) * 20 # Mueve las part铆culas
98
- new_radius = (radius + radius_offset) % (size / 2)
99
-
100
- x = center_x + new_radius * np.cos(angle)
101
- y = center_y + new_radius * np.sin(angle)
102
-
103
- # El color se basa en la paleta del Crisol
104
- color = (
105
- np.random.randint(150, 220), # R
106
- np.random.randint(100, 200), # G
107
- np.random.randint(200, 255) # B -> Tonos p煤rpura/azulados
108
- )
109
-
110
- # Dibujar part铆cula
111
  draw.point((x, y), fill=color)
112
-
113
  frames.append(img)
 
 
114
 
115
- # Guardar los frames como un GIF animado
116
- frames[0].save(
117
- filename,
118
- save_all=True,
119
- append_images=frames[1:],
120
- optimize=False,
121
- duration=100, # ms por frame
122
- loop=0 # bucle infinito
123
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  return filename
 
4
  from pydub import AudioSegment
5
  from pydub.generators import Sine
6
  from io import BytesIO
7
+ import textwrap
8
 
9
+ def generate_audio(state="intro", duration_ms=120000):
10
+ if state == "intro":
11
+ base_freq, binaural_freq, volume = 100, 6, -20 # Theta
12
+ else: # "outro"
13
+ base_freq, binaural_freq, volume = 150, 10, -24 # Alpha
14
+
15
+ left_sine = Sine(base_freq).to_audio_segment(duration=duration_ms, volume=volume).set_channels(1)
16
+ right_sine = Sine(base_freq + binaural_freq).to_audio_segment(duration=duration_ms, volume=volume).set_channels(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  binaural_beat = AudioSegment.from_mono_audiosegments(left_sine, right_sine)
18
+
19
+ filename = f"{state}_resonance.wav"
20
+ binaural_beat.export(filename, format="wav")
 
 
 
 
21
  return filename
22
 
23
+ def generate_bioresonant_sigil(text_input, size=512):
24
+ if not text_input: return Image.new('RGB', (size, size), 'black')
25
+
 
 
26
  hash_object = hashlib.sha256(text_input.encode('utf-8'))
27
+ seed = [int(c, 16) for c in hash_object.hexdigest()]
28
+
29
+ img = Image.new('RGB', (size, size), (10, 5, 15))
30
  draw = ImageDraw.Draw(img)
31
  center_x, center_y = size // 2, size // 2
32
+
33
+ for i in range(16):
 
 
 
 
 
34
  s_idx = (i * 4) % len(seed)
35
+ angle = (sum(seed[s_idx:s_idx+4]) / (15*4)) * 2 * np.pi
36
+ radius = (seed[(i+1)%len(seed)] / 15) * (size * 0.45)
37
+ color = (50 + seed[(i+2)%len(seed)]*12, 50 + seed[(i+3)%len(seed)]*8, 100 + seed[i]*10)
38
+
39
+ x1 = center_x + radius * np.cos(angle)
40
+ y1 = center_y + radius * np.sin(angle)
41
+ x2 = center_x - radius * np.cos(angle)
42
+ y2 = center_y - radius * np.sin(angle)
43
+ draw.line((x1, y1, x2, y2), fill=color, width=2)
 
 
 
44
 
45
+ # Efecto de brillo
46
+ glow = img.filter(ImageFilter.GaussianBlur(radius=size*0.05))
47
+ return Image.alpha_composite(img.convert('RGBA'), glow.convert('RGBA')).convert('RGB')
48
 
 
49
  def create_quantum_tunnel_gif(filename="quantum_tunnel.gif", size=300, num_frames=20):
50
+ # (Esta funci贸n se mantiene igual que la v3.0)
 
 
51
  frames = []
52
  for i in range(num_frames):
53
+ img = Image.new('RGB', (size, size), (13, 13, 13)); draw = ImageDraw.Draw(img)
 
 
54
  center_x, center_y = size // 2, size // 2
 
 
 
55
  np.random.seed(i)
56
+ for _ in range(100):
57
+ angle = np.random.uniform(0, 2*np.pi); radius = np.random.uniform(0, size/2)
58
+ new_radius = (radius + (i/num_frames)*20) % (size/2)
59
+ x = center_x + new_radius*np.cos(angle); y = center_y + new_radius*np.sin(angle)
60
+ color = (np.random.randint(150,220), np.random.randint(100,200), np.random.randint(200,255))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  draw.point((x, y), fill=color)
 
62
  frames.append(img)
63
+ frames[0].save(filename, save_all=True, append_images=frames[1:], optimize=False, duration=100, loop=0)
64
+ return filename
65
 
66
+ def create_soul_artifact(sigil_img, title, key, filename="Soul_Artifact.png"):
67
+ width, height = sigil_img.size
68
+ bg_color = (10, 5, 15)
69
+ text_color = (230, 220, 255)
70
+
71
+ # Crear un lienzo m谩s grande para a帽adir texto
72
+ artifact = Image.new('RGB', (width, height + 200), bg_color)
73
+ artifact.paste(sigil_img, (0, 0))
74
+ draw = ImageDraw.Draw(artifact)
75
+
76
+ # Usar una fuente predeterminada (Pillow buscar谩 una)
77
+ try:
78
+ title_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 32)
79
+ except IOError:
80
+ title_font = ImageFont.load_default()
81
+ try:
82
+ key_font = ImageFont.truetype("DejaVuSans.ttf", 24)
83
+ except IOError:
84
+ key_font = ImageFont.load_default()
85
+
86
+ # Dibujar T铆tulo
87
+ wrapped_title = textwrap.fill(title, width=30)
88
+ draw.text((width/2, height + 50), wrapped_title, font=title_font, fill=text_color, anchor="ms", align="center")
89
+
90
+ # Dibujar Llave Resonante
91
+ wrapped_key = textwrap.fill(f'"{key}"', width=40)
92
+ draw.text((width/2, height + 130), wrapped_key, font=key_font, fill=text_color, anchor="ms", align="center")
93
+
94
+ artifact.save(filename)
95
  return filename