xCoDGAS

Untitled

Apr 21st, 2026
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1. 2. Three.js Visualizer (app.js)
  2. JavaScript
  3.  
  4. let scene, camera, renderer, orbLayers = [], currentState = 'idle';
  5. let targetScale = 1.0, currentScale = 1.0;
  6.  
  7. // Color and State Configurations
  8. const states = {
  9. idle: { // Pale and smaller
  10. layers: [
  11. { color: 0x2a2e5e, opacity: 0.1, scale: 0.7, rotationSpeed: { x: 0.0005, y: 0.001 } },
  12. { color: 0x2a2e5e, opacity: 0.1, scale: 0.6, rotationSpeed: { x: -0.001, y: 0.0015 } }
  13. ],
  14. timeSpeed: 0.008, pulsate: false, chromaticAberration: 0.2, description: 'Sleeping'
  15. },
  16. listening: {
  17. layers: [
  18. { color: 0x434FCF, opacity: 0.2, scale: 1.0, rotationSpeed: { x: 0.002, y: 0.004 } },
  19. { color: 0x434FCF, opacity: 0.4, scale: 0.7, rotationSpeed: { x: 0.004, y: -0.003 } }
  20. ],
  21. timeSpeed: 0.022, pulsate: true, pulsateMin: 0.02, pulsateMax: 0.2, chromaticAberration: 1.2, description: 'Listening'
  22. },
  23. google: { // Visual bridge: Electric Cyan for High Precision parsing
  24. layers: [
  25. { color: 0x00f2ff, opacity: 0.3, scale: 1.1, rotationSpeed: { x: 0.008, y: 0.008 } },
  26. { color: 0x00f2ff, opacity: 0.5, scale: 0.8, rotationSpeed: { x: -0.01, y: 0.01 } }
  27. ],
  28. timeSpeed: 0.05, pulsate: true, pulsateMin: 0.1, pulsateMax: 0.4, chromaticAberration: 2.5, description: 'High Precision'
  29. },
  30. thinking: {
  31. layers: [
  32. { color: 0x8747F7, opacity: 0.2, scale: 0.85, rotationSpeed: { x: 0.003, y: 0.003 } },
  33. { color: 0x8747F7, opacity: 0.4, scale: 0.60, rotationSpeed: { x: 0.005, y: -0.004 } }
  34. ],
  35. timeSpeed: 0.02, pulsate: true, pulsateMin: 0.0, pulsateMax: 0.15, chromaticAberration: 0.8, description: 'Thinking'
  36. },
  37. speaking: {
  38. layers: [
  39. { color: 0xFF1893, opacity: 0.2, scale: 1.0, rotationSpeed: { x: 0.004, y: 0.005 } },
  40. { color: 0xFF1893, opacity: 0.4, scale: 0.70, rotationSpeed: { x: 0.006, y: -0.005 } }
  41. ],
  42. timeSpeed: 0.027, pulsate: true, pulsateMin: 0.05, pulsateMax: 0.22, chromaticAberration: 1.5, description: 'Speaking'
  43. }
  44. };
  45.  
  46. const vertexShader = `
  47. varying vec3 vNormal;
  48. varying vec3 vPosition;
  49. uniform float time;
  50. uniform float audioLevel;
  51. void main() {
  52. vNormal = normalize(normalMatrix * normal);
  53. vec3 pos = position;
  54. float distortion = sin(pos.y * 3.0 + time) * 0.02 * (1.0 + audioLevel);
  55. pos = pos + normal * distortion;
  56. vPosition = pos;
  57. gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
  58. }
  59. `;
  60.  
  61. const fragmentShader = `
  62. varying vec3 vNormal;
  63. varying vec3 vPosition;
  64. uniform vec3 sphereColor;
  65. uniform float opacity;
  66. uniform float chromaticAberration;
  67. void main() {
  68. vec3 viewDirection = normalize(cameraPosition - vPosition);
  69. float fresnel = pow(1.0 - abs(dot(viewDirection, normalize(vNormal))), 2.0);
  70. vec3 color = sphereColor + (fresnel * chromaticAberration * 0.3);
  71. gl_FragColor = vec4(color, opacity + (fresnel * 0.4));
  72. }
  73. `;
  74.  
  75. function init() {
  76. scene = new THREE.Scene();
  77. camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
  78. camera.position.z = 5;
  79. const canvas = document.getElementById('canvas');
  80. renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
  81. renderer.setSize(window.innerWidth, window.innerHeight);
  82.  
  83. // Create 2 fixed layers to allow smooth transitions
  84. for (let i = 0; i < 2; i++) {
  85. const geometry = new THREE.SphereGeometry(1, 64, 64);
  86. const material = new THREE.ShaderMaterial({
  87. vertexShader, fragmentShader,
  88. uniforms: {
  89. time: { value: 0 }, audioLevel: { value: 0 },
  90. sphereColor: { value: new THREE.Color(0x000000) },
  91. opacity: { value: 0 }, chromaticAberration: { value: 0 }
  92. },
  93. transparent: true, depthWrite: false
  94. });
  95. const sphere = new THREE.Mesh(geometry, material);
  96. sphere.userData = { currentScale: 0.1, targetScale: 0.1, rot: { x: 0, y: 0 } };
  97. scene.add(sphere);
  98. orbLayers.push(sphere);
  99. }
  100.  
  101. window.addEventListener('resize', () => {
  102. camera.aspect = window.innerWidth / window.innerHeight;
  103. camera.updateProjectionMatrix();
  104. renderer.setSize(window.innerWidth, window.innerHeight);
  105. });
  106. animate();
  107. }
  108.  
  109. function setState(stateName) {
  110. if (!states[stateName]) return;
  111. currentState = stateName;
  112. const statusEl = document.getElementById('status');
  113. if (statusEl) {
  114. statusEl.textContent = states[stateName].description;
  115. }
  116. }
  117.  
  118. function animate() {
  119. requestAnimationFrame(animate);
  120. const state = states[currentState];
  121. const lerpSpeed = 0.05; // Controls the smoothness of the transition
  122.  
  123. orbLayers.forEach((layer, index) => {
  124. const config = state.layers[index] || { color: 0x000000, opacity: 0, scale: 0, rotationSpeed: { x: 0, y: 0 } };
  125. const uniforms = layer.material.uniforms;
  126.  
  127. // Smooth Color Interpolation
  128. uniforms.sphereColor.value.lerp(new THREE.Color(config.color), lerpSpeed);
  129.  
  130. // Smooth Opacity and Aberration Interpolation
  131. uniforms.opacity.value += (config.opacity - uniforms.opacity.value) * lerpSpeed;
  132. uniforms.chromaticAberration.value += (state.chromaticAberration - uniforms.chromaticAberration.value) * lerpSpeed;
  133.  
  134. // Smooth Scale Interpolation
  135. let pulse = state.pulsate ? (Math.sin(Date.now() * 0.005) * (state.pulsateMax - state.pulsateMin)) : 0;
  136. let tScale = config.scale + pulse;
  137. layer.scale.setScalar(layer.scale.x + (tScale - layer.scale.x) * lerpSpeed);
  138.  
  139. // Animation
  140. uniforms.time.value += state.timeSpeed;
  141. layer.rotation.x += config.rotationSpeed.x;
  142. layer.rotation.y += config.rotationSpeed.y;
  143. });
  144.  
  145. renderer.render(scene, camera);
  146. }
  147.  
  148. function connectToAssistant() {
  149. const socket = new WebSocket('ws://127.0.0.1:8765');
  150.  
  151. socket.onopen = () => {
  152. const statusEl = document.getElementById('status');
  153. if (statusEl) statusEl.textContent = 'Assistant Online';
  154. };
  155.  
  156. socket.onmessage = (event) => {
  157. try {
  158. const data = JSON.parse(event.data);
  159. if (data.state) setState(data.state);
  160. } catch (e) {}
  161. };
  162. socket.onclose = () => setTimeout(connectToAssistant, 2000);
  163. }
  164.  
  165. window.addEventListener('DOMContentLoaded', () => {
  166. init();
  167. connectToAssistant();
  168. });
  169.  
  170. 3. Visual UI Base (index.html)
  171. HTML
  172.  
  173. <!DOCTYPE html>
  174. <html lang="en">
  175. <head>
  176. <meta charset="UTF-8">
  177. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  178. <title>Voice Assistant UI - Smooth</title>
  179. <link rel="stylesheet" href="style.css">
  180. <style>
  181. body {
  182. cursor: none;
  183. background-color: #000;
  184. margin: 0;
  185. overflow: hidden;
  186. }
  187. #controls {
  188. pointer-events: none;
  189. border: none;
  190. background: none;
  191. }
  192. .state-buttons, #startBtn, .theme-toggle {
  193. display: none !important;
  194. }
  195. #status {
  196. bottom: 30px;
  197. opacity: 0.3;
  198. font-size: 12px;
  199. letter-spacing: 2px;
  200. text-transform: uppercase;
  201. color: white;
  202. position: fixed;
  203. width: 100%;
  204. text-align: center;
  205. }
  206. </style>
  207. </head>
  208. <body>
  209. <div id="container">
  210. <canvas id="canvas"></canvas>
  211. <div id="controls">
  212. <div id="status">Connecting...</div>
  213. </div>
  214. </div>
  215. <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
  216. <script src="app.js"></script>
  217. </body>
  218. </html>
Advertisement
Add Comment
Please, Sign In to add comment