 de004da8d5
			
		
	
	
		de004da8d5
		
			
		
	
	
	
	
		
			
			# Objective The migration process for `bevy_color` (#12013) will be fairly involved: there will be hundreds of affected files, and a large number of APIs. ## Solution To allow us to proceed granularly, we're going to keep both `bevy_color::Color` (new) and `bevy_render::Color` (old) around until the migration is complete. However, simply doing this directly is confusing! They're both called `Color`, making it very hard to tell when a portion of the code has been ported. As discussed in #12056, by renaming the old `Color` type, we can make it easier to gradually migrate over, one API at a time. ## Migration Guide THIS MIGRATION GUIDE INTENTIONALLY LEFT BLANK. This change should not be shipped to end users: delete this section in the final migration guide! --------- Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //! Shows how to render simple primitive shapes with a single color.
 | |
| 
 | |
| use bevy::{
 | |
|     prelude::*,
 | |
|     sprite::{MaterialMesh2dBundle, Mesh2dHandle},
 | |
| };
 | |
| 
 | |
| fn main() {
 | |
|     App::new()
 | |
|         .add_plugins(DefaultPlugins)
 | |
|         .add_systems(Startup, setup)
 | |
|         .run();
 | |
| }
 | |
| 
 | |
| const X_EXTENT: f32 = 600.;
 | |
| 
 | |
| fn setup(
 | |
|     mut commands: Commands,
 | |
|     mut meshes: ResMut<Assets<Mesh>>,
 | |
|     mut materials: ResMut<Assets<ColorMaterial>>,
 | |
| ) {
 | |
|     commands.spawn(Camera2dBundle::default());
 | |
| 
 | |
|     let shapes = [
 | |
|         Mesh2dHandle(meshes.add(Circle { radius: 50.0 })),
 | |
|         Mesh2dHandle(meshes.add(Ellipse::new(25.0, 50.0))),
 | |
|         Mesh2dHandle(meshes.add(Capsule2d::new(25.0, 50.0))),
 | |
|         Mesh2dHandle(meshes.add(Rectangle::new(50.0, 100.0))),
 | |
|         Mesh2dHandle(meshes.add(RegularPolygon::new(50.0, 6))),
 | |
|         Mesh2dHandle(meshes.add(Triangle2d::new(
 | |
|             Vec2::Y * 50.0,
 | |
|             Vec2::new(-50.0, -50.0),
 | |
|             Vec2::new(50.0, -50.0),
 | |
|         ))),
 | |
|     ];
 | |
|     let num_shapes = shapes.len();
 | |
| 
 | |
|     for (i, shape) in shapes.into_iter().enumerate() {
 | |
|         // Distribute colors evenly across the rainbow.
 | |
|         let color = LegacyColor::hsl(360. * i as f32 / num_shapes as f32, 0.95, 0.7);
 | |
| 
 | |
|         commands.spawn(MaterialMesh2dBundle {
 | |
|             mesh: shape,
 | |
|             material: materials.add(color),
 | |
|             transform: Transform::from_xyz(
 | |
|                 // Distribute shapes from -X_EXTENT to +X_EXTENT.
 | |
|                 -X_EXTENT / 2. + i as f32 / (num_shapes - 1) as f32 * X_EXTENT,
 | |
|                 0.0,
 | |
|                 0.0,
 | |
|             ),
 | |
|             ..default()
 | |
|         });
 | |
|     }
 | |
| }
 |