poniedziałek, 22 września 2014

Java Simple Fractal

This is simple fractal in Java Applet.  I make cool draw for circle  and simple algorithm



CODE:

import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;

public class Fraktal extends Applet {

/*
* numer version is not necessary but eclipse want it linia nie wymagana ale
* eclipse chce ja
*/
private static final long serialVersionUID = -4516025624539478755L;

int level = 0; // create stages etapy tworzenia

public void init() { // for applet main main apletów

setBackground(new Color(244, 235, 155)); // random color :)

}

public boolean mouseDown(Event ev, int x, int y) {
/*
* MOUSE left next level, right previous level MYSZKA lewy nastepny
* poziom prawy poprzedni
*/
if (!ev.metaDown())
level += 1;
else
level = 0;
repaint();
return true;
}

public void paint(Graphics g) {

g.setColor(Color.BLUE);
drawCircle(g, 280, 20, 700, level);

}

/*
* this is all operation wszystko co potrzeba tu jest
*/
public void drawCircle(Graphics g, int x, int y, int p, int level) {
int help;
g.drawOval(x, y, p, p);
if (level == 0)
return;
level -= 1;
if (p > 2) {
help = p / 4;
// drawCircle(g, x + help, y + help, 2 * help, level); //start
// version wersja poczatkowa
drawCircle(g, x + 3 * help, y + help, 2 * help, level);
drawCircle(g, x - help, y + help, 2 * help, level);

drawCircle(g, x + help, y + 3 * help, 2 * help, level);
drawCircle(g, x + help, y - help, 2 * help, level);
}

}

}

Brak komentarzy:

Prześlij komentarz