generate_frames.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright 2026 Aarav Ravindra Kharade
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. """
  18. Generate boot animation frames: ONLY the nucleus expanding.
  19. The orbiting electrons are handled by Swift after the kernel boots.
  20. Output: animation.bin (concatenated raw 32-bit BGRA frames, 200x200 each)
  21. """
  22. import math
  23. import os
  24. import struct
  25. import sys
  26. FRAME_COUNT = 60
  27. WIDTH = 200
  28. HEIGHT = 200
  29. CX = WIDTH / 2.0
  30. CY = HEIGHT / 2.0
  31. NUCLEUS_MAX_R = 28.0
  32. def main():
  33. if len(sys.argv) < 2:
  34. print("Usage: generate_frames.py <output-dir>")
  35. sys.exit(1)
  36. out_dir = sys.argv[1]
  37. os.makedirs(out_dir, exist_ok=True)
  38. out_path = os.path.join(out_dir, "animation.bin")
  39. all_frames = bytearray()
  40. for f in range(FRAME_COUNT):
  41. # Ease-out cubic expansion
  42. p = f / float(FRAME_COUNT - 1)
  43. p = 1.0 - (1.0 - p) ** 3
  44. radius = p * NUCLEUS_MAX_R
  45. frame = bytearray()
  46. for y in range(HEIGHT):
  47. for x in range(WIDTH):
  48. dx = x - CX
  49. dy = y - CY
  50. dist = math.sqrt(dx * dx + dy * dy)
  51. if dist < radius:
  52. val = 255
  53. elif dist < radius + 1.5:
  54. val = int(255 * (1.0 - (dist - radius) / 1.5))
  55. else:
  56. val = 0
  57. # 32-bit BGRA
  58. frame.extend(struct.pack('BBBB', val, val, val, 0xFF))
  59. all_frames.extend(frame)
  60. with open(out_path, 'wb') as fp:
  61. fp.write(all_frames)
  62. size_kb = len(all_frames) // 1024
  63. print(f" Generated {FRAME_COUNT} frames ({WIDTH}x{HEIGHT}x32bpp) "
  64. f"-> animation.bin ({size_kb} KB)")
  65. if __name__ == '__main__':
  66. main()