Hallo,
mein Programm zeigt mir einen Frame mit der Mandelbrotmenge, an die ich per Mausklick digital ran- und rauszoomen kann.
Mein Problem ist dass der Frame pro Zeichnung ca 3 sekunden braucht bis das komplette bild angezeigt wird, also würde ich ihn gerne erst irgendwo im hintergrund oder einer externen datei zeichnen lassen und ihn sobald er mit zeichnen fertig ist in meinen frame einfügen, sodass er dann wenn ich wieder ran - oder rauszoome einfach so bleibt wie er ist bis das neue bild im hintergrund gezeichnet ist und somit das alte ersetzen kann...
weil das nervt schon wenn sich die ganze zeit beim zoomen das bild von links nach rechts aufbaut und außerdem ist es bestimmt auch schneller wenn sich das bild im hintergrund aufbaut vermute ich mal
vielen dank im vorraus
mein Programm zeigt mir einen Frame mit der Mandelbrotmenge, an die ich per Mausklick digital ran- und rauszoomen kann.
Mein Problem ist dass der Frame pro Zeichnung ca 3 sekunden braucht bis das komplette bild angezeigt wird, also würde ich ihn gerne erst irgendwo im hintergrund oder einer externen datei zeichnen lassen und ihn sobald er mit zeichnen fertig ist in meinen frame einfügen, sodass er dann wenn ich wieder ran - oder rauszoome einfach so bleibt wie er ist bis das neue bild im hintergrund gezeichnet ist und somit das alte ersetzen kann...
weil das nervt schon wenn sich die ganze zeit beim zoomen das bild von links nach rechts aufbaut und außerdem ist es bestimmt auch schneller wenn sich das bild im hintergrund aufbaut vermute ich mal
Java:
package de.straube.Tests;
import java.awt.Color;
import java.awt.Event;
import java.awt.Frame;
import java.awt.Graphics;
public class Mandelbrotmenge
extends Frame
{
/**
*
*
*/
private static final long serialVersionUID = 1L;
int MAX_COUNTER = 200;
double amin = -1.5;
double amax = 0.5;
double bmin = -1;
double bmax = 1;
int xOffset = 0;
int yOffset = 30;
int counter = 0;
public static void main(String arguments[])
{
Mandelbrotmenge frame = new Mandelbrotmenge();
frame.setLocation(100, 100);
frame.setVisible(true);
frame.setSize(800, 800);
}
Mandelbrotmenge()
{
super("Mandelbrotmenge");
}
public boolean mouseUp(Event e, int x, int y)
{
if (e.modifiers == 0)
{
double width = this.getSize().width;
double height = this.getSize().height;
double qa = x / width;
double da = amax - amin;
double a = amin + da * qa;
// neuer Bereich ist nur halb so groß
da = da / 2;
// neues amin = a - die Hälfte des neuen Bereichs
amin = a - da / 2;
amax = a + da / 2;
double qb = y / height;
double db = bmax - bmin;
double b = bmin + db * qb;
// neue Bereich ist nur halb so groß
db = db / 2;
// neues bmin = b - die Hälfte des neuen Bereichs
bmin = b - db / 2;
bmax = b + db / 2;
this.update(this.getGraphics());
}
if (e.modifiers == 4)
{
double width = this.getSize().width;
double height = this.getSize().height;
double qa = x / width;
double da = amax - amin;
double a = amin + da * qa;
// neuer Bereich ist nur halb so groß
da = da / 2;
// neues amin = a - die Hälfte des neuen Bereichs
amin = a - da * 2;
amax = a + da * 2;
double qb = y / height;
double db = bmax - bmin;
double b = bmin + db * qb;
// neue Bereich ist nur halb so groß
db = db / 2;
// neues bmin = b - die Hälfte des neuen Bereichs
bmin = b - db * 2;
bmax = b + db * 2;
this.update(this.getGraphics());
}
if (e.modifiers == 1)
{
double width = this.getSize().width;
double height = this.getSize().height;
double qa = x / width;
double da = amax - amin;
double a = amin + da * qa;
// neuer Bereich ist nur halb so groß
da = da / 2;
// neues amin = a - die Hälfte des neuen Bereichs
amin = a - da;
amax = a + da;
double qb = y / height;
double db = bmax - bmin;
double b = bmin + db * qb;
// neue Bereich ist nur halb so groß
db = db / 2;
// neues bmin = b - die Hälfte des neuen Bereichs
bmin = b - db;
bmax = b + db;
this.update(this.getGraphics());
}
return true;
}
public void paint(Graphics bs)
{
int zaehler;
int ysize = this.getSize().height - 35;
int xsize = this.getSize().width - 5;
double dsx = (amax - amin) / xsize;
double dsy = (bmax - bmin) / ysize;
double a = amin;
for (int s = 0; s <= xsize; s++ )
{
double b = bmin;
for (int r = 0; r <= ysize; r++ )
{
zaehler = berechnePunkt(a, b);
bs.setColor(ermittleFarbe(zaehler));
bs.drawLine(s + xOffset, r + yOffset, s + xOffset, r + yOffset);
b = b + dsy;
}
a = a + dsx;
}
}
private int berechnePunkt(double a, double b)
{
int zaehler = 0;
double x = 0;
double y = 0;
double xx = 0;
double squareRoot = 0;
while (true)
{
squareRoot = Math.sqrt(x * x + y * y);
if (squareRoot >= 3)
break;
zaehler++ ;
if (zaehler == MAX_COUNTER)
break;
xx = x * x - y * y + a;
y = 2 * x * y + b;
x = xx;
}
// Ende Berechnung eines Punktes *************************
return zaehler;
}
private Color ermittleFarbe(int zaehler)
{
if (zaehler == MAX_COUNTER)
{
return Color.black;
}
else if (zaehler < 4)
{
return Color.magenta;
}
else if (zaehler == 5)
{
return Color.pink;
}
else if (zaehler == 6)
{
return Color.blue;
}
else if (zaehler == 7)
{
return Color.red;
}
else if (zaehler == 8)
{
return Color.orange;
}
else if (zaehler == 9)
{
return Color.cyan;
}
else if (zaehler == 10)
{
return Color.red;
}
else if (zaehler <= 20)
{
return Color.green;
}
else if (zaehler <= 30)
{
return Color.lightGray;
}
else if (zaehler <= 40)
{
return Color.blue;
}
else if (zaehler <= 50)
{
return Color.yellow;
}
else if (zaehler <= 60)
{
return Color.magenta;
}
else if (zaehler <= 70)
{
return Color.gray;
}
else if (zaehler <= 80)
{
return Color.orange;
}
else if (zaehler <= 90)
{
return Color.white;
}
else if (zaehler <= 100)
{
return Color.DARK_GRAY;
}
else if (zaehler <= 110)
{
return Color.ORANGE;
}
else if (zaehler <= 120)
{
return Color.YELLOW;
}
else if (zaehler <= 130)
{
return Color.MAGENTA;
}
else if (zaehler <= 140)
{
return Color.GREEN;
}
else if (zaehler <= 150)
{
return Color.PINK;
}
else if (zaehler <= 160)
{
return Color.orange;
}
else if (zaehler <= 170)
{
return Color.blue;
}
else if (zaehler <= 180)
{
return Color.darkGray;
}
else if (zaehler <= 190)
{
return Color.LIGHT_GRAY;
}
else if (zaehler <= 200) { return Color.green; }
return Color.yellow;
}
}
vielen dank im vorraus