package javaapplication3;
/**
*
* @author thomas
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Grafik09 extends Applet implements
MouseListener, MouseMotionListener {
int mouseX1 = 0, mouseY1 = 0,mouseX2 = 0, mouseY2 = 0;
int mouseX1o=0,mouseY1o=0,mouseX2o=0,mouseY2o=0;
int clicko=0,click=0,click2=0;
float pattern=250,paramx=(float)1.7,paramy=(float)1.2;
Graphics g;
// die Methode wird beim Start des Applets aufgerufen
public void init() {
resize(600, 600);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g) {
int zb1;
float x,y,xx,yy,zz,zx,zy,zxx,zyy,z,zb;
String[] dataf = {
"000000",
"000080",
"00008B",
"0000CD",
"0000FF",
"006400",
"008000",
"008080",
"008B8B",
"00BFFF",
"00CED1",
"00FA9A",
"00FF00",
"00FF7F",
"00FFFF",
"00FFFF",
"191970",
"1E90FF",
"20B2AA",
"228B22",
"2E8B57",
"2F4F4F",
"32CD32",
"3CB371",
"40E0D0",
"4169E1",
"4682B4",
"483D8B",
"48D1CC",
"4B0082",
"556B2F",
"5F9EA0",
"6495ED",
"66CDAA",
"696969",
"6A5ACD",
"6B8E23",
"708090",
"778899",
"7B68EE",
"7CFC00",
"7FFF00",
"7FFFD4",
"800000",
"800080",
"808000",
"808080",
"87CEEB",
"87CEFA",
"8A2BE2",
"8B0000",
"8B008B",
"8B4513",
"8FBC8F",
"90EE90",
"9370D8",
"9400D3",
"98FB98",
"9932CC",
"9ACD32",
"A0522D",
"A52A2A",
"A9A9A9",
"ADD8E6",
"ADFF2F",
"AFEEEE",
"B0C4DE",
"B0E0E6",
"B22222",
"B8860B",
"BA55D3",
"BC8F8F",
"BDB76B",
"C0C0C0",
"C71585",
"CD5C5C",
"CD853F",
"D2691E",
"D2B48C",
"D3D3D3",
"D87093",
"D8BFD8",
"DA70D6",
"DAA520",
"DC143C",
"DCDCDC",
"DDA0DD",
"DEB887",
"E0FFFF",
"E6E6FA",
"E9967A",
"EE82EE",
"EEE8AA",
"F08080",
"F0E68C",
"F0F8FF",
"F0FFF0",
"F0FFFF",
"F4A460",
"F5DEB3",
"F5F5DC",
"F5F5F5",
"F5FFFA",
"F8F8FF",
"FA8072",
"FAEBD7",
"FAF0E6",
"FAFAD2",
"FDF5E6",
"FF0000",
"FF00FF",
"FF00FF",
"FF1493",
"FF4500",
"FF6347",
"FF69B4",
"FF7F50",
"FF8C00",
"FFA07A",
"FFA500",
"FFB6C1",
"FFC0CB",
"FFD700",
"FFDAB9",
"FFDEAD",
"FFE4B5",
"FFE4C4",
"FFE4E1",
"FFEBCD",
"FFEFD5",
"FFF0F5",
"FFF5EE",
"FFF8DC",
"FFFACD",
"FFFAF0",
"FFFAFA",
"FFFF00",
"FFFFE0",
"FFFFF0",
"FFFFFF"
};
for(x=0;x<601;x++){ // die Mandelbrotmenge
xx=x/pattern- paramx;
for(y=0;y<601;y++){
yy= y / pattern - paramy;
z=0;zz=0;
zx=0;zy=0;
while(zz<2 && z<777){
zxx= (zx * zx) - (zy * zy) +xx;
zyy= (2* zx * zy) +yy;
zz=zx*zx+zy*zy;
z++; // das "n" der Folge
zx=zxx;zy=zyy;
}
zb=z*(float)0.15; // das entspricht inetwa der Arraygröße
zb1=(int) zb;
g.setColor(new Color(Integer.parseInt(dataf[zb1], 16)));
g.drawLine((int)x, (int)y, (int)x, (int)y);
}
}
}
public void paint2(Graphics g) { // die XOR Markierung um die es hier eigentlich ging
g.setXORMode(Color.red);
if(clicko==2){
g.drawLine(mouseX1o,mouseY1o,mouseX2o,mouseY1o);
g.drawLine(mouseX2o,mouseY1o,mouseX2o,mouseY2o);
g.drawLine(mouseX2o,mouseY2o,mouseX1o,mouseY2o);
g.drawLine(mouseX1o,mouseY2o,mouseX1o,mouseY1o); // das ist so weil rectangle nur positiv geht
}
if(click2!=2){
g.drawLine(mouseX1,mouseY1,mouseX2,mouseY1);
g.drawLine(mouseX2,mouseY1,mouseX2,mouseY2);
g.drawLine(mouseX2,mouseY2,mouseX1,mouseY2);
g.drawLine(mouseX1,mouseY2,mouseX1,mouseY1);
}
mouseX1o=mouseX1;
mouseX2o=mouseX2;
mouseY1o=mouseY1;
mouseY2o=mouseY2;
clicko=click;
click2=0;
}
public void mouseClicked(MouseEvent me)
{
}
public void mouseEntered(MouseEvent me)
{
click=0;
}
public void mouseExited(MouseEvent me)
{
g=super.getGraphics();
click=0;
click2=2;
paint2(g);
}
public void mousePressed(MouseEvent me)
{
mouseX1 = me.getX();
mouseY1 = me.getY();
click = 2;
}
public void mouseReleased(MouseEvent me)
{
float newPosX=0,newPosY=0,newDX;
int temp;
if(mouseX1>mouseX2){temp=mouseX1;mouseX1=mouseX2;mouseX2=temp;}
if(mouseY1>mouseY2){temp=mouseY1;mouseY1=mouseY2;mouseY2=temp;}
newPosX=(float)mouseX1/pattern-paramx;
newPosY=(float)mouseY1/pattern-paramy;
newDX=(float)mouseX2-(float)mouseX1;
newDX=java.lang.Math.abs(newDX)/pattern;
paramx=newPosX;
paramy=newPosY;
pattern=600/newDX;
//showStatus("Dragging mouse at " + newPosX + ", " + newPosY+" "+pattern);
g=super.getGraphics();
//g.dispose();
paint(g); // HIER hätte ich gerne g so wie bei dem ersten automatichen (Warum?) Aufruf von paint.
}
public void mouseDragged(MouseEvent me)
{
g=super.getGraphics();
if(click==2){
mouseX2 = me.getX();
mouseY2 = me.getY();
paint2(g);
}
}
public void mouseMoved(MouseEvent me) { }