PixelChipCode

Spiral Easing Visualizer

Oct 15th, 2024 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | Source Code | 0 0
  1. By oliver @pixelchipcode
  2.  
  3. Name: Spiral Easing Visualizer
  4.  
  5. Description: This code generates a mesmerizing spiral animation that transitions smoothly between predefined positions using easing functions. In the Step event, the position transitions are controlled by an easing function, moving between coordinates stored in an array. As the position updates, a dynamic spiral with pulsing and color-shifting effects is drawn in the Draw event. The spiral consists of thousands of points that move in a hypnotic motion, with two counter-rotating spirals adding depth and complexity. Users can change the easing function and advance to the next position by pressing the 'Q' key.
  6.  
  7.  
  8. = = = = =
  9.  
  10. function EaseLinear(time,start,dest,duration){
  11. return dest * time / duration + start;
  12. }
  13.  
  14. function EaseInOutQuad(time,start,dest,duration){
  15. time /= duration * 0.5;
  16. if (time < 1){
  17. return dest * 0.5 * time * time + start;
  18. }
  19. return dest * -0.5 * (--time * (time - 2) - 1) + start;
  20. }
  21.  
  22. //create event
  23. positions = [[0,0],[1,8],[34,220],[68,0],[90,5],[120,15],[47,62]];
  24. current_position = 0; next_position = 1; time = 0; duration = 60;
  25. use_easing_function = EaseLinear; xx = 0; yy = 0;
  26.  
  27. //step event
  28. var x_start = positions[current_position][0];
  29. var y_start = positions[current_position][1];
  30. var x_dest = positions[next_position][0] - x_start;
  31. var y_dest = positions[next_position][1] - y_start;
  32.  
  33. xx = time < duration ? use_easing_function(time++, x_start, x_dest, duration) : positions[next_position][0];
  34. yy = time < duration ? use_easing_function(time, y_start, y_dest, duration) : positions[next_position][1];
  35.  
  36. if (keyboard_check_pressed(ord("Q"))) {
  37. current_position = (current_position + 1) mod array_length(positions);
  38. next_position = (current_position + 1) mod array_length(positions);
  39. time = 0; use_easing_function = EaseInOutQuad;
  40. }
  41.  
  42. //draw event
  43. var point_count = 5000, spiral_speed = 0.01, base_radius = xx, time_offset = current_time * spiral_speed, pulse = 1 + sin(current_time * 0.01) * 0.01;
  44. gpu_set_blendmode(bm_add);
  45.  
  46. for (var i = 0; i < point_count; i++) {
  47. var radius = base_radius * pulse, angle = i * yy / 500 + time_offset, x_pos = room_width / 2 + lengthdir_x(radius + sin(i * 0.1) * 50, angle);
  48. var y_pos = room_height / 2 + lengthdir_y(radius + cos(i * 0.1) * 50, angle), hue_shift = (current_time * 0.02 + i * 0.1) % 360;
  49. draw_set_color(make_color_hsv(hue_shift, 200, 255));
  50. draw_set_alpha(0.5 + cos(i * 0.02 + current_time * 0.05) * 0.5 * (1 - i / point_count));
  51. draw_circle(x_pos, y_pos, .7, false);
  52. }
  53.  
  54. for (var i = 0; i < point_count; i++) {
  55. var radius = base_radius * 0.8 * pulse, angle = i * 100 - time_offset, x_pos = room_width / 2 + lengthdir_x(radius + cos(i * 0.1) * 40, angle);
  56. var y_pos = room_height / 2 + lengthdir_y(radius + sin(i * 0.1) * 40, angle), hue_shift = (current_time * 0.02 + i * 0.1 + 180) % 360;
  57. draw_set_color(make_color_hsv(hue_shift, 200, 255));
  58. draw_set_alpha(0.5 + sin(i * 0.02 + current_time * 0.05) * 0.5 * (1 - i / point_count));
  59. draw_circle(x_pos, y_pos, .6, false);
  60. }
  61.  
  62. gpu_set_blendmode(bm_normal); draw_set_alpha(1);
Tags: gml gameMaker
Advertisement
Add Comment
Please, Sign In to add comment