import struct
import zlib

def create_png():
    width, height = 128, 128
    
    # Create image data (RGBA)
    pixels = bytearray()
    
    for y in range(height):
        pixels.append(0)  # Filter type for each scanline
        for x in range(width):
            # Calculate distance from center for circle effect
            cx, cy = width // 2, height // 2
            dx, dy = x - cx, y - cy
            dist = (dx*dx + dy*dy) ** 0.5
            
            # Background gradient
            r = int(26 + (10 * y / height))
            g = int(26 + (10 * y / height))
            b = int(46 + (20 * y / height))
            
            # Cyan glow for neutron core
            if dist < 35:
                r = max(0, int(212 * (1 - dist/35)))
                g = 212
                b = 255
            
            # Electrons
            if (abs(x - 114) < 4 and abs(y - 64) < 4 or
                abs(x - 14) < 4 and abs(y - 64) < 4 or
                abs(x - 89) < 4 and abs(y - 34) < 4 or
                abs(x - 39) < 4 and abs(y - 94) < 4):
                r, g, b = 0, 212, 255
            
            a = 255
            pixels.extend([r, g, b, a])
    
    # Compress image data
    compressed = zlib.compress(bytes(pixels))
    
    # PNG signature
    png_data = b'\x89PNG\r\n\x1a\n'
    
    # IHDR chunk
    ihdr_data = struct.pack('>IIBBBBB', width, height, 8, 6, 0, 0, 0)
    ihdr_crc = zlib.crc32(b'IHDR' + ihdr_data) & 0xffffffff
    png_data += struct.pack('>I', 13) + b'IHDR' + ihdr_data + struct.pack('>I', ihdr_crc)
    
    # IDAT chunk
    idat_crc = zlib.crc32(b'IDAT' + compressed) & 0xffffffff
    png_data += struct.pack('>I', len(compressed)) + b'IDAT' + compressed + struct.pack('>I', idat_crc)
    
    # IEND chunk
    iend_crc = zlib.crc32(b'IEND') & 0xffffffff
    png_data += struct.pack('>I', 0) + b'IEND' + struct.pack('>I', iend_crc)
    
    with open('logo.png', 'wb') as f:
        f.write(png_data)
    print('Logo PNG created successfully!')

create_png()
