📜  JavaFX Light.Distant效果

📅  最后修改于: 2020-10-14 01:43:58             🧑  作者: Mango

JavaFX Light.Distant效果

这样,该节点从远处的光源变亮。远光源是一种与物体保持一定距离的光源,并且光从光源到物体在一个方向上衰减。在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)

建设者

该类包含两个构造函数

  • public Light.Distant():使用默认参数创建类的新实例。
  • public Light.Distant(双方位角,双标高,彩色):使用指定的参数创建类的新实例。

例:

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); 
} 
}