The prompt that made it
as published# DIGITAL PETALS SHADER
YOU ARE GIVEN A TASK TO INTEGRATE AN EXISTING REACT COMPONENT IN THE CODEBASE
THE CODEBASE SHOULD SUPPORT:
- SHADCN PROJECT STRUCTURE
- TAILWIND CSS
- TYPESCRIPT
IF IT DOESN'T, PROVIDE INSTRUCTIONS ON HOW TO SETUP PROJECT VIA SHADCN CLI, INSTALL TAILWIND OR TYPESCRIPT.
DETERMINE THE DEFAULT PATH FOR COMPONENTS AND STYLES.
IF DEFAULT PATH FOR COMPONENTS IS NOT /COMPONENTS/UI, PROVIDE INSTRUCTIONS ON WHY IT'S IMPORTANT TO CREATE THIS FOLDER
COPY-PASTE THIS COMPONENT TO /COMPONENTS/UI FOLDER:
```tsx
digital-petals-shader.tsx
import React, { useEffect, useRef } from 'react';
import * as THREE from 'three';
const DigitalPetalsShader = () => {
const containerRef = useRef(null);
useEffect(() => {
const container = containerRef.current;
if (!container) return;
// 1) Renderer, Scene, Camera, Clock
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
const clock = new THREE.Clock();
// 2) GLSL Shaders
const vertexShader = `
void main() {
gl_Position = vec4(position, 1.0);
}
`;
const fragmentShader = `
precision highp float;
uniform vec2 iResolution;
uniform float iTime;
uniform vec2 iMouse;
float random(vec2 st) {
return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
}
void main() {
// normalize coords around center, scale by height
vec2 uv = (gl_FragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
vec2 mouse = (iMouse - 0.5 * iResolution.xy) / iResolution.y;
float t = iTime * 0.3;
float r = length(uv);
float a = atan(uv.y, uv.x);
float mouseDist = length(uv - mouse);
float bloom = smoothstep(0.4, 0.0, mouseDist);
float petals = 5.0 + sin(t) * 2.0;
float petalShape = sin(a * petals + r * 2.0);
petalShape = pow(abs(petalShape), 0.5);
float flow = sin(r * 10.0 - t * 2.0);
float pattern = mix(petalShape, flow, 0.5) + bloom * 0.5;
vec3 color1 = vec3(0.8, 0.1, 0.5);
vec3 color2 = vec3(0.2, 0.4, 0.9);
vec3 highlightColor = vec3(1.0);
vec3 finalColor = mix(
color1,
color2,
smoothstep(0.5, 0.8, r + random(vec2(t, t)) * 0.1)
) * pattern;
finalColor += highlightColor * pow(pattern, 10.0) * (1.0 + bloom);
gl_FragColor = vec4(finalColor, 1.0);
}
`;
// 3) Uniforms, Material, Mesh
const uniforms = {
iTime: { value: 0 },
iResolution: { value: new THREE.Vector2() },
iMouse: { value: new THREE.Vector2(
window.innerWidth / 2,
window.innerHeight / 2
) }
};
const material = new THREE.ShaderMaterial({ vertexShader, fragmentShader, uniforms });
const geometry = new THREE.PlaneGeometry(2, 2);
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
// 4) Resize handler
const onResize = () => {
const width = container.clientWidth;
const height = container.clientHeight;
renderer.setSize(width, height);
uniforms.iResolution.value.set(width, height);
};
window.addEventListener('resize', onResize);
onResize(); // initialize size
// 5) Mouse handler
const onMouseMove = (e) => {
// flip Y so origin is bottom-left for shader
uniforms.iMouse.value.set(
e.clientX,
container.clientHeight - e.clientY
);
};
window.addEventListener('mousemove', onMouseMove);
// 6) Animation loop
renderer.setAnimationLoop(() => {
uniforms.iTime.value = clock.getElapsedTime();
renderer.render(scene, camera);
});
// 7) Cleanup
return () => {
window.removeEventListener('resize', onResize);
window.removeEventListener('mousemove', onMouseMove);
renderer.setAnimationLoop(null);
const canvas = renderer.domElement;
if (canvas && canvas.parentNode) {
canvas.parentNode.removeChild(canvas);
}
material.dispose();
geometry.dispose();
renderer.dispose();
};
}, []);
return (
<div
ref={containerRef}
className="shader-container"
style={{
position: 'fixed',
top: 0,
left: 0,
width: '100vw',
height: '100vh',
zIndex: -1,
pointerEvents: 'none'
}}
aria-label="Digital Petals animated background"
/>
);
};
export default DigitalPetalsShader;
demo.tsx
import DigitalPetalsShader from "@/components/ui/digital-petals-shader";
export default function DemoOne() {
return <div className="app-container">
<DigitalPetalsShader />
<div className="overlay-content">
<h1 className="title">Digital Petals</h1>
<p className="description">An Interactive WebGL Shader</p>
</div>
</div>
}
```
INSTALL NPM DEPENDENCIES:
```bash
three
```
## IMPLEMENTATION GUIDELINES
1. ANALYZE THE COMPONENT STRUCTURE AND IDENTIFY ALL REQUIRED DEPENDENCIES
2. REVIEW THE COMPONENT'S ARGUMENS AND STATE
3. IDENTIFY ANY REQUIRED CONTEXT PROVIDERS OR HOOKS AND INSTALL THEM
4. QUESTIONS TO ASK
- WHAT DATA/PROPS WILL BE PASSED TO THIS COMPONENT?
- ARE THERE ANY SPECIFIC STATE MANAGEMENT REQUIREMENTS?
- ARE THERE ANY REQUIRED ASSETS (IMAGES, ICONS, ETC.)?
- WHAT IS THE EXPECTED RESPONSIVE BEHAVIOR?
- WHAT IS THE BEST PLACE TO USE THIS COMPONENT IN THE APP?
## STEPS TO INTEGRATE
0. COPY PASTE ALL THE CODE ABOVE IN THE CORRECT DIRECTORIES
1. INSTALL EXTERNAL DEPENDENCIES
2. FILL IMAGE ASSETS WITH UNSPLASH STOCK IMAGES YOU KNOW EXIST
3. USE LUCIDE-REACT ICONS FOR SVGS OR LOGOS IF COMPONENT REQUIRES THEMAdds a render step. Works best with the HyperFrames or Remotion skills installed. Free, no sign-up.
Prompt by @pulkitxm. Prompts belong to their creators.