Advertisement
Tranquility3

Untitled

Apr 8th, 2025
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.86 KB | None | 0 0
  1. def generate_star_field(width, height, num_stars=1000):
  2.     img = Image.new('RGB', (width, height), 'black')
  3.     draw = ImageDraw.Draw(img)
  4.     for _ in range(num_stars):
  5.         x = random.randint(0, width)
  6.         y = random.randint(0, height)
  7.         brightness = random.randint(180, 255)
  8.         size = random.choice([1, 2])
  9.         draw.ellipse((x, y, x + size, y + size), fill=(brightness,) * 3)
  10.     return img
  11.  
  12. def generate_fractal_noise(width, height, octaves=5, persistence=0.5):
  13.     noise = np.zeros((height, width), dtype=np.float32)
  14.     amp = 1
  15.     total_amp = 0
  16.     for _ in range(octaves):
  17.         layer = np.random.rand(height, width)
  18.         noise += layer * amp
  19.         total_amp += amp
  20.         amp *= persistence
  21.     noise /= total_amp
  22.     noise = (noise - noise.min()) / (noise.max() - noise.min())
  23.     return noise
  24.  
  25. def generate_nebula_blob(width, height, color, alpha=0.9, blur=8):
  26.     noise = generate_fractal_noise(width, height, octaves=6, persistence=0.5)
  27.     x, y = np.meshgrid(np.linspace(-1, 1, width), np.linspace(-1, 1, height))
  28.     d = np.sqrt(x * x + y * y)
  29.     radial_falloff = np.exp(-d**2 * 3)
  30.     combined = noise * radial_falloff
  31.     combined = (combined - combined.min()) / (combined.max() - combined.min())
  32.     mask_array = (combined * 255).astype(np.uint8)
  33.     mask = Image.fromarray(mask_array).filter(ImageFilter.GaussianBlur(radius=blur))
  34.     blob = Image.new("RGBA", (width, height), color + (0,))
  35.     blob.putalpha(mask.point(lambda p: int(p * alpha)))
  36.     return blob
  37.  
  38. def place_blob(base, blob, position, angle=0):
  39.     rotated = blob.rotate(angle, expand=True)
  40.     temp = Image.new("RGBA", base.size)
  41.     px, py = position[0] - rotated.size[0] // 2, position[1] - rotated.size[1] // 2
  42.     temp.paste(rotated, (px, py), rotated)
  43.     return Image.alpha_composite(base, temp)
  44.  
  45. def generate_nebula_image(width, height):
  46.     base = generate_star_field(width, height).convert("RGBA")
  47.     colors = [
  48.         (255, 100, 100),
  49.         (100, 200, 255),
  50.         (180, 100, 255),
  51.         (255, 255, 120),
  52.         (100, 255, 180),
  53.     ]
  54.     for _ in range(10):
  55.         scale = random.uniform(0.8, 1.4)
  56.         blob_size = int(width * scale), int(height * scale)
  57.         color = random.choice(colors)
  58.         blob = generate_nebula_blob(*blob_size, color, alpha=0.95)
  59.         pos = (random.randint(0, width), random.randint(0, height))
  60.         angle = random.randint(0, 360)
  61.         base = place_blob(base, blob, pos, angle)
  62.  
  63.     base = ImageEnhance.Contrast(base).enhance(1.3)
  64.     base = ImageEnhance.Brightness(base).enhance(1.2)
  65.     # 🟢 FIX: return a proper RGB image
  66.     rgb_image = base.convert("RGB")
  67.     return rgb_image
  68.  
  69.  
  70. async def create_system(self, system_id):
  71.     system = self.bot.systems[system_id]
  72.     # Get the editor object instead of a plain image
  73.     c_width = 1920
  74.     c_height = 1080
  75.     img = generate_nebula_image(1920, 1080)
  76.     print(type(img), img.mode)
  77.     bg = await asyncio.to_thread(generate_nebula_image(c_width, c_height))
  78.    
  79.     editor = Editor(bg)
  80.  
  81.     # Example: Add a title
  82.     font = Font.poppins(size=48, variant="bold")
  83.     editor.text((c_width/2, 50), system.name, font=font, color="white", align = "center")
  84.  
  85.     # Example: Draw a glowing dot or overlay (custom UI)
  86.     editor.ellipse((900, 600), width=20, height=20, color=Color("cyan"))
  87.    
  88.     # Save to buffer
  89.     buffer = BytesIO()
  90.     await asyncio.to_thread(editor.image.save, buffer, format="PNG")
  91.     buffer.seek(0)
  92.     return buffer
  93.  
  94.  
  95.  
  96.  
  97. Traceback error:
  98.     Ignoring exception in command starfield:
  99. Traceback (most recent call last):
  100.   File "/home/tranquility/Bots/Orion/lib/python3.9/site-packages/nextcord/application_command.py", line 1053, in _call_with_hooks
  101.     await callback(*args)
  102.   File "/home/tranquility/Bots/Orion/lib/python3.9/site-packages/nextcord/application_command.py", line 1135, in call_invoke_slash
  103.     await self.invoke_slash(interaction, **kwargs)
  104.   File "/home/tranquility/Bots/Orion/lib/python3.9/site-packages/nextcord/application_command.py", line 1226, in invoke_slash
  105.     await self.callback(self._self_argument, interaction, **kwargs)
  106.   File "/home/tranquility/Bots/Orion/cogs/misc.py", line 146, in starfield
  107.     buffer = await create_system(self, 0)
  108.   File "/home/tranquility/Bots/Orion/utils/solar_system.py", line 92, in create_system
  109.     bg = await asyncio.to_thread(generate_nebula_image(c_width, c_height))
  110.   File "/usr/lib/python3.9/asyncio/threads.py", line 25, in to_thread
  111.     return await loop.run_in_executor(None, func_call)
  112.   File "/usr/lib/python3.9/concurrent/futures/thread.py", line 58, in run
  113.     result = self.fn(*self.args, **self.kwargs)
  114. TypeError: 'Image' object is not callable
  115.  
  116. The above exception was the direct cause of the following exception:
  117.  
  118. nextcord.errors.ApplicationInvokeError: Command raised an exception: TypeError: 'Image' object is not callable
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement