Game-Apps für Smartphones und Tablets

Bern University oh Teacher Education  
HomeOnline-Editor startenDruckenAndroid-TurtlegrafikJava-Online

Farn


Fraktale sind computergenerierte Bilder, die eine Selbstähnlichkeit aufweisen, d.h. bei denen Teilbilder eine verkleinerte Kopie des Gesamtbildes sind. Zur Berechnung der Bildpunkte des Farn sind komplexe Zahlen erforderlich.

 

Beispiel im Online-Editor bearbeiten

App installieren auf Smartphone oder Tablet

QR-Code

Sources downloaden (Farn.zip)

 

 
Programmcode:

// Farn.java

package app.farn;

import ch.aplu.android.*;
import ch.aplu.util.*;
import java.util.*;
import android.graphics.*;

public class Farn extends GameGrid
{
  GGPanel p;

  public void main()
  {
    p = getPanel();
    int nb = requestInt("Point Density""Enter number of points"20000);
    farn(nb);
  }

  private void farn(int nbIterations)
  {
    p.window(-3.5, 3.5, 0, 10);
    Complex = new Complex(0, 0);
    int it = 0;
    Random rnd = new Random();

    while (it <= nbIterations)
    {
      if (it % 1000 == 0)
      {
        p.color(Color.WHITE);
      }
      double = rnd.nextDouble();
      int color = Color.BLACK;

      if (r < 0.01)
      {
        color = Color.YELLOW;
        z = f(z, 0, 0, 0, 0.16, 0, 0); // Stiel
      }
      else
      {
        if (r < 0.86)
        {
          color = Color.GREEN;
          z = f(z, 0.85, 0.04, -0.04, 0.85, 0, 1.60); // symmetry
        }
        else
        {
          if (r > 0.86 && < 0.93)
          {
            color = Color.RED;
            z = f(z, 0.20, -0.26, 0.23, 0.22, 0, 1.60); // left leaves
          }
          else
          {
            if (r > 0.93)
            {
              color = Color.BLUE;
              z = f(z, -0.15, 0.28, 0.26, 0.24, 0, 1.44); // right leaves
            }
          }
        }
      }
      p.color(color);
      p.point(z.real, z.img);
      it++;
    }
    setTitle("Creating Farm...Done.");
  }

  private Complex f(Complex z,
    double a, double b, double c, double d, double e, double f)
  {
    double re = * z.real + * z.img + e;
    double im = * z.real + * z.img + f;
    return new Complex(re, im);
  }
}