Java & JavaScript


Home
Applets
   3D:
 · Würfel
 · Würfel 2
 · Würfel 3
 · Tetraeder
 · Tetraeder 2
 · Dodekaeder
 · Ikosaeder
 · Fußball
 · Kugel
 · Kugel 2
   Fraktale:
 · Apfelmännchen
 · Apfelmännchen 2
 · Apfelmännchen 3
 · Apfelmännchen MA
 · Apfelmännchen Zoom
 · Apfelmännchen Zoom 2
 · Juliamenge
 · Juliamenge MA
 · Julia-Generator
 · Koch-Kurve
 · Koch-Kurve 2
 · Hilbert-Kurve
 · Sierpinski-Dreieck
 · Sierpinski-Dreieck 2
 · Sierpinski-Dreieck 3
 · Sierpinski-Teppich
 · Pythagoras-Baum
 · Lindenmayer-System
 · Lindenmayer-System 2
   Mathematik:
 · Funktionsplotter
 · Eratosthenes-Sieb
 · Miller-Rabin-Test
   Verschiedenes:
 · Morsezeichen-Ticker
 · Analoguhr
Scripts
Gäste
Kontakt

- Applets : 3D : Fußball -


Ein rotierender Fußball als Java-Applet.

[Der Fußball (Bucky-Ball) in Rotation als Java-Applet lässt sich allerdings nur mit aktiviertem Java betrachten !]


Fußball.java

import java.awt.*;
import java.applet.*;

public class Fußball extends Applet {

    // 60 Eckpunkte 1-60
    // mit je 3 Koordinaten 1,2,3
    double p[][] = new double[61][4];

    int x=1, y=2, z=3;

    public void init() {
        setBackground(new Color(255,255,255));

        // Halbe Seitenlänge des umschriebenen Würfels
        double s = 150;

        // Hilfsmaße
        double h  = s*0.5*(Math.sqrt(5)-1);
        double h1 = h/3;
        double h2 = h*2/3;
        double s1 = s/3;
        double s2 = s*2/3;
        double k1 = h+(s-h)/3;
        double k2 = h+(s-h)*2/3;

        // 60 Eckpunkte im lokalen Fußball-Koordinatensystem
        p[1][x] =  -s;     p[1][y] =   0;     p[1][z] =   h1;
        p[2][x] =  -s;     p[2][y] =   0;     p[2][z] =  -h1;
        p[3][x] =  -k2;    p[3][y] =   s1;    p[3][z] =  -h2;
        p[4][x] =  -k1;    p[4][y] =   s2;    p[4][z] =  -h1;
        p[5][x] =  -k1;    p[5][y] =   s2;    p[5][z] =   h1;
        p[6][x] =  -k2;    p[6][y] =   s1;    p[6][z] =   h2;
        p[7][x] =  -k2;    p[7][y] =  -s1;    p[7][z] =  -h2;
        p[8][x] =  -k1;    p[8][y] =  -s2;    p[8][z] =  -h1;
        p[9][x] =  -k1;    p[9][y] =  -s2;    p[9][z] =   h1;
        p[10][x] = -k2;    p[10][y] = -s1;    p[10][z] =  h2;
        p[11][x] = -s2;    p[11][y] = -h1;    p[11][z] =  k1;
        p[12][x] = -s1;    p[12][y] = -h2;    p[12][z] =  k2;
        p[13][x] =  0;     p[13][y] = -h1;    p[13][z] =  s;
        p[14][x] =  0;     p[14][y] =  h1;    p[14][z] =  s;
        p[15][x] = -s1;    p[15][y] =  h2;    p[15][z] =  k2;
        p[16][x] = -s2;    p[16][y] =  h1;    p[16][z] =  k1;
        p[17][x] = -h1;    p[17][y] =  k1;    p[17][z] =  s2;
        p[18][x] = -h2;    p[18][y] =  k2;    p[18][z] =  s1;
        p[19][x] = -h2;    p[19][y] = -k2;    p[19][z] =  s1;
        p[20][x] = -h1;    p[20][y] = -k1;    p[20][z] =  s2;
        p[21][x] =  s;     p[21][y] =  0;     p[21][z] = -h1;
        p[22][x] =  s;     p[22][y] =  0;     p[22][z] =  h1;
        p[23][x] =  k2;    p[23][y] = -s1;    p[23][z] =  h2;
        p[24][x] =  k1;    p[24][y] = -s2;    p[24][z] =  h1;
        p[25][x] =  k1;    p[25][y] = -s2;    p[25][z] = -h1;
        p[26][x] =  k2;    p[26][y] = -s1;    p[26][z] = -h2;
        p[27][x] =  k2;    p[27][y] =  s1;    p[27][z] =  h2;
        p[28][x] =  k1;    p[28][y] =  s2;    p[28][z] =  h1;
        p[29][x] =  k1;    p[29][y] =  s2;    p[29][z] = -h1;
        p[30][x] =  k2;    p[30][y] =  s1;    p[30][z] = -h2;
        p[31][x] =  s2;    p[31][y] =  h1;    p[31][z] = -k1;
        p[32][x] =  s1;    p[32][y] =  h2;    p[32][z] = -k2;
        p[33][x] =  0;     p[33][y] =  h1;    p[33][z] = -s;
        p[34][x] =  0;     p[34][y] = -h1;    p[34][z] = -s;
        p[35][x] =  s1;    p[35][y] = -h2;    p[35][z] = -k2;
        p[36][x] =  s2;    p[36][y] = -h1;    p[36][z] = -k1;
        p[37][x] =  h1;    p[37][y] = -k1;    p[37][z] = -s2;
        p[38][x] =  h2;    p[38][y] = -k2;    p[38][z] = -s1;
        p[39][x] =  h2;    p[39][y] =  k2;    p[39][z] = -s1;
        p[40][x] =  h1;    p[40][y] =  k1;    p[40][z] = -s2;
        p[41][x] = -h1;    p[41][y] =  s;     p[41][z] =  0;
        p[42][x] =  h1;    p[42][y] =  s;     p[42][z] =  0;
        p[43][x] =  h2;    p[43][y] =  k2;    p[43][z] =  s1;
        p[44][x] =  h1;    p[44][y] =  k1;    p[44][z] =  s2;
        p[45][x] =  s1;    p[45][y] =  h2;    p[45][z] =  k2;
        p[46][x] =  s2;    p[46][y] =  h1;    p[46][z] =  k1;
        p[47][x] =  s1;    p[47][y] = -h2;    p[47][z] =  k2;
        p[48][x] =  s2;    p[48][y] = -h1;    p[48][z] =  k1;
        p[49][x] =  h1;    p[49][y] = -k1;    p[49][z] =  s2;
        p[50][x] =  h2;    p[50][y] = -k2;    p[50][z] =  s1;
        p[51][x] =  h1;    p[51][y] = -s;     p[51][z] =  0;
        p[52][x] = -h1;    p[52][y] = -s;     p[52][z] =  0;
        p[53][x] = -h2;    p[53][y] = -k2;    p[53][z] = -s1;
        p[54][x] = -h1;    p[54][y] = -k1;    p[54][z] = -s2;
        p[55][x] = -s1;    p[55][y] = -h2;    p[55][z] = -k2;
        p[56][x] = -s2;    p[56][y] = -h1;    p[56][z] = -k1;
        p[57][x] = -s1;    p[57][y] =  h2;    p[57][z] = -k2;
        p[58][x] = -s2;    p[58][y] =  h1;    p[58][z] = -k1;
        p[59][x] = -h1;    p[59][y] =  k1;    p[59][z] = -s2;
        p[60][x] = -h2;    p[60][y] =  k2;    p[60][z] = -s1;
    }

    // Rotationswinkel in rad
    double ax = 0.01;
    double ay = 0.0075;
    double az = 0.005;

    Image buffer;
    Graphics2D gBuffer;

    double px, py, pz;

    public void paint(Graphics g) {

        // Double-Buffering
        if (buffer==null) {
            buffer=createImage(this.getSize().width, this.getSize().height);
            gBuffer=(Graphics2D)buffer.getGraphics();
        }
        gBuffer.clearRect(0,0, this.getSize().width, this.getSize().height);

        // Antialiasing
        gBuffer.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

        // Fußball-Eckpunkte verbinden. 90 Kanten
        drawLine(1,2);     drawLine(2,3);     drawLine(3,4);
        drawLine(4,5);     drawLine(5,6);     drawLine(6,1);
        drawLine(2,7);     drawLine(7,8);     drawLine(8,9);
        drawLine(9,10);    drawLine(10,1);    drawLine(11,12);
        drawLine(12,13);   drawLine(13,14);   drawLine(14,15);
        drawLine(15,16);   drawLine(16,11);   drawLine(6,16);
        drawLine(10,11);   drawLine(5,18);    drawLine(18,17);
        drawLine(17,15);   drawLine(9,19);    drawLine(19,20);
        drawLine(20,12);   drawLine(21,22);   drawLine(22,23);
        drawLine(23,24);   drawLine(24,25);   drawLine(25,26);
        drawLine(26,21);   drawLine(22,27);   drawLine(27,28);
        drawLine(28,29);   drawLine(29,30);   drawLine(30,21);
        drawLine(31,32);   drawLine(32,33);   drawLine(33,34);
        drawLine(34,35);   drawLine(35,36);   drawLine(36,31);
        drawLine(26,36);   drawLine(30,31);   drawLine(25,38);
        drawLine(38,37);   drawLine(37,35);   drawLine(29,39);
        drawLine(39,40);   drawLine(40,32);   drawLine(41,42);
        drawLine(43,44);   drawLine(45,46);   drawLine(47,48);
        drawLine(49,50);   drawLine(51,52);   drawLine(53,54);
        drawLine(55,56);   drawLine(57,58);   drawLine(59,60);
        drawLine(42,43);   drawLine(44,17);   drawLine(44,45);
        drawLine(45,14);   drawLine(47,13);   drawLine(49,20);
        drawLine(50,51);   drawLine(52,53);   drawLine(54,55);
        drawLine(56,58);   drawLine(57,59);   drawLine(46,48);
        drawLine(47,49);   drawLine(18,41);   drawLine(4,60);
        drawLine(60,41);   drawLine(59,40);   drawLine(42,39);
        drawLine(51,38);   drawLine(53,8);    drawLine(37,54);
        drawLine(43,28);   drawLine(46,27);   drawLine(50,24);
        drawLine(3,58);    drawLine(34,55);   drawLine(56,7);
        drawLine(57,33);   drawLine(23,48);   drawLine(19,52);

        g.drawImage (buffer,0,0,this);

        // Verzögerung
        try {Thread.sleep(20);}
        catch (InterruptedException e) {}

        for (int i=1;i<61;i++) {

            px = p[i][x];
            py = p[i][y];
            pz = p[i][z];

            // Rotation um x-Achse
            p[i][y] = py*Math.cos(ax)-pz*Math.sin(ax);
            p[i][z] = py*Math.sin(ax)+pz*Math.cos(ax);

            py = p[i][y];
            pz = p[i][z];

            // Rotation um y-Achse
            p[i][x] = px*Math.cos(ay)+pz*Math.sin(ay);
            p[i][z] =-px*Math.sin(ay)+pz*Math.cos(ay);

            px = p[i][x];

            // Rotation um z-Achse
            p[i][x] = px*Math.cos(az)-py*Math.sin(az);
            p[i][y] = py*Math.cos(az)+px*Math.sin(az);
        }

        repaint();
    }

    public void update(Graphics g) {paint(g);}

    public void drawLine(int i, int j) {
        gBuffer.drawLine(
            (int)(p[i][x])+200,(int)(p[i][y])+200,
            (int)(p[j][x])+200,(int)(p[j][y])+200);
    }
}


Download  Fussball.zip (Applet und Code, ca. 5 kb)




© 2001-2004 Albert Kluge - Alle Rechte vorbehalten
Impressum | Datenschutz | Nutzung | eMail