PixelChipCode

Kaleidoscope Effect

Oct 5th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.61 KB | Source Code | 0 0
  1. // Kaleidoscope Effect Code 🌈✨
  2.  
  3. // Create Event
  4. // Create a surface with the dimensions of the room to draw the effect.
  5. surface = surface_create(room_width, room_height);
  6.  
  7.  
  8. // Step Event
  9. // Handle window resizing
  10. // If the room size changes, recreate the surface to match the new dimensions.
  11. if (surface_get_width(surface) != room_width || surface_get_height(surface) != room_height) {
  12.     if (surface_exists(surface)) surface_free(surface); // Free the existing surface to avoid memory leaks.
  13.     surface = surface_create(room_width, room_height); // Create a new surface with updated dimensions.
  14. }
  15.  
  16.  
  17. // Draw Event
  18. // Ensure the surface exists before drawing.
  19. if (!surface_exists(surface)) {
  20.     surface = surface_create(room_width, room_height);
  21. }
  22.  
  23. // Set the surface as the target for drawing.
  24. surface_set_target(surface);
  25.  
  26. // Draw a point at the mouse position to create a dynamic effect.
  27. draw_point(mouse_x, mouse_y);
  28.  
  29. // Reset the drawing target back to the application surface.
  30. surface_reset_target();
  31.  
  32. // Draw the kaleidoscope effect by mirroring parts of the surface.
  33. // First, draw the base surface.
  34. draw_surface(surface, 0, 0);
  35.  
  36. // Draw mirrored parts of the surface to create the kaleidoscope effect.
  37. draw_surface_part_ext(surface, 0, 0, room_width, room_height, room_width, 0, -1, 1, c_white, 1); // Mirror horizontally.
  38. draw_surface_part_ext(surface, 0, 0, room_width, room_height, room_width, room_height, -1, -1, c_white, 1); // Mirror both horizontally and vertically.
  39. draw_surface_part_ext(surface, 0, 0, room_width, room_height, 0, room_height, 1, -1, c_white, 1); // Mirror vertically.
Tags: gameMaker
Advertisement
Add Comment
Please, Sign In to add comment