7 Adding a Lighting Effect

转自:http://docs.oracle.com/javafx/2/visual_effects/lighting.htm#BCGJFEBI

The lighting effect simulates(模拟) a light source shining on the given content, which can be used to give flat objects a more realistic(实际) three-dimensional appearance.

Figure 7-1 shows the lighting effect on text.

Example 7-1 shows how to create a lighting effect on text.

package visualEffects;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.VPos;
import javafx.scene.effect.Light.Distant;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.shape.*;
import javafx.scene.effect.*;
import javafx.scene.paint.*;
import javafx.scene.text.*;

public class TestLighting extends Application {
	Stage stage;
	Scene scene;

	@Override
	public void start(Stage stage) {
		stage.show();

		scene = new Scene(new Group());
		ObservableList<Node> content = ((Group) scene.getRoot()).getChildren();

		content.add(lighting());
		stage.setScene(scene);
	}

	static Node lighting() {
		Distant light = new Distant();
		light.setAzimuth(-135.0f);

		Lighting l = new Lighting();
		l.setLight(light);
		l.setSurfaceScale(5.0f);

		Text t = new Text();
		t.setText("JavaFX" + "\n" + "Lighting!");
		t.setFill(Color.RED);
		t.setFont(Font.font("null", FontWeight.BOLD, 70));
		t.setX(10.0f);
		t.setY(10.0f);
		t.setTextOrigin(VPos.TOP);

		t.setEffect(l);

		t.setTranslateX(0);
		t.setTranslateY(320);

		return t;
	}

	public static void main(String[] args) {
		Application.launch(args);
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值