Import java. AWT .*;
Import java. Applet .*;
Public class wuerfel extends applet {
// 8 eckpunkte 1-8
// Mit Je 3 koordinaten 1, 2, 3
Double P [] [] = new double [9] [4];
Int x = 1, y = 2, Z = 3;
Public void Init (){
Setbackground (new color (255,255,255 ));
// Construct the image
P [1] [x] =-100; P [1] [Y] =-100; P [1] [Z] =-100;
P [2] [x] = + 100; P [2] [Y] =-100; P [2] [Z] =-100;
P [3] [x] = + 100; P [3] [Y] =-100; P [3] [Z] = + 100;
P [4] [x] =-100; P [4] [Y] =-100; P [4] [Z] = + 100;
P [5] [x] =-100; P [5] [Y] = + 100; P [5] [Z] =-100;
P [6] [x] = + 100; P [6] [Y] = + 100; P [6] [Z] =-100;
P [7] [x] = + 100; P [7] [Y] = + 100; P [7] [Z] = + 100;
P [8] [x] =-100; P [8] [Y] = + 100; P [8] [Z] = + 100;
// 8--7
/// |/|
// 5---6 |
// |
// | 4--|-3
// |/
// 1---2
}
// Rotationswinkel In Rad
Double angle_x = 0.01;
Double angle_y = 0.0075;
Double angle_z= 0.005;
Image Buffer;
Graphics2d gbuffer;
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 );
Gbuffer. drawline (INT) (p [1] [x]) + 200, (INT) (p [1] [Y]) + 200, (INT) (P [2] [x]) + 200, (INT) (p [2] [Y]) + 200 );
Gbuffer. drawline (INT) (p [2] [x]) + 200, (INT) (p [2] [Y]) + 200, (INT) (P [3] [x]) + 200, (INT) (p [3] [Y]) + 200 );
Gbuffer. drawline (INT) (p [3] [x]) + 200, (INT) (p [3] [Y]) + 200, (INT) (P [4] [x]) + 200, (INT) (p [4] [Y]) + 200 );
Gbuffer. drawline (INT) (p [4] [x]) + 200, (INT) (p [4] [Y]) + 200, (INT) (P [1] [x]) + 200, (INT) (p [1] [Y]) + 200 );
Gbuffer. drawline (INT) (p [5] [x]) + 200, (INT) (p [5] [Y]) + 200, (INT) (P [6] [x]) + 200, (INT) (p [6] [Y]) + 200 );
Gbuffer. drawline (INT) (p [6] [x]) + 200, (INT) (p [6] [Y]) + 200, (INT) (P [7] [x]) + 200, (INT) (p [7] [Y]) + 200 );
Gbuffer. drawline (INT) (p [7] [x]) + 200, (INT) (p [7] [Y]) + 200, (INT) (P [8] [x]) + 200, (INT) (p [8] [Y]) + 200 );
Gbuffer. drawline (INT) (p [8] [x]) + 200, (INT) (p [8] [Y]) + 200, (INT) (P [5] [x]) + 200, (INT) (p [5] [Y]) + 200 );
Gbuffer. drawline (INT) (p [1] [x]) + 200, (INT) (p [1] [Y]) + 200, (INT) (P [5] [x]) + 200, (INT) (p [5] [Y]) + 200 );
Gbuffer. drawline (INT) (p [2] [x]) + 200, (INT) (p [2] [Y]) + 200, (INT) (P [6] [x]) + 200, (INT) (p [6] [Y]) + 200 );
Gbuffer. drawline (INT) (p [3] [x]) + 200, (INT) (p [3] [Y]) + 200, (INT) (P [7] [x]) + 200, (INT) (p [7] [Y]) + 200 );
Gbuffer. drawline (INT) (p [4] [x]) + 200, (INT) (p [4] [Y]) + 200, (INT) (P [8] [x]) + 200, (INT) (p [8] [Y]) + 200 );
G. drawimage (buffer, 0, 0, this );
// Thread
Try {thread. Sleep (10 );}
Catch (interruptedexception e ){}
Double PX, Py, PZ;
For (INT I = 1; I <9; I ++ ){
Px = P [I] [x];
Py = P [I] [Y];
PZ = P [I] [Z];
// Rotation um x-achse
P [I] [Y] = py * Math. Cos (angle_x)-PZ * Math. Sin (angle_x );
P [I] [Z] = py * Math. Sin (angle_x) + PZ * Math. Cos (angle_x );
Py = P [I] [Y];
PZ = P [I] [Z];
// Rotation um y-achse
P [I] [x] = px * Math. Cos (angle_y) + PZ * Math. Sin (angle_y );
P [I] [Z] =-Px * Math. Sin (angle_y) + PZ * Math. Cos (angle_y );
Px = P [I] [x];
// Rotation um Z-achse
P [I] [x] = px * Math. Cos (angle_z)-py * Math. Sin (angle_z );
P [I] [Y] = py * Math. Cos (angle_z) + px * Math. Sin (angle_z );
}
Repaint ();
}
Public void Update (Graphics g) {paint (g );}
}