-
Notifications
You must be signed in to change notification settings - Fork 66
/
colormaterial_color.rs
110 lines (101 loc) · 3.41 KB
/
colormaterial_color.rs
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use bevy::{
color::palettes::css::*,
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
use bevy_tweening::{lens::*, *};
use std::time::Duration;
mod utils;
fn main() {
App::default()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "ColorMaterialColorLens".to_string(),
resolution: (1200., 600.).into(),
present_mode: bevy::window::PresentMode::Fifo, // vsync
..default()
}),
..default()
}))
.add_systems(Update, utils::close_on_esc)
.add_plugins(TweeningPlugin)
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
let size = 80.;
let spacing = 1.25;
let screen_x = 450.;
let screen_y = 120.;
let mut x = -screen_x;
let mut y = screen_y;
let quad_mesh: Mesh2dHandle = meshes.add(Rectangle::new(1., 1.)).into();
for ease_function in &[
EaseFunction::QuadraticIn,
EaseFunction::QuadraticOut,
EaseFunction::QuadraticInOut,
EaseFunction::CubicIn,
EaseFunction::CubicOut,
EaseFunction::CubicInOut,
EaseFunction::QuarticIn,
EaseFunction::QuarticOut,
EaseFunction::QuarticInOut,
EaseFunction::QuinticIn,
EaseFunction::QuinticOut,
EaseFunction::QuinticInOut,
EaseFunction::SineIn,
EaseFunction::SineOut,
EaseFunction::SineInOut,
EaseFunction::CircularIn,
EaseFunction::CircularOut,
EaseFunction::CircularInOut,
EaseFunction::ExponentialIn,
EaseFunction::ExponentialOut,
EaseFunction::ExponentialInOut,
EaseFunction::ElasticIn,
EaseFunction::ElasticOut,
EaseFunction::ElasticInOut,
EaseFunction::BackIn,
EaseFunction::BackOut,
EaseFunction::BackInOut,
EaseFunction::BounceIn,
EaseFunction::BounceOut,
EaseFunction::BounceInOut,
] {
// Create a unique material per entity, so that it can be animated
// without affecting the other entities. Note that we could share
// that material among multiple entities, and animating the material
// asset would change the color of all entities using that material.
let unique_material = materials.add(Color::BLACK);
let tween = Tween::new(
*ease_function,
Duration::from_secs(1),
ColorMaterialColorLens {
start: RED.into(),
end: BLUE.into(),
},
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat);
commands.spawn((
MaterialMesh2dBundle {
mesh: quad_mesh.clone(),
transform: Transform::from_translation(Vec3::new(x, y, 0.))
.with_scale(Vec3::splat(size)),
material: unique_material,
..default()
},
AssetAnimator::new(tween),
));
y -= size * spacing;
if y < -screen_y {
x += size * spacing;
y = screen_y;
}
}
}