1use miniquad::*;
2use quad_gl::*;
3
4struct Stage {
5 gl: QuadGl,
6}
7
8fn rect(gl: &mut QuadGl, w: f32, h: f32) {
9 gl.geometry(
10 &[
11 Vertex::new(-w / 2., h, 0., 0., 0., RED),
12 Vertex::new(w / 2., h, 0., 0., 0., RED),
13 Vertex::new(-w / 2., 0., 0., 0., 0., RED),
14 Vertex::new(w / 2., 0., 0., 0., 0., RED),
15 ],
16 &[0, 1, 2, 1, 2, 3],
17 );
18}
19
20fn tree(gl: &mut QuadGl, time: f64, deep: u32, angle: f32, tall: f32) {
21 if deep >= 8 {
22 return;
23 }
24
25 rect(gl, 0.01, tall);
27
28 gl.push_model_matrix(glam::Mat4::from_translation(glam::vec3(0., tall, 0.)));
29
30 gl.push_model_matrix(glam::Mat4::from_rotation_z(angle + time.sin() as f32 * 0.1));
32 tree(gl, time, deep + 1, angle * 0.7, tall * 0.8);
33 gl.pop_model_matrix();
34
35 gl.push_model_matrix(glam::Mat4::from_rotation_z(
37 -angle - time.cos() as f32 * 0.1,
38 ));
39 tree(gl, time, deep + 1, angle * 0.7, tall * 0.8);
40 gl.pop_model_matrix();
41
42 gl.pop_model_matrix();
43}
44impl EventHandler for Stage {
45 fn update(&mut self, _ctx: &mut Context) {}
46
47 fn draw(&mut self, ctx: &mut Context) {
48 ctx.clear(Some((0., 1., 0., 1.)), None, None);
49
50 self.gl
51 .push_model_matrix(glam::Mat4::from_translation(glam::vec3(0., -0.5, 0.)));
52 tree(&mut self.gl, miniquad::date::now(), 0, 1., 0.3);
53 self.gl.pop_model_matrix();
54
55 self.gl.draw(ctx);
56 }
57}
58
59fn main() {
60 miniquad::start(conf::Conf::default(), |mut ctx| {
61 UserData::owning(
62 Stage {
63 gl: QuadGl::new(&mut ctx),
64 },
65 ctx,
66 )
67 });
68}