Add spin dog slide
This commit is contained in:
parent
48b2419a24
commit
8d67289ec0
BIN
cfg/img/dog.png
Normal file
BIN
cfg/img/dog.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 474 KiB |
@ -101,3 +101,6 @@ title = "Software as a Bit"
|
||||
type = "CreativeDemo"
|
||||
title = "Software as a Creative Outlet"
|
||||
|
||||
[[slides]]
|
||||
type = "SpinDog"
|
||||
dog = "dog.png"
|
||||
|
||||
@ -2,6 +2,7 @@ use crate::slide::Slide;
|
||||
use crate::slides::creative_demo::{CreativeDemo, CreativeDemoCfg};
|
||||
use crate::slides::demo::Demo;
|
||||
use crate::slides::projects::Projects;
|
||||
use crate::slides::spin_dog::{SpinDog, SpinDogCfg};
|
||||
use crate::slides::standard_slide::{StandardSlide, StandardSlideConfig};
|
||||
use crate::slides::title::Title;
|
||||
use config::Config;
|
||||
@ -16,6 +17,7 @@ pub enum SlideType {
|
||||
Projects,
|
||||
StandardSlide(StandardSlideConfig),
|
||||
CreativeDemo(CreativeDemoCfg),
|
||||
SpinDog(SpinDogCfg),
|
||||
}
|
||||
|
||||
impl SlideType {
|
||||
@ -26,6 +28,7 @@ impl SlideType {
|
||||
SlideType::Projects => Projects::new(),
|
||||
SlideType::StandardSlide(cfg) => StandardSlide::new(cfg, asset_dir).await,
|
||||
SlideType::CreativeDemo(cfg) => CreativeDemo::new(cfg),
|
||||
SlideType::SpinDog(cfg) => SpinDog::new(cfg, asset_dir).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,9 +4,7 @@ use crate::slide_show_config::Context;
|
||||
use crate::utils::{draw_text_with_background, screen_center};
|
||||
use macroquad::color::{BLACK, Color, ORANGE, VIOLET};
|
||||
use macroquad::math::Vec2;
|
||||
use macroquad::prelude::{
|
||||
BLUE, GREEN, RED, YELLOW, clear_background,
|
||||
};
|
||||
use macroquad::prelude::{BLUE, GREEN, RED, YELLOW, clear_background};
|
||||
use macroquad::time::get_time;
|
||||
use macroquad::window::{screen_height, screen_width};
|
||||
use serde::Deserialize;
|
||||
|
||||
@ -8,6 +8,7 @@ pub mod config;
|
||||
pub mod creative_demo;
|
||||
pub mod demo;
|
||||
pub mod projects;
|
||||
pub mod spin_dog;
|
||||
pub mod standard_slide;
|
||||
pub mod title;
|
||||
|
||||
|
||||
66
src/slides/spin_dog.rs
Normal file
66
src/slides/spin_dog.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use crate::effects::star_field;
|
||||
use crate::slide::Slide;
|
||||
use crate::slide_show_config::Context;
|
||||
use macroquad::camera::{Camera3D, set_camera, set_default_camera};
|
||||
use macroquad::color::BLACK;
|
||||
use macroquad::prelude::{
|
||||
Texture2D, WHITE, clear_background, draw_plane, draw_text, get_frame_time, get_time,
|
||||
load_texture, vec2, vec3,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct SpinDogCfg {
|
||||
dog: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SpinDog {
|
||||
texture: Texture2D,
|
||||
camera_angle: f32,
|
||||
}
|
||||
|
||||
impl SpinDog {
|
||||
pub async fn new(cfg: SpinDogCfg, asset_path: &Path) -> Box<Self> {
|
||||
let texture = load_texture(asset_path.join(cfg.dog).to_str().unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Box::new(Self {
|
||||
texture,
|
||||
camera_angle: 0.0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Slide for SpinDog {
|
||||
fn display(&mut self, _ctx: &Context<'_>) {
|
||||
clear_background(BLACK);
|
||||
star_field();
|
||||
|
||||
let camera_x = self.camera_angle.sin() * 20.0;
|
||||
let camera_y = self.camera_angle.cos() * 20.0;
|
||||
set_camera(&Camera3D {
|
||||
position: vec3(camera_x, camera_y, 0.0),
|
||||
up: vec3(0., 0.0, -1.0),
|
||||
target: vec3(0., 0., 0.),
|
||||
..Default::default()
|
||||
});
|
||||
draw_plane(vec3(0., 0., 0.), vec2(5.0, 5.0), Some(&self.texture), WHITE);
|
||||
|
||||
// Back to screen space, render some text
|
||||
let diff = 1.0 + get_time() as f32 * 0.1;
|
||||
let update = diff * get_frame_time();
|
||||
self.camera_angle = (self.camera_angle + update) % 360.0;
|
||||
|
||||
set_default_camera();
|
||||
draw_text(
|
||||
&format!("dog.png @ {diff:0.3} deg/s"),
|
||||
10.0,
|
||||
20.0,
|
||||
30.0,
|
||||
WHITE,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user