Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def generate_star_field(width, height, num_stars=1000):
- img = Image.new('RGB', (width, height), 'black')
- draw = ImageDraw.Draw(img)
- for _ in range(num_stars):
- x = random.randint(0, width)
- y = random.randint(0, height)
- brightness = random.randint(180, 255)
- size = random.choice([1, 2])
- draw.ellipse((x, y, x + size, y + size), fill=(brightness,) * 3)
- return img
- def generate_fractal_noise(width, height, octaves=5, persistence=0.5):
- noise = np.zeros((height, width), dtype=np.float32)
- amp = 1
- total_amp = 0
- for _ in range(octaves):
- layer = np.random.rand(height, width)
- noise += layer * amp
- total_amp += amp
- amp *= persistence
- noise /= total_amp
- noise = (noise - noise.min()) / (noise.max() - noise.min())
- return noise
- def generate_nebula_blob(width, height, color, alpha=0.9, blur=8):
- noise = generate_fractal_noise(width, height, octaves=6, persistence=0.5)
- x, y = np.meshgrid(np.linspace(-1, 1, width), np.linspace(-1, 1, height))
- d = np.sqrt(x * x + y * y)
- radial_falloff = np.exp(-d**2 * 3)
- combined = noise * radial_falloff
- combined = (combined - combined.min()) / (combined.max() - combined.min())
- mask_array = (combined * 255).astype(np.uint8)
- mask = Image.fromarray(mask_array).filter(ImageFilter.GaussianBlur(radius=blur))
- blob = Image.new("RGBA", (width, height), color + (0,))
- blob.putalpha(mask.point(lambda p: int(p * alpha)))
- return blob
- def place_blob(base, blob, position, angle=0):
- rotated = blob.rotate(angle, expand=True)
- temp = Image.new("RGBA", base.size)
- px, py = position[0] - rotated.size[0] // 2, position[1] - rotated.size[1] // 2
- temp.paste(rotated, (px, py), rotated)
- return Image.alpha_composite(base, temp)
- def generate_nebula_image(width, height):
- base = generate_star_field(width, height).convert("RGBA")
- colors = [
- (255, 100, 100),
- (100, 200, 255),
- (180, 100, 255),
- (255, 255, 120),
- (100, 255, 180),
- ]
- for _ in range(10):
- scale = random.uniform(0.8, 1.4)
- blob_size = int(width * scale), int(height * scale)
- color = random.choice(colors)
- blob = generate_nebula_blob(*blob_size, color, alpha=0.95)
- pos = (random.randint(0, width), random.randint(0, height))
- angle = random.randint(0, 360)
- base = place_blob(base, blob, pos, angle)
- base = ImageEnhance.Contrast(base).enhance(1.3)
- base = ImageEnhance.Brightness(base).enhance(1.2)
- # 🟢 FIX: return a proper RGB image
- rgb_image = base.convert("RGB")
- return rgb_image
- async def create_system(self, system_id):
- system = self.bot.systems[system_id]
- # Get the editor object instead of a plain image
- c_width = 1920
- c_height = 1080
- img = generate_nebula_image(1920, 1080)
- print(type(img), img.mode)
- bg = await asyncio.to_thread(generate_nebula_image(c_width, c_height))
- editor = Editor(bg)
- # Example: Add a title
- font = Font.poppins(size=48, variant="bold")
- editor.text((c_width/2, 50), system.name, font=font, color="white", align = "center")
- # Example: Draw a glowing dot or overlay (custom UI)
- editor.ellipse((900, 600), width=20, height=20, color=Color("cyan"))
- # Save to buffer
- buffer = BytesIO()
- await asyncio.to_thread(editor.image.save, buffer, format="PNG")
- buffer.seek(0)
- return buffer
- Traceback error:
- Ignoring exception in command starfield:
- Traceback (most recent call last):
- File "/home/tranquility/Bots/Orion/lib/python3.9/site-packages/nextcord/application_command.py", line 1053, in _call_with_hooks
- await callback(*args)
- File "/home/tranquility/Bots/Orion/lib/python3.9/site-packages/nextcord/application_command.py", line 1135, in call_invoke_slash
- await self.invoke_slash(interaction, **kwargs)
- File "/home/tranquility/Bots/Orion/lib/python3.9/site-packages/nextcord/application_command.py", line 1226, in invoke_slash
- await self.callback(self._self_argument, interaction, **kwargs)
- File "/home/tranquility/Bots/Orion/cogs/misc.py", line 146, in starfield
- buffer = await create_system(self, 0)
- File "/home/tranquility/Bots/Orion/utils/solar_system.py", line 92, in create_system
- bg = await asyncio.to_thread(generate_nebula_image(c_width, c_height))
- File "/usr/lib/python3.9/asyncio/threads.py", line 25, in to_thread
- return await loop.run_in_executor(None, func_call)
- File "/usr/lib/python3.9/concurrent/futures/thread.py", line 58, in run
- result = self.fn(*self.args, **self.kwargs)
- TypeError: 'Image' object is not callable
- The above exception was the direct cause of the following exception:
- nextcord.errors.ApplicationInvokeError: Command raised an exception: TypeError: 'Image' object is not callable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement