forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacked_gradients.rs
More file actions
91 lines (87 loc) · 3.28 KB
/
stacked_gradients.rs
File metadata and controls
91 lines (87 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! An example demonstrating overlaid gradients
use bevy::color::palettes::css::BLUE;
use bevy::color::palettes::css::RED;
use bevy::color::palettes::css::YELLOW;
use bevy::prelude::*;
use core::f32::consts::TAU;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2d);
commands
.spawn(Node {
display: Display::Grid,
width: percent(100),
height: percent(100),
..Default::default()
})
.with_children(|commands| {
commands.spawn((
Node {
width: percent(100),
height: percent(100),
..Default::default()
},
BackgroundColor(Color::BLACK),
BackgroundGradient(vec![
LinearGradient::to_top_right(vec![
ColorStop::auto(RED),
ColorStop::auto(RED.with_alpha(0.)),
])
.into(),
LinearGradient::to_top_left(vec![
ColorStop::auto(BLUE),
ColorStop::auto(BLUE.with_alpha(0.)),
])
.into(),
ConicGradient {
start: 0.,
position: UiPosition::CENTER,
stops: vec![
AngularColorStop::auto(YELLOW.with_alpha(0.)),
AngularColorStop::auto(YELLOW.with_alpha(0.)),
AngularColorStop::auto(YELLOW),
AngularColorStop::auto(YELLOW.with_alpha(0.)),
AngularColorStop::auto(YELLOW.with_alpha(0.)),
],
..Default::default()
}
.into(),
RadialGradient {
position: UiPosition::TOP.at_x(percent(5)),
shape: RadialGradientShape::Circle(vh(30)),
stops: vec![
ColorStop::auto(Color::WHITE),
ColorStop::auto(YELLOW),
ColorStop::auto(YELLOW.with_alpha(0.1)),
ColorStop::auto(YELLOW.with_alpha(0.)),
],
..Default::default()
}
.into(),
LinearGradient {
angle: TAU / 16.,
stops: vec![
ColorStop::auto(Color::BLACK),
ColorStop::auto(Color::BLACK.with_alpha(0.)),
],
..Default::default()
}
.into(),
LinearGradient {
angle: 15. * TAU / 16.,
stops: vec![
ColorStop::auto(Color::BLACK),
ColorStop::auto(Color::BLACK.with_alpha(0.)),
],
..Default::default()
}
.into(),
]),
));
});
}