TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
- /*
- <applet code="Wuerfel.class" width="400",height="400"></applet>
- */
- 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));
- //构造图形
- 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);
- //线程
- 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);}
- }
复制代码
源码下载:http://file.javaxxz.com/2014/10/1/210746516.zip |
|