/*
biomorph
f(zn+1) = sin(zn) + exp(zn) + c 
f(zn+1) = zn3 + c 
f(zn+1) = zn5 + c 
f(zn+1) = sin(zn) + zn2 + c 
f(zn+1) = zn**zn + zn5 + c 
f(zn+1) = zn**zn + zn6 + c 

zn+1 = zn-2 + c 
zn+1 = c zn-2 + c 
zn+1 = c2 zn-2 + c 
zn+1 = c-1 zn-2 + c 
*/

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.event.*;
import java.awt.*; 
import javax.swing.JButton;  
import java.util.Timer;
import java.util.TimerTask;
import java.awt.Dimension;

public class Panneau extends JPanel implements MouseListener
{ 
	static int longueur;
	static int haut; 
  static double minX = -2.4;
	static double maxX = 2.4;
	static double minY = -1.5;
	static double maxY =  1.5;
	static int nbdebut=2000;
	static int nb=nbdebut;
	static boolean flag=false; 
	static boolean listen=false;
	static boolean dyna=false; 
	static boolean traveling=false;
	static boolean montre =true;
	static boolean conjug=false; 
	static int nbi;
	static boolean mandelbrot=true; 
	static boolean cycle=false;
	static boolean cycled=false; 
	static boolean attracteur=false; 
	static Font font = new Font("Serif", Font.PLAIN, 20);
	
	static double fibonacci[]={0.1436,0.0,1,   -0.5,0.0,2,  -0.8866,-0.027,2,   0.1376,-0.4,4,   -1.1441,0.0,4,
		-0.135,-0.4,3,   -0.127,-0.705,3,   -0.423,-0.44,5,   0.255,-0.298,5,      0.3012,-0.23,6,   -1.08,-0.145,6,   -0.1169,-0.81,6,
		-0.559,-0.375,7,   0.07,-0.54,7,   -0.335,-0.5575,8,   -1.0,-0.1632,8,   -0.629,-0.32,9,   0.28,-0.3955,9,   -0.071,-0.766,9,   -0.071,-0.766,9,
		-0.9345,-0.2,10};
		
	static double cx[]={0.0, 0.0,   -0.743643887037151, 0.13182590420533,     -1.7549, 0,	-1.310, 0,   0.3, 0.5,   -0.1226, 0.7449,
	   -0.1565, 0,   0.001643721971153, 0.822467633298876,
	   -0.096, 0.735,   -0.414, -0.612,   0.382, 0.147,   0.284, -0.0122,    -0.0958, 0.735,     -0.181, -0.667,
	   -0.652,0.272, 0.72,0.11, 0.28,-0.02,
	   -1,0,   0,1, -1.7548,0,   -0.122, 0.744,   0.28, 0.53,    -0.15, 1.03,    0.25, 0,   -0.75, 0,   -0.101, 0.956, 
	   -0.63, 0.67,   0.35, 0.05,   -0.76, 0.12,
	    1.0,1.0, 0.5,0, 0.75669,0.75669,    -0.481762,-0.531657,  -0.39054,-0.58679    };
	    
static double period[]={
0.0,0.0,1,1,
-1.0,0.0,2,1,
-1.757,0.0,3,1,
-1.314,0.0,4,1,
-0.5060,-0.5675,5,1,
-0.6297,-0.4275,7,1,
-0.6758,-0.3407,9,1,
-0.6990,-0.2807,11,1,
-0.1321,-0.7449,3,1,
0.2738,-0.5422,4,1,
0.373878,-0.3345,5,1,
0.3860,-0.2160,6,1,
0.3754,-0.1456,7,1,
0.3589,-0.1020,8,1,
-1.3837,0.0,8,1,


-1.1348,-0.2439,6,2,
-1.0044,-0.2714,8,2,
-0.9166,-0.2514,10,2,
0.3745,-0.267,11,2,
-0.2129,-0.8114,9,2,
-0.2287,-0.7554,12,2,
-0.2214,-0.7194,15,2,
0.1150,-0.6107,7,2,
0.3301,-0.4157,9,2,
-0.1069,-0.8664,6,2,
-0.02934,-0.7949,9,2,
-0.02510,-0.7439,12,2,
0.32569,-0.5654,8,2,
-0.032,-0.714,15,2,
-0.3637,-0.6257,8,2,
-0.5698,-0.4782,12,2, 
-0.6449,-0.3727,16,2,

-1.40,0.0,16,3,
-0.06195,-0.8190,15,3,
-0.1766,-0.8314,15,3,
-0.2170,-0.7757,21,3,
0.04969,-0.6335,10,3,
0.172112,-0.5735,11,3,
-0.8654,-0.2429,12,3,
-0.5344,-0.6032,10,3,
-1.21335,-0.15718,10,3,
-1.34487,-0.0571,12,3,
-0.1111,-0.8881,12,3,
0.2746,-0.5823,12,3,
0.32614,-0.51585,12,3,
0.13134,-0.6305,14,3,
-0.0912,-0.8714,18,3,
-0.13357,-0.8770,18,3,
-0.4867,-0.6035,15,3,
-1.1520,-0.2710,12,3,
-1.41755,-4.199,12,3,
-1.4771,0.0,12,3,
-1.627,0.0,5,3,
-1,3123,-0.0636,16,3,
-1,3123,-0.0636,16,3,

};
	static int indexpt=0; 
	static double thecx=0;
	static double thecy=0;
	static double pastravel=0.0001;
	static boolean showperiode=false; 
	static JButton bstopdyna = new JButton("<html>Arret<br>Zoom</html>");
	static int numfon=0;
	static double modulemin;
	static int indexmin;

	private int color;
	private int oldcolor;
	static double RZ;
	static double IZ; 
	static double RC=0.0;
	static double IC=0.0; 
	static double R;
	static double I;
	static double resux;
	static double resuy;
	static double elemx; 
	static double elemy;
	static double cyclex;
	static double cycley;
	
	static String tabfon[]={"Zn+1=Zn*Zn+C","Zn+1=Zn**3+C","Zn+1=Zn**4+C","Zn+1=Zn**5+C","Zn+1=C * sin(Zn)","Zn+1=C i * cos(Zn)","Zn+1=sin(Zn)+C","Zn+1=cos(Zn)+C",
		"Zn+1=C exp(Zn)","Zn+1=sin(Zn) + exp(Zn) + C",
	"Zn+1=sin(Zn)+exp(C) + Zn","Zn+1=ch(Zn)+C","Zn+1=sh(Zn)+C","Zn+1=C * Zn *(1-Zn)","Zn+1=Zn**1.5+C","Zn+1=Zn**Z+C",};
	static String typescol[]={"vitesse de convergence","abs(x)","angle","imaginaire >0","x mod 2","équipotentiel","module min","Fibonacci"};
 	static Timer t=new Timer();
 	static int nbcycle=10;
 	static int ncycle=0;
 	static int i;
 	static double tabcyclex[]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
 	static double tabcycley[]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
 	static int coloration=0;
 	Dimension dime = Toolkit.getDefaultToolkit().getScreenSize();
  int theight = (int)dime.getHeight();
	int twidth  = (int)dime.getWidth();
 	BufferedImage buffimag = new BufferedImage(twidth, theight, BufferedImage.TYPE_INT_RGB);
 	
//public void init() { 
//	 addMouseListener(this);
//	 System.out.println("init mouselistener");
//} 
	
public void mousePressed(MouseEvent e) { 
int buttonDown = e.getButton();
if (buttonDown == MouseEvent.BUTTON3) 
	{// Bouton droit enfoncé
	dyna=false;
	traveling=false;
	double vx=e.getX();
	double vy=e.getY();
	double vRC=minX + (maxX - minX)/(double)longueur * (double)vx;
	double vIC=minY + (maxY - minY)/(double)haut * (double)vy;
	//System.out.println("milieu "+vRC+" "+vIC);
	if (mandelbrot==true)
		{thecx=vRC;
		thecy=vIC;
		cyclex=0;
		cycley=0;
		mandelbrot=false;}
	else
		{
		cycle=true;
		cyclex=vRC;
		cycley=vIC;
		}
	if (cycled==false) {t.schedule(new timetask(),50,1511);}
 	cycled=true;
 	repaint();
	}
else { 
if (buttonDown == MouseEvent.BUTTON1) {dyna=false;}//Bouton GAUCHE enfoncé
if (buttonDown == MouseEvent.BUTTON2) {

	nb=nbdebut;
	if (attracteur==true) {nb=nbdebut+100;}
	nbi=0; 
	dyna=true;
	bstopdyna.setVisible(true);
	//System.out.println("bouton milieu");}	// Bouton milieu enfoncé 
	}
 {
	double vx=e.getX();
	double vy=e.getY();
	//Invoked when the mouse has been clicked on a component.
	if (flag==true)
		{flag=false;
		//System.out.println("Pressed"+vx+"-"+vy+"- "+minX+"-"+maxX+"- "+minY+"-"+maxY  );

		double deltaX=maxX-minX;
		double deltaY=maxY-minY;

		double vRC=minX + (maxX - minX)/(double)longueur * (double)vx;
		double vIC=minY + (maxY - minY)/(double)haut * (double)vy;
		if (mandelbrot==true)
			{thecx=vRC;
			thecy=vIC;
			}

		minX=vRC-deltaX/5.0;
		maxX=vRC+deltaX/5.0;
		minY=vIC-deltaY/5.0;
		maxY=vIC+deltaY/5.0;
		nb=nb+40;
		//text.visible=false; 
		//System.out.println(""+deltaX+"-"+deltaY+"- "+minX+"-"+maxX+"- "+minY+"-"+maxY);
		repaint();
		}
	}
} 
}
 
public void mouseClicked(MouseEvent e) {
	//System.out.println("Clicked");
	}
	//Invoked when a mouse button has been pressed on a component.

public void mouseReleased(MouseEvent e) {
	//System.out.println("Released");
	} 
	//Invoked when a mouse button has been released on a component.

public void mouseEntered(MouseEvent e) {
	//System.out.println("Entered");
	}
	//Invoked when the mouse enters a component.

public void mouseExited(MouseEvent e) {
	//System.out.println("Exited");
	}
	//Invoked when the mouse exits a component.


private void mandel () {
/*stage.addEventListener(MouseEvent.MOUSE_DOWN, clic);
stage.addChild(mc);
 
text.x=10; 
text.y=10;
text.width=500;
text.text="Ensemble deMandelbrot\nC est l ensemble des point complexes C tels que la suite Zn=Zn-1*Zn-1 + C ne diverge pas vers l infini\nCet ensemble est connexe (tous les points noirs sont relies entre eux)\nPour zoomer (et changer de point C pour Julia), cliquer sur les points colores voisins de l ensembe";
stage.addChild(text);*/

minX = -2.4;
maxX =  2.4;
minY = -1.5;
maxY = 1.5;

//draw();
}

private void mul(double a, double b, double m, double n)
	{
	resux=a*m-b*n;
	resuy=a*n+b*m;
	}


private void sinus(double x,double y)
	{
	resux=Math.sin(x)*(Math.exp(y)+Math.exp(-y))/2.0;
	resuy=Math.cos(x)*(Math.exp(y)-Math.exp(-y))/2.0;
	}


private void cosinus(double x,double y)
	{
	resux=Math.cos(x)*(Math.exp(y)+Math.exp(-y))/2.0;
	resuy=-Math.sin(x)*(Math.exp(y)-Math.exp(-y))/2.0;
	}
	
private void exp(double x,double y)
	{ 
	resux=Math.exp(x)*Math.cos(y);
	resuy=Math.exp(x)*Math.sin(y);
	}


public void calcule()
{
double logimag;
double logreal;
if (conjug==true) {I=-I;}
switch (numfon)
	{
	case 0:
		{	//Zn+1=Z*Z+C							zn+1=RZ,IZ  zn=R,I		c=RC,IC
		RZ = R*R - I*I + RC;
		IZ = 2* R*I + IC; 
		break;
		}
	case 1:
		{	// Z3+C
		elemx=R;
		elemy=I;
		for (int i=0;i<3;i++)
			{
			mul(elemx,elemy,R,I);
			elemx=resux;
			elemy=resuy;
			}
		RZ=resux+RC;
		IZ=resuy+IC;
		break;
		}
	case 2:
		{	//	Z4+C
		elemx=R;
		elemy=I;
		for (int i=0;i<4;i++)
			{
			mul(elemx,elemy,R,I);
			elemx=resux;
			elemy=resuy;
			}
		RZ=resux+RC;
		IZ=resuy+IC;
		break;
		}
	case 3:
		{	// Z5+C
		elemx=R;
		elemy=I;
		for (int i=0;i<5;i++)
			{
			mul(elemx,elemy,R,I);
			elemx=resux;
			elemy=resuy; 
			}
		RZ=resux+RC;
		IZ=resuy+IC;
		break;
		} 
	case 4:
		{ //	Zn+1 = C sin(Zn)
		sinus(R,I);
		elemx=resux;
		elemy=resuy;
		mul(RC,IC,elemx,elemy);
		RZ=resux;
		IZ=resuy;
		break;
		}
	case 5:
		{	//	Zn+1 = C i cos(Zn)
		cosinus(R,I);
		elemx=resux;
		elemy=resuy;
		mul(-IC,RC,elemx,elemy);
		RZ=resux;
		IZ=resuy;
		break;
		}
	case 6:
		{	// sin(Z)+C
		sinus(R,I);
		RZ=resux+RC;
		IZ=resuy+IC;
		break;
		}
	case 7:
		{ // cos(Z)+C
		cosinus(R,I);
		RZ=resux+RC;
		IZ=resuy+IC;
		break;
		}
	case 8:
		{	//	Zn+1 = C exp (Zn)
		exp(R,I);
		elemx=resux;
		elemy=resuy;
//		mul(RC,IC,resux,resuy); 
		RZ=resux+RC;
		IZ=resuy+IC;
		break;
		}
	case 9:
		{	//	Zn+1 = sin(Zn) + exp(Zn) + C
		sinus(R,I);
		elemx=resux;
		elemy=resuy;
		exp(R,I);
		RZ=elemx+resux+RC;
		IZ=elemy+resuy+IC;
		break;
		}	
	case 10:
		{	//	Zn+1 = sin(Zn) + exp(C) + Zn
		sinus(R,I);
		elemx=resux;
		elemy=resuy;
		exp(RC,IC);
		RZ=elemx+resux+R;
		IZ=elemy+resuy+I;
		break;
		}
	case 11:
		{	//ch(Z)+C
		exp(R,I);
		elemx=resux;
		elemy=resuy;
		exp(-R,-I);
		RZ=(elemx+resux)/2+RC;
		IZ=(elemy+resuy)/2+IC;
		break;
		}
	case 12:
		{	//sh(Z)+C
		exp(R,I);
		elemx=resux;
		elemy=resuy;
		exp(-R,-I);
		RZ=(elemx-resux)/2+RC;
		IZ=(elemy-resuy)/2+IC;
		break;	
		}
case 13:
		{	//	Zn+1 = C Zn (1 - Zn)
		mul(RC, IC, R,I);
		elemx=resux;
		elemy=resuy;
		mul(elemx,elemy,1-R,-I);
		RZ=resux;
		IZ=resuy;
		break;
		}
	case 14:
		{	// Z**1.5+C =exp(1.5*ln(z)) = exp(1.5*ln(x+yi),
/*		logreal = Math.log(Math.sqrt(R*R+I*I));
		if (Math.abs(R)<0.001)
			{logimag=Math.PI/2;}
		else
			{logimag = Math.atan(I/R);}
		if ((R<0) && (I>0)) {logimag=logimag+Math.PI;}
		if ((R<0) && (I<0)) {logimag=logimag-Math.PI;}
		double indexreal = 1.5*logreal;
		double indeximag = 1.5*logimag;
		RZ=Math.exp(indexreal)*Math.cos(indeximag);
		IZ=Math.exp(indexreal)*Math.sin(indeximag); 
		
		logreal = Math.log(1.5);
		if (Math.abs(1.5)<0.001)
			{logimag=Math.PI/2;}
		else
			{logimag = 0;}
		
		double indexreal = R*logreal-I*logimag;
		double indeximag = R*logimag+I*logreal;*/
		exp(R*Math.log(1.5),I*Math.log(1.5));
		RZ=resux;	//Math.exp(indexreal)*Math.cos(indeximag);
		IZ=resuy;	//Math.exp(indexreal)*Math.sin(indeximag); 
		break;
		}
	case 15:
		{	// Z**z+c 	=exp(z*ln(z)) = exp(x+yi)ln(x+yi), 
		logreal = Math.log(Math.sqrt(R*R+I*I));
		if (Math.abs(R)<0.001)
			{logimag=Math.PI/2;}
		else 
			{logimag = Math.atan(I/R);}
		if ((R<0) && (I>0)) {logimag=logimag+Math.PI;}
		if ((R<0) && (I<0)) {logimag=logimag-Math.PI;}
		double indexreal = R*logreal - I*logimag;
		double indeximag = R*logimag + I*logreal;
		RZ=Math.exp(indexreal)*Math.cos(indeximag);
		IZ=Math.exp(indexreal)*Math.sin(indeximag); 
		break;
		}
	default:
		{}
	}
}

public void paintComponent(Graphics g)
{

boolean  stop;
int a;
double max;
double module;
double epsilon=(maxX-minX)*0.000001/2.4;

RC=0;
IC=0;
int X;
int Y;
flag=false;
 
max=10;
if (numfon==0) {max=2;}
if (listen==false) {addMouseListener(this);}
listen=true;
color=0;
oldcolor=0;

if (mandelbrot==false)
	{
	RC=thecx;
	IC=thecy;
	}
for(X= 0;X<longueur-1;X++)
	{ // pour mandelbrot X Y represente C qui est la variable 
	  // pour julia X Y represente Z qui est la variable
	for (Y= 0;Y<haut-1;Y++)
		{
		if (mandelbrot==true)
			{ 
 			RC = minX + (maxX - minX)/longueur * X;	// RC est la partie réelle de C; elle est égale à la valeur de X courante; de -2,4 au départ à 2,4 à l'arrivée.
			IC = minY + (maxY - minY)/haut * Y;
 
			RZ = 0;
			IZ = 0; // Le nombre complexe Z est initialisé à 0.
			modulemin=10000.0;
			indexmin=0;
			}
		else 
			{
 			RZ = minX + (maxX - minX)/longueur * X;	// RC est la partie réelle de Z
			IZ = minY + (maxY - minY)/haut * Y;
			}
		stop=false;
		a=0;
	
		for(i=0;i<nbcycle;i++)
				{
				tabcyclex[i]=-10;
				tabcycley[i]=-10;
				} 
		while (stop==false)
			{ R = RZ;	// RZ est la partie réelle de Z mémorisée (n); R est la valeur en cours de calcul (n+1). 
			I = IZ;
			calcule();
			module=RZ*RZ + IZ*IZ;
			if (module<modulemin)
				{modulemin=module;
				indexmin=a;}
			if ( module > max*max) 
				{stop=true;color=(nb-1-a)*0xFFFFFF/nb;}
			else
				{
				if (attracteur==true)
					{
					for (i=0;i<nbcycle;i++)
						{
						if ((RZ-tabcyclex[i])*(RZ-tabcyclex[i])+(IZ-tabcycley[i])*(IZ-tabcycley[i])<epsilon) 
							{
							stop=true;
							if (attracteur==true) 
								{color=0xFF00*(nb-a)/nb;i=nbcycle;} 
							else
								{color=0;i=nbcycle;}
							}
						} // for
					tabcyclex[ncycle]=RZ;
					tabcycley[ncycle]=IZ;
					if (ncycle<nbcycle-1)
						{ncycle=ncycle+1;}
					else
						{ncycle=0;}
					}
				}
			
 			if (a==nb-1) {stop=true;color=0;} 
 			if (stop==false)	{a++;}
 			} // while
		switch (coloration)
				{ 
				case 0: {	break; }
				case 1:	
					{	// abs module
					if ((Math.abs(RZ) < max) && (Math.abs(IZ) < max)) {color=Color.black.getRGB();}
					if ((Math.abs(RZ) >= max) && (Math.abs(IZ) < max)) {color=Color.red.getRGB();}
					if ((Math.abs(RZ) < max) && (Math.abs(IZ) >= max)) {color=Color.green.getRGB();}
					if ((Math.abs(RZ) >= max) && (Math.abs(IZ) >= max)) {color=Color.yellow.getRGB();} 
					break;
					}
				case 2:
					{ 	// angle
					double angle=Math.atan(IZ/RZ);
					if ((RZ<0) && (IZ>0)) {angle=angle+Math.PI;}
					if ((RZ<0) && (IZ<0))	{angle=angle+Math.PI;}
					if ((RZ>0) && (IZ<0))	{angle=angle+2*Math.PI;}
					i=(int) Math.floor(angle/(Math.PI/4));
					i=i % 2;
					if (i == 0)
						{color=Color.white.getRGB();}
					else	
						{color=Color.black.getRGB();}
					break;
					}
				case 3:
					{	// imaginaire positif
					if (IZ>0) {color=Color.black.getRGB();}
					else	{color=Color.white.getRGB();}
					break;
					}
				case 4:
					{ // rz et iz modulo 2
					double rz=(int) Math.floor(Math.abs(RZ))%2;
					double iz=(int) Math.floor(Math.abs(IZ))%2;
					if ((rz ==0) && (iz ==0)) {color=Color.black.getRGB();}
					if ((rz ==0) && (iz ==1)) {color=Color.cyan.getRGB();}
					if ((rz ==1) && (iz ==0)) {color=Color.blue.getRGB();}
					if ((rz ==1) && (iz ==0)) {color=Color.yellow.getRGB();} 
					break;
					}
				case 5:	
					{	// equipotentiel
					if (color==0) 
						{oldcolor=0;}
					else
						{
						if (color==oldcolor)
							{color=Color.white.getRGB();}
						else
							{if (oldcolor==0)
									{oldcolor=color;color=Color.white.getRGB();}
								else 
									{
									oldcolor=color;
									color=Color.black.getRGB();
									}
							}
						}
					break; 
					}
				case 6:
					{ // modulemin
					if (color==0)
						{double rz=(int) Math.floor(modulemin*500);
						rz=rz%2;
						if (rz==0) {color=Color.white.getRGB();}
						else {color=Color.black.getRGB();}
						}
					else
						{color=a%2;
						if (color==0) {color=Color.black.getRGB();}
						else {color=Color.white.getRGB();}
						}
					break;
					}
				case 7:
					{ // fibonacci
					if (color==0)
						{color=indexmin*0xFFFFFF/10;}
					else
						{color=a%2;
						if (color==0) {color=Color.black.getRGB();}
						else {color=Color.white.getRGB();}
						}
					break;
					}
				default:{}
				} 
		buffimag.setRGB(X, Y, color); 
/* 	g.setColor(mycol);          
 		g.drawLine(X,Y,X,Y);*/
 		} // for Y
 	} // for X
 	
g.drawImage(buffimag, 0, 0, null);  

//if (mandelbrot==true)
	{
	if (montre==true) 
		{
		g.setColor(Color.white); 
		int rc=longueur/2;
		int ic=haut/2;
		g.setColor(Color.magenta); 
		g.drawLine(rc-5,ic,rc+5,ic);
		g.drawLine(rc,ic-5,rc,ic+5);
		int rc0= (int) Math.floor(( -minX)/(maxX - minX)*longueur);
		int ic0=(int) Math.floor(( -minY)/(maxY - minY)*haut);
		g.drawLine(rc0-500,ic0,rc0+500,ic0);
		g.drawLine(rc0,ic0-400,rc0,ic0+400);
		int rc1= (int) Math.floor((1 -minX)/(maxX - minX)*longueur);
		g.drawLine(rc1,ic0-3,rc1,ic0+3);
		int ic1=(int) Math.floor((1 -minY)/(maxY - minY)*haut);
		g.drawLine(rc0-3,ic1,rc0+3,ic1);
		
		rc= (int) Math.floor((thecx -minX)/(maxX - minX)*longueur);
		ic=(int) Math.floor( (thecy -minY)/(maxY - minY)*haut);
		g.setColor(Color.red); 
		g.drawLine(rc-7,ic,rc+7,ic);
		g.drawLine(rc,ic-7,rc,ic+7);
		}
	} 
if (cycle==true)
	{
	X= (int) Math.floor((cyclex -minX)/(maxX - minX)*longueur);
	Y=(int) Math.floor( (cycley -minY)/(maxY - minY)*haut);
//	System.out.println("croix "+cyclex+" "+cycley+" "+X+" "+Y);
	g.setColor(Color.white);
	g.drawLine(X-5,Y,X+5,Y);
	g.drawLine(X,Y-5,X,Y+5);
	}

if ((coloration==7) && (mandelbrot==true) && (numfon==0))
	{
	showperiode=false;
	attracteur=false;
	g.setColor(Color.white);
	for (i=0;i<(fibonacci.length+1)/3;i++)
		{
			int rc0= (int) Math.floor((fibonacci[3*i] -minX)/(maxX - minX)*longueur);
			int ic0=(int) Math.floor((fibonacci[3*i+1] -minY)/(maxY - minY)*haut);
			int j=(int) Math.floor(fibonacci[3*i+2]+0.1);
			g.drawString(""+j,rc0-2,ic0+3);
			
		}
	}

if ((showperiode==true) && (mandelbrot==true) && (numfon==0))
	{
	int nperiod=2;
	g.setColor(Color.white);
	if (maxX-minX>1.7) {nperiod=1;}
	if (maxX-minX<0.65) {nperiod=3;}
	for (i=0;i<(period.length+1)/4;i++)
		{
		if (nperiod+1>period[4*i+3])
			{
			int rc0= (int) Math.floor((period[4*i] -minX)/(maxX - minX)*longueur);
			int ic0=(int) Math.floor((period[4*i+1] -minY)/(maxY - minY)*haut);
			int j=(int) Math.floor(period[4*i+2]+0.1);
			g.drawString(""+j,rc0-2,ic0+3);
			}
		}
	}

flag=true; 
} // paint 
  class timetask extends TimerTask
        	{
        	public void run()  
        		{
    				if ((cycle==true) && (flag==true))
    						{
    						mandelbrot=false;
        				RC=thecx;
        				IC=thecy;
        				R=cyclex;
        				I=cycley;
        				calcule();
        				if ((RZ-cyclex)*(RZ-cyclex)+(IZ-cycley)*(IZ-cycley) < 0.0001) {cycle=false;}
        				cyclex=RZ;
        				cycley=IZ;
        		//		System.out.println("timer "+RZ+" "+IZ);
        				if (cyclex*cyclex+cycley*cycley>10){cycle=false;}
        				if (cycle==true) {repaint();}
        				}
        		}
        	} 

} // class

