simple2d-3d 0.2.5__tar.gz → 0.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple2d_3d
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: A lightweight, hardware-accelerated 2D-3D layout and engine.
5
5
  Author: ProdeeptoSundar Roy
6
6
  Project-URL: Homepage, https://github.com/rtumpa099-gif/Simple2D_3D
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simple2d_3d" # The name users will type: pip install my_engine
7
- version = "0.2.5"
7
+ version = "0.2.7"
8
8
  authors = [
9
9
  { name="ProdeeptoSundar Roy" }
10
10
  ]
@@ -454,32 +454,54 @@ class ParticleSystem:
454
454
  def update(self, dt):
455
455
  self.particles = [p for p in self.particles if p.update(dt)]
456
456
 
457
- def draw(self, renderer):
457
+ def draw(self, renderer):
458
458
  for p in self.particles:
459
459
  alpha = max(0, min(255, int(p.life * 255)))
460
460
 
461
- # --- 1. Only create the texture if it doesn't exist yet ---
461
+ # --- 1. Create a circular texture if it doesn't exist yet ---
462
462
  if p.size not in self.cached_textures:
463
463
  diameter = p.size * 2
464
+ radius = p.size
464
465
 
465
- # Using 0 for masks lets SDL2 automatically assign a standard, correct 32-bit RGBA layout
466
466
  surface = sdl2.SDL_CreateRGBSurface(0, diameter, diameter, 32, 0, 0, 0, 0)
467
-
468
- # Safety check: If SDL failed to allocate the surface memory, skip this frame
469
467
  if not surface:
470
468
  continue
471
469
 
472
- # Fill the surface template with pure white
473
- sdl2.SDL_FillRect(surface, None, sdl2.SDL_MapRGBA(surface.contents.format, 255, 255, 255, 255))
470
+ # We need to manually color pixels to make a smooth circle shape
471
+ # Lock the surface so we can write directly to raw pixel memory safely
472
+ sdl2.SDL_LockSurface(surface)
473
+
474
+ # Convert the raw pixels array pointer to a usable ctypes format
475
+ pixels_ptr = ctypes.cast(surface.contents.pixels, ctypes.POINTER(ctypes.c_uint32))
476
+ pitch = surface.contents.pitch // 4 # 4 bytes per pixel (32-bit)
477
+
478
+ # Get the pixel format mapping for pure white
479
+ white_pixel = sdl2.SDL_MapRGBA(surface.contents.format, 255, 255, 255, 255)
480
+ transparent_pixel = sdl2.SDL_MapRGBA(surface.contents.format, 0, 0, 0, 0)
474
481
 
475
- # Upload to GPU texture memory
482
+ # Loop through every single coordinate inside our square bounding box
483
+ for y in range(diameter):
484
+ for x in range(diameter):
485
+ # Calculate distance from the center of the square using Pythagorean theorem
486
+ dx = x - radius
487
+ dy = y - radius
488
+ if (dx * dx + dy * dy) <= (radius * radius):
489
+ # Inside the circle radius? Color it solid white!
490
+ pixels_ptr[y * pitch + x] = white_pixel
491
+ else:
492
+ # Outside the circle? Keep it transparent
493
+ pixels_ptr[y * pitch + x] = transparent_pixel
494
+
495
+ sdl2.SDL_UnlockSurface(surface)
496
+
497
+ # Upload our brand-new round circle template straight to GPU memory
476
498
  texture = sdl2.SDL_CreateTextureFromSurface(renderer, surface)
477
499
  sdl2.SDL_FreeSurface(surface)
478
500
 
479
501
  if texture:
480
502
  self.cached_textures[p.size] = texture
481
503
  else:
482
- continue # Skip if texture creation failed
504
+ continue
483
505
 
484
506
  # --- 2. Pull the texture and apply modifiers ---
485
507
  tex = self.cached_textures.get(p.size)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple2d_3d
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: A lightweight, hardware-accelerated 2D-3D layout and engine.
5
5
  Author: ProdeeptoSundar Roy
6
6
  Project-URL: Homepage, https://github.com/rtumpa099-gif/Simple2D_3D
File without changes
File without changes
File without changes