PixelChipCode

Orbit Trails in GameMaker

Oct 23rd, 2024 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.29 KB | Source Code | 0 0
  1. /*
  2.     Orbit Trails :: By oliver @pixelchipcode
  3.  
  4.     This script creates a mesmerizing visual of orbits, each with a sphere moving along its path
  5.     and leaving behind a fading trail. The orbits have varying radii and speeds, creating a dynamic
  6.     effect as they circle around the center of the room.
  7.  
  8.     Key Features:
  9.     - **Varying Orbit Sizes**: The radius of each orbit increases incrementally, creating a spread-out effect.
  10.     - **Varying Speeds**: Each orbit moves at a different speed, adding a variety of motion to the visual.
  11.     - **Fading Trail**: Each sphere leaves a fading trail behind it as it moves, simulating the effect of motion over time.
  12.     - **Distance Check**: Prevents visual glitches by skipping overly long lines between trail points.
  13.    
  14.     The result is a beautiful pattern of rotating spheres with smooth, fading trails, perfect for creating
  15.     a hypnotic and engaging animation.
  16.  
  17.     Created in GML for GameMaker Studio, this minimal implementation leverages arrays and simple trigonometric
  18.     functions to achieve a striking visual effect with just a few lines of code.
  19. */
  20.  
  21.  
  22. // Create Event
  23. orbits = [];
  24. repeat(200) {
  25.     array_push(orbits, {
  26.         radius: 50 + array_length(orbits) * 3,
  27.         speed: random_range(0.001, 0.006),
  28.         angle: random(360),
  29.         trail: []
  30.     });
  31. }
  32.  
  33. // Step Event
  34. var i = 0;
  35. repeat(array_length(orbits)) {
  36.     var orbit = orbits[i];
  37.     orbit.angle += orbit.speed;
  38.     if (orbit.angle >= 360) orbit.angle -= 360;
  39.    
  40.     array_insert(orbit.trail, 0, [
  41.         room_width/2 + orbit.radius * cos(orbit.angle),
  42.         room_height/2 + orbit.radius * sin(orbit.angle)
  43.     ]);
  44.     if (array_length(orbit.trail) > 200) array_pop(orbit.trail);
  45.     i++;
  46. }
  47.  
  48. // Draw Event
  49. var i = 0;
  50. repeat(array_length(orbits)) {
  51.     var orbit = orbits[i];
  52.     var j = 0;
  53.     repeat(array_length(orbit.trail) - 1) {
  54.         var pos1 = orbit.trail[j];
  55.         var pos2 = orbit.trail[j + 1];
  56.         if (point_distance(pos1[0], pos1[1], pos2[0], pos2[1]) <= 5) {
  57.             draw_set_alpha(1 - j/array_length(orbit.trail));
  58.             draw_line(pos1[0], pos1[1], pos2[0], pos2[1]);
  59.         }
  60.         j++;
  61.     }
  62.     draw_set_alpha(1);
  63.     draw_circle(orbit.trail[0][0], orbit.trail[0][1], 3, false);
  64.     i++;
  65. }
  66. draw_set_alpha(1);
  67.  
Tags: gml gameMaker
Advertisement
Add Comment
Please, Sign In to add comment