现场演示
->
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.stage.Stage;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.Sphere;
public class DrawingSphere extends Application {
public void start(Stage stage) {
//Drawing a sphere
Sphere sphere = new Sphere();
//Setting the properties of the Box(cube)
sphere.setRadius(140.0);
//Setting other properties
sphere.setCullFace(CullFace.BACK);
sphere.setDrawMode(DrawMode.FILL);
PhongMaterial material = new PhongMaterial();
material.setDiffuseColor(Color.BROWN);
sphere.setMaterial(material);
//Translating
sphere.setTranslateX(300.0);
sphere.setTranslateY(150.0);
sphere.setTranslateZ(150.0);
//Setting the perspective camera
PerspectiveCamera cam = new PerspectiveCamera();
cam.setTranslateX(-50);
cam.setTranslateY(25);
cam.setTranslateZ(0);
//Setting the Scene
Group root = new Group(sphere);
Scene scene = new Scene(root, 595, 300, Color.BEIGE);
scene.setCamera(cam);
stage.setTitle("Drawing A Sphere");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果