Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import javafx.animation.AnimationTimer;
  2. import javafx.scene.*; import javafx.scene.canvas.*;
  3. public class cube extends javafx.application.Application {
  4.   GraphicsContext gc; private void poly(String c, double... a) {
  5.     gc.setFill(javafx.scene.paint.Color.web("#"+c));
  6.     gc.fillPolygon(a, new double[] {a[4],a[5],a[6],a[7]},4); }
  7.   public void start(javafx.stage.Stage stage) {
  8.     Group root = new Group(); Canvas canvas = new Canvas(320, 240);
  9.     gc = canvas.getGraphicsContext2D(); root.getChildren().add(canvas);
  10.     stage.setScene(new Scene(root)); stage.show();
  11.     AnimationTimer timer = new AnimationTimer() {
  12.       public void handle(long time) {
  13.         gc.clearRect(0,0,320,240);
  14.         double x[]={0,0,0,0}, y[]={0,0,0,0}, y2[]={0,0,0,0};
  15.         for(int i=0;i<4;i++)
  16.         { x[i]=160+120*Math.cos(time/10e6*Math.PI/180+i*Math.PI/2);
  17.           y[i]=60+30*Math.sin(time/10e6*Math.PI/180+i*Math.PI/2);}
  18.         poly("808",x[0],x[1],x[1],x[0],y[0],y[1],120+y[1],120+y[0]);
  19.         poly("808",x[2],x[3],x[3],x[2],y[2],y[3],120+y[3],120+y[2]);
  20.         poly("808",x[3],x[0],x[0],x[3],y[3],y[0],120+y[0],120+y[3]);
  21.         poly("808",x[1],x[2],x[2],x[1],y[1],y[2],120+y[2],120+y[1]);
  22.         poly("93C",x[0],x[1],x[2],x[3],y[0],y[1], y[2], y[3]);
  23.       } }; timer.start(); } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement