Update helpers.py
Browse files- 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 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
| 34 |
-
|
| 35 |
-
|
| 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 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
return Image.new('RGB', (size, size), 'black')
|
| 46 |
-
text_input = emotion + " " + location
|
| 47 |
hash_object = hashlib.sha256(text_input.encode('utf-8'))
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
img = Image.new('RGB', (size, size),
|
| 51 |
draw = ImageDraw.Draw(img)
|
| 52 |
center_x, center_y = size // 2, size // 2
|
| 53 |
-
|
| 54 |
-
|
| 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 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 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 |
-
|
| 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 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 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 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 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
|