3D Solar System Simulation with Avatar for drawaria.online

Remake of Cosmic Galaxy this one Injects a 3D solar system simulation with your avatar

当前为 2025-02-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 3D Solar System Simulation with Avatar for drawaria.online
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Remake of Cosmic Galaxy this one Injects a 3D solar system simulation with your avatar
  6. // @author YouTubeDrawaria
  7. // @match https://drawaria.online/*
  8. // @grant none
  9. // @license MIT
  10. // @icon https://drawaria.online/avatar/cache/86e33830-86ea-11ec-8553-bff27824cf71.jpg
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Create a container for the canvas
  17. const container = document.createElement('div');
  18. container.id = 'canvas-container';
  19. container.style.width = '100%';
  20. container.style.height = '100%';
  21. container.style.position = 'fixed';
  22. container.style.top = '0';
  23. container.style.left = '0';
  24. container.style.zIndex = '9999'; // You may adjust z-index depending on Drawaria's layout
  25. document.body.appendChild(container);
  26.  
  27. // Create an info div
  28. const info = document.createElement('div');
  29. info.className = 'info';
  30. info.style.position = 'absolute';
  31. info.style.top = '10px';
  32. info.style.left = '10px';
  33. info.style.color = '#fff';
  34. info.style.fontFamily = 'sans-serif';
  35. info.style.zIndex = '10000';
  36. info.textContent = '3D Solar System Simulation';
  37. document.body.appendChild(info);
  38.  
  39. // Include Three.js library from CDN
  40. const script = document.createElement('script');
  41. script.src = 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js';
  42. script.onload = function() {
  43. // Create scene, camera, and renderer
  44. const scene = new THREE.Scene();
  45. const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 2000);
  46. camera.position.set(0, 100, 250);
  47.  
  48. const renderer = new THREE.WebGLRenderer({ antialias: true });
  49. renderer.setSize(window.innerWidth, window.innerHeight);
  50. renderer.setPixelRatio(window.devicePixelRatio);
  51. container.appendChild(renderer.domElement);
  52.  
  53. // Add ambient light and a point light to simulate the sun's light
  54. const ambientLight = new THREE.AmbientLight(0x222222);
  55. scene.add(ambientLight);
  56.  
  57. const sunLight = new THREE.PointLight(0xffffff, 2, 1500);
  58. scene.add(sunLight);
  59.  
  60. // Utility function to create a planet mesh
  61. function createPlanet(radius, segments, color, textureUrl) {
  62. const geometry = new THREE.SphereGeometry(radius, segments, segments);
  63. const materialOptions = { color: color };
  64. if (textureUrl) {
  65. const texture = new THREE.TextureLoader().load(textureUrl);
  66. materialOptions.map = texture;
  67. }
  68. const material = new THREE.MeshStandardMaterial(materialOptions);
  69. const mesh = new THREE.Mesh(geometry, material);
  70. return mesh;
  71. }
  72.  
  73. // Create the Sun
  74. const sunGeometry = new THREE.SphereGeometry(16, 32, 32);
  75. const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xFDB813 });
  76. const sun = new THREE.Mesh(sunGeometry, sunMaterial);
  77. scene.add(sun);
  78. sunLight.position.copy(sun.position);
  79.  
  80. // Array to hold each planet's pivot and orbital speed
  81. const planets = [];
  82.  
  83. // Define planet parameters: name, distance from sun, radius, color, and orbital speed
  84. const planetData = [
  85. { name: "Mercury", distance: 30, radius: 3, color: 0x888888, speed: 0.04 },
  86. { name: "Venus", distance: 45, radius: 4, color: 0xEEDC82, speed: 0.03 },
  87. { name: "Earth", distance: 60, radius: 4.2, color: 0x2A75B3, speed: 0.02 },
  88. { name: "Mars", distance: 75, radius: 3.5, color: 0xB22222, speed: 0.017 }
  89. ];
  90.  
  91. planetData.forEach(data => {
  92. // Create a pivot object at the sun's position to simulate orbital rotation
  93. const pivot = new THREE.Object3D();
  94. scene.add(pivot);
  95.  
  96. // Create the planet mesh and position it along the x-axis
  97. const planet = createPlanet(data.radius, 32, data.color);
  98. planet.position.x = data.distance;
  99. pivot.add(planet);
  100.  
  101. // Save the pivot and orbital speed for animation
  102. planets.push({ pivot: pivot, speed: data.speed });
  103.  
  104. // (Optional) Create a visual orbit path as a thin ring
  105. const orbitGeometry = new THREE.RingGeometry(data.distance - 0.2, data.distance + 0.2, 64);
  106. const orbitMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide, transparent: true, opacity: 0.3 });
  107. const orbit = new THREE.Mesh(orbitGeometry, orbitMaterial);
  108. orbit.rotation.x = Math.PI / 2;
  109. scene.add(orbit);
  110. });
  111.  
  112. // Create a starry background using a particle system
  113. function addStars() {
  114. const starGeometry = new THREE.BufferGeometry();
  115. const starCount = 10000;
  116. const starVertices = [];
  117. for (let i = 0; i < starCount; i++) {
  118. const x = THREE.MathUtils.randFloatSpread(2000);
  119. const y = THREE.MathUtils.randFloatSpread(2000);
  120. const z = THREE.MathUtils.randFloatSpread(2000);
  121. starVertices.push(x, y, z);
  122. }
  123. starGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starVertices, 3));
  124. const starMaterial = new THREE.PointsMaterial({ color: 0xffffff });
  125. const stars = new THREE.Points(starGeometry, starMaterial);
  126. scene.add(stars);
  127. }
  128. addStars();
  129.  
  130. // Handle responsiveness: resize renderer and update camera aspect ratio
  131. window.addEventListener("resize", () => {
  132. camera.aspect = window.innerWidth / window.innerHeight;
  133. camera.updateProjectionMatrix();
  134. renderer.setSize(window.innerWidth, window.innerHeight);
  135. });
  136.  
  137. // Avatar Properties
  138. const avatar = {
  139. position: { x: 0, y: 0, z: 0 },
  140. velocity: { x: 0, y: 0, z: 0 },
  141. maxSpeed: 15,
  142. acceleration: 0.25,
  143. friction: 0.985,
  144. angle: 0,
  145. element: createAvatarElement()
  146. };
  147.  
  148. function createAvatarElement() {
  149. const img = new Image();
  150. img.style.position = 'absolute';
  151. img.style.width = '60px';
  152. img.style.height = '60px';
  153. img.style.transformOrigin = 'center';
  154. img.style.zIndex = '10000'; // High z-index to ensure it's above other elements
  155. document.body.appendChild(img);
  156. return img;
  157. }
  158.  
  159. // Fetch the real avatar URL
  160. function fetchAvatarURL() {
  161. const avatarImageElement = document.querySelector('#selfavatarimage');
  162. if (avatarImageElement) {
  163. avatar.element.src = avatarImageElement.src;
  164. } else {
  165. console.error('Avatar image element not found.');
  166. }
  167. }
  168.  
  169. // Call the function to fetch the avatar URL
  170. fetchAvatarURL();
  171.  
  172. // Movement System
  173. const keys = {};
  174. window.addEventListener('keydown', e => keys[e.key] = true);
  175. window.addEventListener('keyup', e => keys[e.key] = false);
  176.  
  177. function handleMovement() {
  178. // Acceleration
  179. if (keys.ArrowRight) avatar.velocity.x += avatar.acceleration;
  180. if (keys.ArrowLeft) avatar.velocity.x -= avatar.acceleration;
  181. if (keys.ArrowDown) avatar.velocity.y += avatar.acceleration;
  182. if (keys.ArrowUp) avatar.velocity.y -= avatar.acceleration;
  183.  
  184. // Velocity limits
  185. avatar.velocity.x = Math.max(-avatar.maxSpeed, Math.min(avatar.velocity.x, avatar.maxSpeed));
  186. avatar.velocity.y = Math.max(-avatar.maxSpeed, Math.min(avatar.velocity.y, avatar.maxSpeed));
  187.  
  188. // Apply friction
  189. avatar.velocity.x *= avatar.friction;
  190. avatar.velocity.y *= avatar.friction;
  191.  
  192. // Update position
  193. avatar.position.x += avatar.velocity.x;
  194. avatar.position.y += avatar.velocity.y;
  195.  
  196. // Update avatar display
  197. avatar.element.style.left = `${avatar.position.x}px`;
  198. avatar.element.style.top = `${avatar.position.y}px`;
  199.  
  200. // Calculate rotation angle
  201. avatar.angle = Math.atan2(avatar.velocity.y, avatar.velocity.x);
  202. avatar.element.style.transform = `rotate(${avatar.angle}rad)`;
  203. }
  204.  
  205. // Animation loop to render the scene and update orbital movements
  206. function animate() {
  207. requestAnimationFrame(animate);
  208.  
  209. // Rotate each planet's pivot to simulate orbiting around the sun
  210. planets.forEach(item => {
  211. item.pivot.rotation.y += item.speed;
  212. });
  213.  
  214. // Optional: slowly rotate the sun
  215. sun.rotation.y += 0.002;
  216.  
  217. // Handle avatar movement
  218. handleMovement();
  219.  
  220. renderer.render(scene, camera);
  221. }
  222. animate();
  223. };
  224. document.head.appendChild(script);
  225. })();