Certainly! Let's enhance your "Next-Gen Code Generator" with more creative styling and animated effects to make it even more engaging and visually appealing. Below are the improvements we'll implement:
-
Enhanced Background Animation:
- Introduce a dynamic gradient background that smoothly transitions between colors.
- Add subtle particle animations using Vanta.js for a more interactive feel.
-
Card Animations:
- Implement a 3D flip animation on hover for the container to give it depth.
- Add a ripple effect when interacting with form elements.
-
Button Enhancements:
- Introduce a gradient border and a pulsating effect on the submit button.
- Add a hover effect that slightly enlarges the button and changes its shadow.
-
Input Field Improvements:
- Add a subtle shake animation on validation errors.
- Implement floating labels with smooth transitions.
-
Loader Animation:
- Enhance the loader with a more intricate design and smoother animation.
-
Responsive Design:
- Ensure all enhancements are responsive and maintain their integrity across different devices.
Let's dive into the updated code with these enhancements:
<!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>
<style>
:root {
--primary-color: #6C63FF;
--secondary-color: #4CAF50;
--background-color: #1A1A2E;
--text-color: #FFFFFF;
--card-bg-color: rgba(255, 255, 255, 0.1);
--border-gradient: linear-gradient(45deg, #6C63FF, #4CAF50);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
background: linear-gradient(135deg, #1A1A2E, #0F0F1A);
color: var(--text-color);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
position: relative;
}
#vanta-background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.container {
width: 90%;
max-width: 800px;
padding: 2rem;
background-color: var(--card-bg-color);
border-radius: 20px;
backdrop-filter: blur(15px);
box-shadow: 0 16px 64px rgba(31, 38, 135, 0.6);
border: 2px solid transparent;
background-image: var(--border-gradient);
background-clip: border-box;
position: relative;
transform: translateY(50px) rotateX(0deg) rotateY(0deg);
opacity: 0;
transition: all 0.7s ease;
perspective: 1000px;
}
.container::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: linear-gradient(45deg, #6C63FF, #4CAF50, #FFA500, #FF5722);
z-index: -1;
filter: blur(10px);
opacity: 0.7;
border-radius: 22px;
animation: gradientMove 10s linear infinite;
}
@keyframes gradientMove {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.container:hover {
box-shadow: 0 24px 80px rgba(31, 38, 135, 0.8);
transform: translateY(50px) rotateX(5deg) rotateY(5deg);
}
h1 {
text-align: center;
margin-bottom: 2rem;
font-size: 2.5rem;
background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
animation: textGlow 3s ease-in-out infinite;
}
@keyframes textGlow {
0%, 100% {
text-shadow: 0 2px 10px rgba(108, 99, 255, 0.5);
}
50% {
text-shadow: 0 2px 20px rgba(76, 175, 80, 0.7);
}
}
form {
display: flex;
flex-direction: column;
gap: 1.5rem;
position: relative;
}
.input-group {
position: relative;
overflow: hidden;
}
label {
position: absolute;
top: 50%;
left: 1rem;
transform: translateY(-50%);
background-color: var(--background-color);
padding: 0 0.5rem;
font-size: 0.9rem;
color: var(--primary-color);
transition: all 0.3s ease;
pointer-events: none;
}
input[type="text"], select {
width: 100%;
padding: 1rem;
background-color: var(--background-color);
border: 2px solid transparent;
border-radius: 10px;
color: var(--text-color);
font-size: 1rem;
transition: all 0.3s ease;
position: relative;
z-index: 1;
}
input[type="text"]:focus, select:focus {
outline: none;
border-color: var(--secondary-color);
box-shadow: 0 0 15px 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 {
color: var(--secondary-color);
top: -0.8rem;
font-size: 0.8rem;
background-color: var(--background-color);
padding: 0 0.3rem;
}
input[type="submit"] {
padding: 1rem 2rem;
background: var(--primary-color);
color: var(--text-color);
border: none;
border-radius: 10px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 1px;
position: relative;
overflow: hidden;
z-index: 1;
}
input[type="submit"]::before {
content: '';
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: rgba(255, 255, 255, 0.15);
transform: rotate(45deg);
transition: all 0.5s ease;
opacity: 0;
}
input[type="submit"]:hover::before {
top: 0;
left: 0;
opacity: 1;
}
input[type="submit"]:hover {
background: var(--secondary-color);
transform: translateY(-3px) scale(1.05);
box-shadow: 0 8px 20px rgba(76, 175, 80, 0.4);
}
.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 {
margin-top: 2rem;
padding: 1.5rem;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 10px;
font-family: 'Fira Code', monospace;
font-size: 0.9rem;
line-height: 1.5;
white-space: pre-wrap;
overflow-x: auto;
opacity: 0;
transform: translateY(20px);
transition: all 0.5s ease;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@media (max-width: 600px) {
.container {
width: 95%;
padding: 1.5rem;
}
h1 {
font-size: 2rem;
}
input[type="text"], select, input[type="submit"] {
font-size: 0.9rem;
}
}
</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 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>
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: 12,
maxDistance: 25.00,
spacing: 20.00
});
gsap.to('.container', {
opacity: 1,
y: 0,
duration: 1,
ease: 'power3.out',
delay: 0.5
});
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;
gsap.to(form, { opacity: 0.5, pointerEvents: 'none', duration: 0.3 });
loader.style.display = 'block';
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)}`
});
const data = await response.json();
output.textContent = data.response;
gsap.to(output, {
display: 'block',
opacity: 1,
y: 0,
duration: 0.5,
ease: 'power2.out'
});
} 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'
});
} finally {
loader.style.display = 'none';
gsap.to(form, { opacity: 1, pointerEvents: 'auto', duration: 0.3 });
}
});
// Floating label animation and shake effect on error
const inputs = document.querySelectorAll('input[type="text"], select');
inputs.forEach(input => {
input.addEventListener('focus', () => {
input.previousElementSibling.style.color = '#4CAF50';
});
input.addEventListener('blur', () => {
if (input.value === "") {
input.previousElementSibling.style.color = '#6C63FF';
}
});
});
// Optional: Add shake animation on error
function shakeElement(element) {
gsap.fromTo(element, { x: -10 }, { x: 10, repeat: 5, yoyo: true, duration: 0.1 });
}
// Example: Trigger shake on output if there's an error
/*
if (errorCondition) {
shakeElement(output);
}
*/
</script>
</body>
</html>
Enhancements Breakdown
-
Background Animation:
- Dynamic Gradient Border: Added a
::before pseudo-element to the .container with a gradient that moves seamlessly using the gradientMove keyframes.
- Enhanced Vanta.js Settings: Increased the number of points and max distance for a more intricate network.
-
Container Animations:
- 3D Rotation on Hover: The container now slightly rotates on the X and Y axes when hovered, giving a subtle 3D effect.
- Glow Effect on Text: The
<h1> now has a pulsating glow animation (textGlow) to make it stand out.
-
Form and Input Enhancements:
- Floating Labels: Improved the floating label transition for better visibility and smoother animations.
- Ripple Effect on Submit Button: Added a
::before pseudo-element to create a ripple effect on hover.
- Shake Animation: Optionally, you can trigger a shake animation on form validation errors by using the
shakeElement function.
-
Loader Improvements:
- Increased Size and Thickness: Made the loader larger and more noticeable.
- Smooth Animation: Enhanced the spin animation for a smoother loading indicator.
-
Responsive Design:
- Ensured that all elements scale appropriately on smaller screens by adjusting padding and font sizes.
-
Additional Animations:
- Text Glow: The heading has an infinite glow animation that transitions between primary and secondary colors.
- Gradient Border Animation: The container’s border gradient smoothly transitions through multiple colors, adding a dynamic visual effect.
Optional Enhancements
Final Thoughts
These enhancements aim to create a more engaging and visually stimulating user experience. Feel free to adjust the animations, colors, and effects to better suit your brand and user preferences. Remember to test the webpage across different devices and browsers to ensure consistency and responsiveness.
If you have any specific animations or effects in mind that you'd like to incorporate, let me know, and I can provide further assistance!