File size: 10,697 Bytes
4eb7346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a921fc6
4eb7346
 
a921fc6
 
4eb7346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a921fc6
 
 
4eb7346
 
 
 
 
 
 
 
 
 
a921fc6
 
 
 
 
 
4eb7346
a921fc6
 
 
 
 
 
 
4eb7346
 
 
 
 
a921fc6
4eb7346
a921fc6
4eb7346
a921fc6
 
 
 
 
4eb7346
a921fc6
 
4eb7346
 
a921fc6
4eb7346
 
a921fc6
 
 
 
4eb7346
a921fc6
4eb7346
 
a921fc6
 
 
 
 
 
 
 
 
 
 
 
4eb7346
 
a921fc6
e233942
4eb7346
 
 
 
 
 
 
 
 
 
 
 
 
 
a921fc6
4eb7346
e233942
a921fc6
4eb7346
 
 
e233942
a921fc6
 
 
 
4eb7346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a921fc6
 
4eb7346
 
 
 
 
 
a921fc6
4eb7346
 
 
 
 
 
 
 
 
 
a921fc6
 
4eb7346
a921fc6
4eb7346
 
a921fc6
4eb7346
a921fc6
 
 
 
 
 
 
 
4eb7346
 
 
 
a921fc6
4eb7346
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import random

# Your predefined words list
SPECIAL_WORDS = [
    'movie', 'excited', 'waiting', 'long', 'time', 'production', 'real', 'coded', 'digital', 'favorite', 
    'asking', 'doing', 'basketball', 'soccer', 'football', 'baseball', 'soup', 'food', 'burgers', 'pizza', 
    'fruit', 'pineapple', 'milk', 'jello', 'candy', 'rice', 'greens', 'lettuce', 'oatmeal', 'cereal', 
    'dogs', 'cats', 'animals', 'goats', 'sheep', 'movies', 'money', 'bank', 'account', 'keeping', 
    'looking', 'moving', 'boxes', 'elephants', 'movement', 'coding', 'developing', 'going', 'cruise', 
    'ship', 'boat', 'bahamas', 'foods', 'healthy', 'eating', 'important', 'pennsylvania', 'atlanta', 
    'north carolina', 'new york', 'france', 'paris', 'work', 'jobs', 'computers', 'computer', 'grocery', 
    'glamorous', 'version', 'truck', 'pickup', 'play', 'types', 'games', 'applications', 'quantum', 
    'speeds', 'advancements', 'technological', 'glimpse', 'countless', 'technology', 'future', 'walking', 
    'hello', 'jordan', 'season', 'superstar', 'nba', 'championship', 'leading', 'points', 'assist', 
    'career', 'chicago', 'scared', 'tongue', 'energy', 'disguise', 'business', 'older', 'grown', 'call', 
    'bills', 'garden', 'house', 'fallen', 'blossoms', 'lawn', 'love', 'forever', 'most', 'fan', 'clout', 
    'space', 'team', 'today', 'woke', 'work', 'relax', 'quicker', 'thicker', 'richer', 'data', 'ballet', 
    'dancer', 'goat', 'post', 'lebron', 'james', 'eagles', 'rockets', 'times', 'tank', 'pencil', 'watch', 
    'rolex', 'rappers', 'rockstar', 'rocket', 'rocks', 'tooth', 'teeth', 'pancake', 'breakfast', 'lunch', 
    'dinner', 'zoom', 'calling', 'talking', 'rule', 'ruler', 'rick', 'morty', 'martin', 'smith', 'wild', 
    'track', 'field', 'touchdown', 'basket', 'hope', 'yours', 'thank', 'olympics', 'sports', 'help', 
    'legal', 'law', 'firm', 'crowd', 'winner', 'winter', 'smoking', 'green', 'purple', 'blue', 'pink', 
    'orange', 'black', 'white', 'yellow', 'gold', 'weather', 'sun', 'middle', 'summer', 'heat', 'spring'
]

# Global variables
original_word_designs = {}
selected_words = []

def generate_word_design(word, word_id, use_color=False):
    """Generate styled design for a 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",
        "'Open Sans Condensed', sans-serif",
        "'Poiret One', cursive",
        "'Indie Flower', cursive",
        "'Pacifico', cursive",
        "'Teko', sans-serif"
    ]
    font_sizes = ["18px", "19px", "20px"] if not use_color else ["20px", "22px", "24px"]
    font_tops = ["0px", "1px", "-1px"] if not use_color else ["-2px", "0px", "2px", "3px"]
    letter_spacings = ["-1px", "0px", "1px"] if not use_color else ["-2px", "0px", "2px", "3px"]
    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"
    ] if not use_color else [
        "0px 0px 5px",
        "2px 2px 4px",
        "0px 0px 8px",
        "3px 3px 6px",
        "1px 1px 10px"
    ]
    skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"] if not use_color else ["-35deg", "-25deg", "0deg", "25deg", "35deg", "40deg"]

    # Choose color
    color = '#000000' if not use_color else f'#{random.randint(0, 0xFFFFFF):06x}'
    
    # Generate unique animation name for movement
    animation_name = f"animate_{word_id}_{random.randint(0, 10000)}"

    letters = list(word)
    styled_letters = []
    
    for i, letter in enumerate(letters):
        # Generate COMPLETELY NEW random styles (not based on original)
        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.03cm", "-0.01cm", "0.00cm", "0.01cm", "0.03cm"]),
            'position': 'relative',
            'top': random.choice(font_tops),
            'color': color,
            'display': 'inline-block',
            'margin': '0 1px',
            'vertical-align': 'middle'
        }
        
        if use_color:
            style['animation'] = f'{animation_name} 0.8s ease-in-out infinite'
            style['animation-delay'] = f'{i * 0.15}s'
        
        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)

    # Create keyframes for movement animation
    keyframes = f"""
    <style>
    @keyframes {animation_name} {{
        0% {{ transform: scale(1) rotate(0deg) skew({random.choice(skew_angles)}); }}
        25% {{ transform: scale(1.3) rotate({random.choice(["-15deg", "15deg", "20deg"])}deg) skew({random.choice(skew_angles)}); }}
        50% {{ transform: scale(0.9) rotate({random.choice(["-10deg", "10deg", "25deg"])}deg) skew({random.choice(skew_angles)}); }}
        75% {{ transform: scale(1.2) rotate({random.choice(["-5deg", "5deg", "30deg"])}deg) skew({random.choice(skew_angles)}); }}
        100% {{ transform: scale(1.1) rotate(0deg) skew({random.choice(skew_angles)}); }}
    }}
    </style>
    """ if use_color else ""

    return f'''
    {keyframes}
    <span class="word-container" id="word-{word_id}" style="display: inline-block; 
                                       margin: 10px; 
                                       padding: 8px 12px; 
                                       border: 2px solid #333; 
                                       border-radius: 8px;
                                       background-color: rgba(255,255,255,0.8);">
        <span style="display: inline-flex; 
                     align-items: baseline; 
                     vertical-align: middle;">
            {" ".join(styled_letters)}
        </span>
    </span>'''

def generate_random_words():
    """Generate 5 random words with initial styling."""
    global original_word_designs, selected_words
    
    # Reset data
    original_word_designs = {}
    selected_words = random.sample(SPECIAL_WORDS, 5)
    
    styled_words = []
    for i, word in enumerate(selected_words):
        # Generate original design (black)
        original_design = generate_word_design(word, i, use_color=False)
        original_word_designs[i] = original_design
        styled_words.append(original_design)
    
    final_output = f"""
    <html>
    <head>
        <link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@100&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@300&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Caveat&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Nothing+You+Could+Do&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Reenie+Beanie&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Orbitron&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Raleway:500" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght@300&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Poiret+One&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Teko&display=swap" rel="stylesheet">
        <style>
        body {{
            background-color: #f5f5f5;
            color: #000;
            font-size: 18px;
            line-height: 1.6;
            font-family: "Josefin Sans", sans-serif;
            padding: 20px;
        }}
        .styled-letter {{
            transition: all 0.6s ease;
        }}
        </style>
    </head>
    <body>
        <div style='max-width: 800px; margin: auto; text-align: center;'>
            <h2 style="margin-bottom: 30px;">Random Styled Words</h2>
            <div id="words-container" style="display: flex; flex-wrap: wrap; justify-content: center; align-items: center;">
                {" ".join(styled_words)}
            </div>
        </div>
    </body>
    </html>
    """
    
    return final_output

def trigger_movement(input_html):
    """Function to trigger the movement by replacing each word with a completely NEW styled version."""
    global original_word_designs, selected_words
    
    if not original_word_designs or not selected_words:
        return input_html

    updated_html = input_html
    
    # Replace each word with its completely new animated version
    for i, word in enumerate(selected_words):
        if i in original_word_designs:
            # Generate COMPLETELY NEW design with color and animation
            new_movement_design = generate_word_design(word, i, use_color=True)
            # Replace the original design with the new one
            updated_html = updated_html.replace(original_word_designs[i], new_movement_design, 1)

    return updated_html

# Create Gradio interface using Blocks
with gr.Blocks() as demo:
    gr.Markdown("# Random Word Styler\nGenerate 5 random styled words that transform into completely new styles!")
    
    generate_button = gr.Button("Generate Random Words", variant="primary")
    output_html = gr.HTML()
    animate_button = gr.Button("Trigger Movement Animation", variant="secondary")
    
    generate_button.click(generate_random_words, outputs=output_html)
    animate_button.click(trigger_movement, inputs=output_html, outputs=output_html)

# Launch the app
demo.launch()