File size: 5,289 Bytes
46404cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8cd9c7
46404cc
 
 
 
 
 
 
 
 
 
 
 
 
c8cd9c7
 
46404cc
 
 
6153859
46404cc
 
 
 
 
 
 
 
 
 
c8cd9c7
46404cc
 
 
 
 
 
 
 
 
 
 
 
 
c8cd9c7
46404cc
c0a5aff
46404cc
c0a5aff
c8cd9c7
46404cc
 
 
 
 
 
 
 
 
 
 
 
c8cd9c7
6fe8ec9
c8cd9c7
6153859
 
 
 
 
6fe8ec9
 
 
 
 
 
 
 
 
 
 
 
 
46404cc
c8cd9c7
6153859
 
 
 
c8cd9c7
c0a5aff
c8cd9c7
c0a5aff
 
 
 
c8cd9c7
 
 
c0a5aff
c8cd9c7
c0a5aff
c8cd9c7
 
 
 
 
c0a5aff
 
 
6153859
 
46404cc
 
 
 
 
 
6153859
46404cc
c0a5aff
46404cc
 
 
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
import gradio as gr
import random

def generate_initial_design(word):
    fonts = [
        "'VT323', monospace",
        "'Josefin Sans', sans-serif",
        "'Rajdhani', sans-serif",
        "'Anton', sans-serif",
        "'Caveat', cursive",
        "'Patrick Hand', cursive",
        "'Nothing You Could Do', cursive",
        "'Reenie Beanie', cursive",
        "'Orbitron', sans-serif",
        "'Raleway', sans-serif"
    ]
    font_sizes = ["18px", "19px", "20px"]
    font_tops = ["0px", "1px", "-1px"]
    letter_spacings = ["-1px", "0px", "1px"]
    text_shadows = [
        "0px 0px 1px",
        "0px 0px 2px",
        "1px 0px 0px",
        "0px 0px 0px",
        "0px 1px 0px",
        "0px 2px 0px",
        "0px 1px 1px",
        "1px 1px 0px",
        "1px 0px 1px"
    ]
    skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"]

    letters = list(word)
    styled_letters = []
    
    for i, letter in enumerate(letters):
        style = {
            'font-family': random.choice(fonts),
            'line-height': '1.6',
            'font-size': random.choice(font_sizes),
            'letter-spacing': random.choice(letter_spacings),
            'text-shadow': random.choice(text_shadows),
            'transform': f'skew({random.choice(skew_angles)})',
            'margin-top': random.choice(["-0.02cm", "0.00cm", "0.02cm"]),
            'position': 'relative',
            'top': random.choice(font_tops),
            'color': '#000000',
            'display': 'inline-block',
            'margin': '0 1px',
            'vertical-align': 'middle',
            'cursor': 'pointer'
        }
        
        style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
        styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
        styled_letters.append(styled_letter)

    return f'''
    <span style="display: inline-flex; 
                 align-items: baseline; 
                 vertical-align: middle; 
                 margin: 0 2px;">
        {" ".join(styled_letters)}
    </span>'''

def generate_output_html():
    paragraphs = [
        "Proctors's voice quavered, “Where are we, Benshiro? This can't be real. We went full speed into that...”",
        "“Proctor, I hear you! Is that you? I'm so thankful, but where are you? I can't see you.” Benshiro's words echoed in the void."
    ]

    result = []
    
    for paragraph in paragraphs:
        words = paragraph.split()
        special_word = random.choice(words)
        styled_word = generate_initial_design(special_word)
        styled_paragraph = ' '.join(word if word != special_word else styled_word for word in words)
        result.append(styled_paragraph)

    output_html = '<br><br>'.join(result)
    return output_html

def create_html_with_script(output_text):
    return f"""
    <html>
    <head>
        <link href="https://fonts.googleapis.com/css?family=VT323|Josefin+Sans|Rajdhani|Anton|Caveat|Patrick+Hand|Nothing+You+Could+Do|Reenie+Beanie|Orbitron|Raleway" rel="stylesheet">
        <style>
        body {{
            background-color: #fff;
            color: #000;
            font-size: 18px;
            line-height: 1.6;
            font-family: "Josefin Sans", sans-serif;
            padding: 20px;
        }}
        .styled-letter {{
            transition: transform 0.3s ease;
        }}
        @keyframes wiggle {{
            0% {{ transform: rotate(0deg); }}
            50% {{ transform: rotate(5deg); }}
            100% {{ transform: rotate(0deg); }}
        }}
        button {{
            background-color: #4CAF50;
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;
            border-radius: 8px;
        }}
        </style>
        <script>
        function triggerMovement() {{
            document.querySelectorAll('.styled-letter').forEach(el => {{
                el.style.animation = 'wiggle 0.5s infinite';
            }});
        }}

        function revealWords() {{
            const container = document.getElementById('text-content');
            const fullText = `{output_text}`;
            const words = fullText.split(' ');
            container.innerHTML = '';
            let i = 0;
            function displayWord() {{
                if (i < words.length) {{
                    container.innerHTML += words[i] + ' ';
                    i++;
                    setTimeout(displayWord, 150);
                }}
            }}
            displayWord();
        }}
        </script>
    </head>
    <body>
        <div style='max-width: 800px; margin: auto;' id="text-content"></div>
        <button onclick="revealWords()">Start Text</button>
        <button onclick="triggerMovement()">Start Movement</button>
    </body>
    </html>
    """

# Create Gradio interface using Blocks
with gr.Blocks() as demo:
    gr.Markdown("# Styled Text with Animation")
    output_html = gr.HTML()
    demo.load(fn=lambda: create_html_with_script(generate_output_html()), outputs=output_html)

# Launch the app
demo.launch()