// $Header: z:/javafrak.java 2.1
import java.awt.*;
import java.lang.*;
public class javafrak extends java.applet.Applet
implements Runnable
{
Thread thread=null;
int Max_X,Max_Y,Iter,X,Y,Col,ColR,ColG,ColB;
double A,B,C,D,G,F,H,I,J,K,L,M,Zoom,verti,hori;
double A1,B1,C1,D1,Step;
String message1,message2,textfont;
int textsize,textX,textY,textH,textW;
Graphics offGraphics;
Image offImage;
public void init()
{
Max_X=size().width;
Max_Y=size().height;
offImage=createImage(Max_X,Max_Y);
offGraphics=offImage.getGraphics();
offGraphics.fillRect(0,0,Max_X+1,Max_Y+1);
Iter = 1250;
hori = .000036; // nach rechts
verti = .000035; // höher
Zoom = .002500; // tiefer
Step = Zoom/80;
A = -.765216+Zoom+hori;
B = -.765325-Zoom+hori;
C = .099886-Zoom+verti;
D = .099996+Zoom+verti;
message1 = "Bitte etwas Geduld";
message2 = "Fraktal wird berechnet";
textfont = "TimesRoman";
textsize = 36;
Font myFont=new Font(textfont, Font.BOLD, textsize);
FontMetrics myMetrix=getFontMetrics(myFont);
textH=myMetrix.getHeight();
textW=myMetrix.stringWidth(message1);
textX=(int)((Max_X-textW)/2);
textY=(int)((Max_Y-textH)/2)-myMetrix.getDescent();
setFont(myFont);
}
public void start()
{
if(thread == null)
{
thread = new Thread(this);
thread.start();
}
}
public void stop()
{
thread = null;
offImage = null;
offGraphics = null;
}
public void run()
{
while (thread != null)
{
try {Thread.sleep(0);}
catch (InterruptedException e) {}
repaint();
}
}
public void paint(Graphics g)
{
setBackground(Color.black);
g.setColor(Color.green);
g.drawString(message1,textX,textY);
g.drawString(message2,textX-textsize,textY+textH);
update(g);
}
public void update(Graphics g)
{
A1 = A;
B1 = B;
C1 = C;
D1 = D;
A -= Step;
B += Step;
C += Step;
D -= Step;
G=(D1-C1)/Max_Y;
F=(B1-A1)/Max_X;
//----------------------------------------------
for (Y = 0; Y < Max_Y; Y++)
{
for (X = 0; X < Max_X; X++)
{
Col=0;
K=G*Y+C1;
J=K;
I=F*X+A1;
H=I;
L=J*J;
M=H*H;
//----------------------------------------------
frak: {
while (Col<Iter)
{
J=2*H*J+K;
H=M-L+I;
L=J*J;
M=H*H;
Col++;
if ((M+L)>4)
{
break frak;
}
}
}
// -------------- Pixel-Setzer ----------------
Col=(Col & 0x0000FF); // and
ColR=(Col & 0xE0);
ColG=(Col & 0x18);
ColG=(ColG << 3); // shl
ColB=(Col & 0x07);
ColB=(ColB << 5);
offGraphics.setColor(new Color(ColR,ColG,ColB));
offGraphics.drawLine(X,Y,X,Y);
//----------------------------------------------
} // next X
} // next Y
//----------------------------------------------
g.drawImage(offImage,0,0,this);
}
}