# -*- coding:utf-8 -*-
__projet__ = "mandelbrot"
__nom_fichier__ = "lecture_fichier_fractale"
__author__ = "Christine Fay-Varnier"
__date__ = "avril 2020"

from lire_ligne import lire_ligne
from complexe import Complexe

def lire_fichier_fractales(nom_fichier):
    """

    :param nom_fichier:     nom du fichier qui contient les données
    :return:                xmin, xmax, ymin, ymax, nx, ny, niter
                            listes des valeurs des suites à tester
    """
    fsource = open(nom_fichier, "r")

    # lecture des paramètres pour afficher la fractale : xmin, xmax, ymin, ymax, nx, ny, niter
    ligne = lire_ligne(fsource)
    xmin, xmax = ligne.split()
    xmin = int(xmin)
    xmax = int(xmax)

    ligne = lire_ligne(fsource)
    ymin, ymax = ligne.split()
    ymin = int(ymin)
    ymax = int(ymax)

    ligne = lire_ligne(fsource)
    nx, ny = ligne.split()
    nx = int(nx)
    ny = int(ny)

    niter = lire_ligne(fsource)
    niter = int(niter)

    n = lire_ligne(fsource)
    n = int(n)

    # lecture des différentes suites utilisées pour les tests
    # chaque donnée est fournie sur deux lignes
    # p
    # aib
    lcpx = []
    for i in range(n):
        p = lire_ligne(fsource)
        p = int(p)

        cpx = lire_ligne(fsource)
        reel, imag = cpx.split("i")
        lcpx.append((p, Complexe(float(reel), float(imag))))

    return xmin, xmax, ymin, ymax, nx, ny, niter, lcpx

if __name__ == '__main__':
    xmin, xmax, ymin, ymax, nx, ny, niter, lcpx = lire_fichier_fractales("source_fractales.txt")
    print(xmin, xmax, ymin, ymax, nx, ny, niter)
    for p, cpx in lcpx:
        print(p, cpx)