-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathdraw_pattern.rs
53 lines (44 loc) · 1.07 KB
/
draw_pattern.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use notan::draw::*;
use notan::prelude::*;
#[derive(AppState)]
struct State {
img: Texture,
count: f32,
multi: f32,
}
impl State {
pub fn count(&mut self, value: f32) {
if self.count >= 200.0 || self.count <= 0.0 {
self.multi *= -1.0;
}
self.count += value * self.multi;
}
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(init)
.add_config(DrawConfig)
.update(|app: &mut App, state: &mut State| state.count(60.0 * app.timer.delta_f32()))
.draw(draw)
.build()
}
fn init(gfx: &mut Graphics) -> State {
let texture = gfx
.create_texture()
.from_image(include_bytes!("assets/pattern.png"))
.build()
.unwrap();
State {
img: texture,
count: 1.0,
multi: 1.0,
}
}
fn draw(gfx: &mut Graphics, state: &mut State) {
let mut draw = gfx.create_draw();
draw.clear(Color::BLACK);
draw.pattern(&state.img)
.size(800.0, 600.0)
.image_offset(-state.count, -state.count);
gfx.render(&draw);
}