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