Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.25 KB

regular_polygons.md

File metadata and controls

42 lines (32 loc) · 1.25 KB

Regular Polygons

We can also add a regular polygon to our app.

use bevy::{
    app::{App, Startup},
    asset::Assets,
    core_pipeline::core_2d::Camera2dBundle,
    ecs::system::{Commands, ResMut},
    prelude::default,
    render::mesh::{shape::RegularPolygon, Mesh},
    sprite::ColorMesh2dBundle,
    DefaultPlugins,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
    commands.spawn(Camera2dBundle::default());

    commands.spawn(ColorMesh2dBundle {
        mesh: meshes.add(RegularPolygon::new(50., 5).into()).into(),
        ..default()
    });
}

The new function of RegularPolygon accepts two parameters, which are the radius and the number of sides of the RegularPolygon.

Result:

Regular Polygons

➡️ Next: Shapes With Transformation

📘 Back: Table of contents