Skip to content

Instantly share code, notes, and snippets.

@zakki
Created December 11, 2014 09:11
Show Gist options
  • Select an option

  • Save zakki/894e2b13a61033c6ae27 to your computer and use it in GitHub Desktop.

Select an option

Save zakki/894e2b13a61033c6ae27 to your computer and use it in GitHub Desktop.
import javafx.application.Application;
import javafx.scene.AmbientLight;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;
public class Text3D extends Application {
@Override
public void start(Stage stage) {
PhongMaterial material = new PhongMaterial();
material.setDiffuseColor(Color.LIGHTGRAY);
material.setSpecularColor(Color.rgb(30, 30, 30));
Group root = new Group();
Box box = new Box(200, 200, 200);
box.setMaterial(material);
box.setTranslateX(0);
box.setTranslateY(0);
box.setTranslateZ(0);
box.setDrawMode(DrawMode.FILL);
box.setCullFace(CullFace.BACK);
root.getChildren().add(box);
PointLight pointLight = new PointLight(Color.ANTIQUEWHITE);
pointLight.setTranslateX(800);
pointLight.setTranslateY(-100);
pointLight.setTranslateZ(-1000);
root.getChildren().add(pointLight);
root.getChildren().add(new AmbientLight(Color.DARKGRAY));
// for (int i = 0; i < 360; i += 10) {
// Text text = new Text("X " + i);
// text.setFont(Font.font(100));
// text.setFill(Color.LIGHTBLUE);
// text.getTransforms().addAll(
// new Rotate(i, Rotate.X_AXIS),
// new Translate(0, 600, 0));
// root.getChildren().add(text);
// }
for (int i = 0; i < 360; i += 10) {
Text text = new Text("Y " + i);
text.setFont(Font.font(100));
text.setFill(Color.LIGHTGREEN);
text.getTransforms().addAll(
new Rotate(i, Rotate.Y_AXIS),
new Translate(600, 0, 0));
root.getChildren().add(text);
}
Scene scene = new Scene(root, 800, 800, true);
scene.setFill(Color.rgb(10, 10, 40));
PerspectiveCamera camera = new PerspectiveCamera(false);
camera.getTransforms().addAll(
new Translate(-400, -400, 0),
new Rotate(40, Rotate.Y_AXIS),
new Rotate(-30, Rotate.X_AXIS),
new Translate(0, 0, -3000)
);
scene.setCamera(camera);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment