Issue
I'm new in JavaFX and I'am trying to make solar system. Now, I want to make sun like this I've tried:
Glow g = new Glow(100);
sphere.setEffect(g);
But it doesn't work. Any solutions? Thanks.
Solution
Source
import javafx.application.Application;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage stage)
{
// Create a rectangle
Rectangle rect = new Rectangle(75, 75);
rect.setTranslateX(300);
rect.setTranslateY(-5);
rect.setTranslateZ(400);
// Load an image
rect.setFill(new ImagePattern(new Image("file:spark2.png")));
// Create a Camera to view the 3D Shapes
PerspectiveCamera camera = new PerspectiveCamera(false);
camera.setTranslateX(100);
camera.setTranslateY(-50);
camera.setTranslateZ(300);
// Add the Shapes and the Light to the Group
AnchorPane root = new AnchorPane(rect);
// Create a Scene with depth buffer enabled
Scene scene = new Scene(root, 800, 800, true);
// Fill the background with black
scene.setFill(Color.BLACK);
// Add the Camera to the Scene
scene.setCamera(camera);
// Add the Scene to the Stage
stage.setScene(scene);
// Set the Title of the Stage
stage.setTitle("An Example");
// Display the Stage
stage.show();
}
}
Output:
The sparkle image:
Answered By - Snix