如何在JavaFX中创建Sphere(3D)?
现场演示
->
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);
}
}输出结果
热门推荐
10 饭桌祝福语长辈文案简短
11 周六早晨祝福语简短
12 春节初二祝福语简短
13 女儿生日简短祝福语幽默
14 情侣结婚的祝福语简短
15 高考加油祝福语简短押韵
16 祝福语男性朋友简短大方
17 送同学的简短祝福语
18 元旦祝福语同学简短创意