Your current "Next-Gen Code Generator" UI is already sleek and modern, utilizing Vanta.js for the dynamic background and GSAP for smooth animations. To make it even more creative and animated, here are several enhancements you can implement:
-
Enhanced Background Animation: Introduce more dynamic effects using Vanta.js or combine multiple effects for a richer background.
-
Animated Form Elements: Add subtle animations to form inputs and buttons to improve user interaction.
-
Interactive Loader: Create a more engaging loader animation to keep users entertained while the code is being generated.
-
Themed Transitions: Implement theme transitions or mode switches (e.g., light and dark modes) with smooth animations.
-
Micro-Interactions: Incorporate micro-interactions such as button ripples, input field highlights, and hover effects.
-
Typography Enhancements: Use animated gradients or text shadows to make the headings and labels more eye-catching.
Below is the enhanced version of your HTML, CSS, and JavaScript incorporating these improvements:
Enhanced HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Next-Gen Code Generator</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&family=Fira+Code&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vanta/0.5.21/vanta.net.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
<!-- Adding Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Existing CSS Variables */
:root {
--primary-color: #6C63FF;
--secondary-color: #4CAF50;
--background-color: #1A1A2E;
--text-color: #FFFFFF;
--card-bg-color: rgba(255, 255, 255, 0.1);
--input-focus-color: #4CAF50;
--button-hover-color: #3e8e41;
--gradient: linear-gradient(45deg, #6C63FF, #4CAF50);
}
/* Global Styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
transition: all 0.3s ease;
}
body {
font-family: 'Roboto', sans-serif;
background-color: var(--background-color);
color: var(--text-color);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
position: relative;
}
/* Vanta Background Overlay */
#vanta-background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
/* Container Styles */
.container {
width: 90%;
max-width: 800px;
padding: 2.5rem 2rem;
background: var(--card-bg-color);
border-radius: 15px;
backdrop-filter: blur(15px);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
border: 1px solid rgba(255, 255, 255, 0.18);
transform: translateY(50px);
opacity: 0;
animation: fadeInUp 1s forwards;
position: relative;
}
/* Enhanced Hover Effect */
.container:hover {
box-shadow: 0 16px 64px 0 rgba(31, 38, 135, 0.6);
transform: scale(1.02);
}
/* Animated Gradient Heading */
h1 {
text-align: center;
margin-bottom: 2.5rem;
font-size: 2.5rem;
background: var(--gradient);
background-size: 200% 200%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: gradientAnimation 5s linear infinite;
text-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
/* Form Styles */
form {
display: flex;
flex-direction: column;
gap: 2rem;
}
.input-group {
position: relative;
}
label {
position: absolute;
top: 50%;
left: 1rem;
transform: translateY(-50%);
background-color: var(--background-color);
padding: 0 0.5rem;
font-size: 1rem;
color: var(--primary-color);
transition: all 0.3s ease;
pointer-events: none;
z-index: 1;
}
input[type="text"], select {
width: 100%;
padding: 1.2rem 1rem;
background-color: var(--background-color);
border: 2px solid transparent;
border-radius: 10px;
color: var(--text-color);
font-size: 1rem;
outline: none;
position: relative;
z-index: 0;
}
input[type="text"]:focus, select:focus {
border-color: var(--secondary-color);
box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}
input[type="text"]:focus + label,
select:focus + label,
input[type="text"]:not(:placeholder-shown) + label,
select:not([value=""]) + label {
top: -0.5rem;
font-size: 0.85rem;
color: var(--secondary-color);
background-color: var(--background-color);
padding: 0 0.3rem;
}
/* Enhanced Submit Button */
input[type="submit"] {
padding: 1rem 2.5rem;
background-color: var(--primary-color);
color: var(--text-color);
border: none;
border-radius: 50px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
position: relative;
overflow: hidden;
transition: all 0.3s ease;
}
input[type="submit"]:hover {
background-color: var(--secondary-color);
box-shadow: 0 4px 20px rgba(76, 175, 80, 0.3);
}
/* Button Ripple Effect */
input[type="submit"]::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: -100%;
background: rgba(255, 255, 255, 0.2);
transition: all 0.6s;
transform: skewX(-45deg) translateX(0);
pointer-events: none;
}
input[type="submit"]:hover::after {
left: 100%;
transform: skewX(-45deg) translateX(-100%);
}
/* Loader Styles */
.loader {
display: none;
width: 60px;
height: 60px;
border: 6px solid var(--primary-color);
border-top: 6px solid var(--secondary-color);
border-radius: 50%;
margin: 2rem auto;
animation: spin 1s linear infinite;
}
/* Output Styles */
#output {
margin-top: 2.5rem;
padding: 1.8rem;
background-color: rgba(0, 0, 0, 0.6);
border-radius: 10px;
font-family: 'Fira Code', monospace;
font-size: 1rem;
line-height: 1.6;
white-space: pre-wrap;
overflow-x: auto;
opacity: 0;
transform: translateY(20px);
animation: fadeInUpOutput 0.8s forwards;
position: relative;
}
/* Output Header */
#output::before {
content: '<!-- Generated Code -->';
display: block;
font-family: 'Fira Code', monospace;
font-size: 0.9rem;
color: var(--secondary-color);
margin-bottom: 0.5rem;
opacity: 0;
transform: translateY(-10px);
animation: revealOutputHeader 0.5s forwards;
}
/* Keyframes for Animations */
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@keyframes fadeInUp {
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes gradientAnimation {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
@keyframes fadeInUpOutput {
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes revealOutputHeader {
to {
opacity: 1;
transform: translateY(0);
}
}
/* Responsive Adjustments */
@media (max-width: 600px) {
.container {
width: 95%;
padding: 2rem 1.5rem;
}
h1 {
font-size: 2rem;
}
input[type="text"], select, input[type="submit"] {
font-size: 0.9rem;
}
#output {
font-size: 0.85rem;
}
}
/* Micro-Interaction: Ripple Effect on Form Inputs */
.input-group::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
border-radius: 10px;
pointer-events: none;
background: radial-gradient(circle, rgba(0,0,0,0.1) 10%, transparent 10.01%);
background-repeat: no-repeat;
background-position: center;
transform: scale(10);
opacity: 0;
transition: all 0.3s ease;
}
.input-group:active::after {
transform: scale(0);
opacity: 1;
transition: transform 0.1s ease-out, opacity 0.3s ease-out;
background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 10%, transparent 10.01%);
}
</style>
</head>
<body>
<div id="vanta-background"></div>
<div class="container">
<h1>Next-Gen Code Generator</h1>
<form id="codeForm">
<div class="input-group">
<input type="text" id="codeType" name="codeType" required autocomplete="off" placeholder=" ">
<label for="codeType">Enter code type</label>
</div>
<div class="input-group">
<select id="language" name="language" required>
<option value="" disabled selected>Select language</option>
<option value="python">Python</option>
<option value="java">Java</option>
<option value="javascript">JavaScript</option>
<option value="c">C</option>
<option value="c++">C++</option>
<option value="html">HTML</option>
<option value="ruby">Ruby</option>
</select>
<label for="language">Programming language</label>
</div>
<input type="submit" value="Generate Code">
</form>
<div class="loader" id="loader"></div>
<div id="output"></div>
</div>
<script>
// Initialize Vanta Background with Enhanced Effects
VANTA.NET({
el: "#vanta-background",
mouseControls: true,
touchControls: true,
gyroControls: false,
minHeight: 200.00,
minWidth: 200.00,
scale: 1.00,
scaleMobile: 1.00,
color: 0x6C63FF,
backgroundColor: 0x1A1A2E,
points: 15,
maxDistance: 25.00,
spacing: 25.00,
showLines: true,
lineWidth: 2.0
});
// Animate Container Appearance
gsap.from('.container', {
opacity: 0,
y: 50,
duration: 1,
ease: 'power3.out',
delay: 0.5
});
// Animate Vanta Background Fade-In
gsap.from('#vanta-background', {
opacity: 0,
duration: 1.5,
ease: 'power2.out'
});
const form = document.getElementById('codeForm');
const loader = document.getElementById('loader');
const output = document.getElementById('output');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const codeType = document.getElementById('codeType').value;
const language = document.getElementById('language').value;
// Disable Form and Show Loader
gsap.to(form, { opacity: 0.5, pointerEvents: 'none', duration: 0.3 });
loader.style.display = 'block';
gsap.to(loader, { opacity: 1, duration: 0.3 });
output.style.display = 'none';
try {
const response = await fetch('/code_generation', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `codeType=${encodeURIComponent(codeType)}&language=${encodeURIComponent(language)}`
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
output.textContent = data.response;
// Animate Output Display
gsap.to(output, {
display: 'block',
opacity: 1,
y: 0,
duration: 0.5,
ease: 'power2.out',
onStart: () => {
// Reset Output Position
gsap.set(output, { y: 20 });
}
});
} catch (error) {
console.error('Error:', error);
output.textContent = 'Error generating code. Please try again.';
gsap.to(output, {
display: 'block',
opacity: 1,
y: 0,
duration: 0.5,
ease: 'power2.out',
onStart: () => {
gsap.set(output, { y: 20 });
}
});
} finally {
// Hide Loader and Re-enable Form
gsap.to(loader, { opacity: 0, duration: 0.3, onComplete: () => { loader.style.display = 'none'; } });
gsap.to(form, { opacity: 1, pointerEvents: 'auto', duration: 0.3 });
}
});
// Floating Label Micro-Interactions
const inputs = document.querySelectorAll('input[type="text"], select');
inputs.forEach(input => {
input.addEventListener('focus', () => {
input.previousElementSibling.style.color = 'var(--secondary-color)';
gsap.to(input.previousElementSibling, { scale: 1.1, duration: 0.3 });
});
input.addEventListener('blur', () => {
if (input.value === "") {
input.previousElementSibling.style.color = 'var(--primary-color)';
gsap.to(input.previousElementSibling, { scale: 1, duration: 0.3 });
}
});
});
// Optional: Add Theme Toggle (Light/Dark Mode)
// Uncomment the following code to add a theme toggle button
/*
// Add Theme Toggle Button
const themeToggle = document.createElement('button');
themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
themeToggle.style.position = 'absolute';
themeToggle.style.top = '20px';
themeToggle.style.right = '20px';
themeToggle.style.background = 'none';
themeToggle.style.border = 'none';
themeToggle.style.color = 'var(--text-color)';
themeToggle.style.fontSize = '1.5rem';
themeToggle.style.cursor = 'pointer';
themeToggle.style.transition = 'transform 0.3s';
document.body.appendChild(themeToggle);
themeToggle.addEventListener('mouseenter', () => {
gsap.to(themeToggle, { scale: 1.2, duration: 0.3 });
});
themeToggle.addEventListener('mouseleave', () => {
gsap.to(themeToggle, { scale: 1, duration: 0.3 });
});
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('light-mode');
if (document.body.classList.contains('light-mode')) {
themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
gsap.to(':root', {
'--primary-color': '#FFD700',
'--secondary-color': '#FF6347',
'--background-color': '#F0F0F0',
'--text-color': '#000000',
'--card-bg-color': 'rgba(255, 255, 255, 0.8)',
'--input-focus-color': '#FF6347',
'--button-hover-color': '#FF4500',
'--gradient': 'linear-gradient(45deg, #FFD700, #FF6347)'
});
} else {
themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
gsap.to(':root', {
'--primary-color': '#6C63FF',
'--secondary-color': '#4CAF50',
'--background-color': '#1A1A2E',
'--text-color': '#FFFFFF',
'--card-bg-color': 'rgba(255, 255, 255, 0.1)',
'--input-focus-color': '#4CAF50',
'--button-hover-color': '#3e8e41',
'--gradient': 'linear-gradient(45deg, #6C63FF, #4CAF50)'
});
}
});
*/
</script>
</body>
</html>
Detailed Enhancements
-
Dynamic Background Enhancements:
- Increased Points and Spacing: The Vanta.NET background now has more points (
points: 15) and increased spacing for a denser network effect.
- Line Width Adjustment: Increased
lineWidth to 2.0 for more prominent connections.
-
Enhanced Container Animation:
- Fade-In with Upward Motion: The container uses
@keyframes fadeInUp to appear smoothly from below.
- Scale on Hover: The container scales up slightly on hover (
transform: scale(1.02)) for a subtle 3D effect.
-
Animated Gradient Heading:
- Gradient Animation: The
<h1> text has an animated gradient that shifts over time, making the heading more vibrant and dynamic.
-
Improved Form Elements:
- Floating Labels: The labels smoothly transition above the input fields when focused or filled, with scale animations for added effect.
- Ripple Effect on Submit Button: The submit button now has a ripple effect on hover, providing a modern interactive experience.
- Enhanced Input Groups: Added micro-interactions such as a ripple effect when clicking on input fields.
-
Interactive Loader:
- Bigger and Thicker Loader: Increased the loader size and border thickness for better visibility.
- Smooth Fade-In/Fade-Out: The loader fades in and out smoothly using GSAP animations.
-
Output Section Enhancements:
- Animated Appearance: The output section now fades in and moves upwards into view.
- Header for Output: Added a pseudo-element
<-- Generated Code --> for a code-like comment appearance.
-
Additional Micro-Interactions:
- Input Ripple Effect: Added a subtle ripple effect when input fields are clicked.
- Label Scaling: Labels scale up slightly on focus to draw attention.
-
Optional Theme Toggle:
Additional Suggestions
-
Accessibility: Ensure that color contrasts meet accessibility standards. You might want to test your design using tools like WebAIM's Contrast Checker.
-
Performance Optimization: While animations enhance the user experience, excessive use can affect performance. Optimize animations and ensure they run smoothly across different devices.
-
Server-Side Handling: Ensure your server-side /code_generation endpoint is secure and can handle various types of inputs to prevent potential vulnerabilities.
-
Feedback Mechanism: Consider adding more feedback, such as success messages or error highlighting on form fields if the user input is invalid.
-
Loading State Enhancements: You could add more states to the loader, such as different animations or progress indicators to inform users about the status of their request.
By implementing these enhancements, your UI will become more interactive, visually appealing, and user-friendly. Feel free to customize the animations and styles further to match your specific vision and branding.