📅  最后修改于: 2020-10-14 01:43:58             🧑  作者: Mango
这样,该节点从远处的光源变亮。远光源是一种与物体保持一定距离的光源,并且光从光源到物体在一个方向上衰减。在JavaFX中,类javafx.scene.effect.Light.Distant表示Distant光源。我们需要实例化此类以在节点上生成适当的光。
该类包含下表中描述的两个属性。
Property | Description | Setter Methods |
---|---|---|
azimuth | This property is of the type double and it represents the Azimuth of the light. | setAzimuth(double value) |
elevation | This property is of double type and it represents the elevation of the light. | setAlivation(double value) |
该类包含两个构造函数
package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Light;
import javafx.scene.effect.Lighting;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class LightingExample1 extends Application {
@Override
public void start(Stage stage) {
Text text = new Text();
text.setFont(Font.font(null, FontWeight.BOLD, 35));
text.setX(60);
text.setY(100);
text.setText("Welcome to JavaTpoint");
text.setFill(Color.GREEN);
Image img = new Image("https://www.javatpoint.com/operating-system/images/operating-system-tutorial.png");
ImageView imgview = new ImageView(img);
imgview.setX(150);
imgview.setY(200);
Light.Distant light = new Light.Distant();
light.setAzimuth(0.2);
light.setColor(Color.YELLOW);
Lighting lighting = new Lighting();
lighting.setLight(light);
text.setEffect(lighting);
imgview.setEffect(lighting);
Group root = new Group(text,imgview);
Scene scene = new Scene(root, 580, 420);
stage.setTitle("light.Distant example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}