예제 #1
0
# fractal images

################################################################################
import fractal
pixels = fractal.mandelbrot(448, 256)
print(pixels)

import bmp
bmp.write_grayscale('mandel.bmp', pixels)

################################################################################
예제 #2
0
'''
@author: Steven
'''
import fractal
import math
import math.pi as pi

#iteration= 400,points = 1920, prec=.0000002,x=-1.711114+.5,y=-0.002468

sides = 360

for i in range(sides):
    name = str(i) + "mandel360.png"
    zoom = 2*10 ** -5
    cx = math.cos(2*pi * i/sides)*.25
    cy = math.sin(2*pi * i /sides)*.25
	fractal.mandelbrot(iteration = 400, points = 500, prec = zoom ,x=-.5+cx,y=cy,  picname= name)
예제 #3
0
파일: bmp.py 프로젝트: gan3i/Python_first
    """Determine the dimensions in pixels of a BMP image.

    Args:
        filename: The filename of a BMP file.

    Returns:
        A tuple containing two integers with the width
        and height in pixels.

    Raises:
        ValueError: If the file was not a BMP file.
        OSError: If there was a problem reading the file.
    """

    with open(filename, 'rb') as f:
        magic = f.read(2)
        if magic != b'BM':
            raise ValueError("{} is not a BMP file".format(filename))

        f.seek(18)
        width_bytes = f.read(4)
        height_bytes = f.read(4)

        return (_bytes_to_int32(width_bytes), _bytes_to_int32(height_bytes))


from fractal import mandelbrot
if __name__ == "__main__":
    pixels = mandelbrot(448, 256)
    write_grayscale("mandel.bmp", pixels)
        for c in range(256):
            bmp.write(bytes((c, c, c, 0)))  # Blue, Green, Red, Zero

        # Pixel data
        pixel_data_bookmark = bmp.tell()
        for row in reversed(pixels):  # BMP files are bottom to top
            row_data = bytes(row)
            bmp.write(row_data)
            padding = b'\x00' * (
                (4 - (len(row) % 4)) % 4)  # Pad row to multiple of four bytes
            bmp.write(padding)

        # End of file
        eof_bookmark = bmp.tell()

        # Fill in file size placeholder
        bmp.seek(size_bookmark)
        bmp.write(_int32_to_bytes(eof_bookmark))

        # Fill in pixel offset placeholder
        bmp.seek(pixel_offset_bookmark)
        bmp.write(_int32_to_bytes(pixel_data_bookmark))


def _int32_to_bytes(i):
    "Convert an integer to four bytes in little-endian format."
    return bytes((i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff, i >> 24 & 0xff))


write_grayscale('test1.bmp', mandelbrot(640, 430))