The full code of the program is as follows:
use bevy::{
prelude::*,
window::WindowResolution,
};
const WIDTH: usize = 240;
const HEIGHT: usize = 240;
const ITERATIONS: usize = 50;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(WIDTH as f32, HEIGHT as f32),
title: String::from("Mandelbrot Set"),
..default()
}),
..default()
}))
.add_systems(Startup, (spawn_camera, spawn_visual, color_pixels_in_viewport).chain())
.run();
}
fn spawn_camera(mut cmds: Commands) {
cmds.spawn(Camera2dBundle::default());
}
#[derive(Resource, Deref, DerefMut)]
struct VisualTexture(Handle<Image>);
fn spawn_visual(mut cmds: Commands, asset_server: Res<AssetServer>) {
let tex = asset_server.load("base.png");
cmds.spawn(SpriteBundle {
texture: tex.clone(),
..default()
});
cmds.insert_resource(VisualTexture(tex));
}