2020-03-14 19:56:37 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2020-03-20 23:35:19 +00:00
|
|
|
App::build()
|
2020-04-04 19:40:32 +00:00
|
|
|
.add_default_plugins()
|
2020-05-14 00:31:56 +00:00
|
|
|
.add_startup_system(setup.system())
|
2020-05-04 06:49:45 +00:00
|
|
|
.add_system(placement_system.system())
|
2020-03-14 19:56:37 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-05-04 06:49:45 +00:00
|
|
|
fn placement_system(
|
2020-05-14 00:52:47 +00:00
|
|
|
time: Res<Time>,
|
|
|
|
materials: Res<Assets<ColorMaterial>>,
|
2020-07-10 04:18:35 +00:00
|
|
|
mut query: Query<(&mut Node, &Handle<ColorMaterial>)>,
|
2020-05-04 06:49:45 +00:00
|
|
|
) {
|
2020-07-22 03:12:15 +00:00
|
|
|
for (mut node, material_handle) in &mut query.iter() {
|
2020-06-27 19:06:12 +00:00
|
|
|
let material = materials.get(&material_handle).unwrap();
|
|
|
|
if material.color.r > 0.2 {
|
|
|
|
node.position += Vec2::new(0.1 * time.delta_seconds, 0.0);
|
|
|
|
}
|
2020-04-30 20:52:11 +00:00
|
|
|
}
|
2020-03-14 19:56:37 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 04:18:35 +00:00
|
|
|
fn setup(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
|
2020-07-20 00:00:08 +00:00
|
|
|
commands.spawn(Camera2dComponents::default());
|
2020-03-14 19:56:37 +00:00
|
|
|
|
|
|
|
let mut prev = Vec2::default();
|
|
|
|
let count = 1000;
|
|
|
|
for i in 0..count {
|
|
|
|
// 2d camera
|
2020-06-25 17:13:00 +00:00
|
|
|
let cur = Vec2::new(1.0, 1.0) + prev;
|
2020-07-18 21:08:46 +00:00
|
|
|
commands.spawn(NodeComponents {
|
2020-06-25 17:13:00 +00:00
|
|
|
node: Node {
|
|
|
|
position: Vec2::new(75.0, 75.0) + cur,
|
|
|
|
anchors: Anchors::new(0.5, 0.5, 0.5, 0.5),
|
|
|
|
margins: Margins::new(0.0, 100.0, 0.0, 100.0),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2020-05-04 18:06:02 +00:00
|
|
|
material: materials.add(Color::rgb(0.0 + i as f32 / count as f32, 0.1, 0.1).into()),
|
2020-05-03 00:56:30 +00:00
|
|
|
..Default::default()
|
2020-03-14 19:56:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
prev = cur;
|
|
|
|
}
|
|
|
|
}
|