-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtransforms.rs
More file actions
75 lines (59 loc) · 2.14 KB
/
transforms.rs
File metadata and controls
75 lines (59 loc) · 2.14 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use processing_glfw::GlfwContext;
use bevy::math::Vec2;
use processing::prelude::*;
use processing_render::render::command::DrawCommand;
use std::f32::consts::PI;
fn main() {
sketch().unwrap();
exit(0).unwrap();
}
fn sketch() -> error::Result<()> {
let mut glfw_ctx = GlfwContext::new(400, 400)?;
init(Config::default())?;
let surface = glfw_ctx.create_surface(400, 400)?;
let graphics = graphics_create(surface, 400, 400, TextureFormat::Rgba16Float)?;
let mut t: f32 = 0.0;
while glfw_ctx.poll_events() {
graphics_begin_draw(graphics)?;
graphics_record_command(
graphics,
DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.1, 0.1, 0.1)),
)?;
for i in 0..4 {
for j in 0..4 {
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
graphics_record_command(
graphics,
DrawCommand::Translate(Vec2::new(
50.0 + j as f32 * 100.0,
50.0 + i as f32 * 100.0,
)),
)?;
let angle = t + (i + j) as f32 * PI / 8.0;
graphics_record_command(graphics, DrawCommand::Rotate { angle })?;
let s = 0.8 + (t * 2.0 + (i * j) as f32).sin() * 0.2;
graphics_record_command(graphics, DrawCommand::Scale(Vec2::splat(s)))?;
let r = j as f32 / 3.0;
let g = i as f32 / 3.0;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgb(r, g, 0.8)),
)?;
graphics_record_command(
graphics,
DrawCommand::Rect {
x: -20.0,
y: -20.0,
w: 40.0,
h: 40.0,
radii: [0.0; 4],
},
)?;
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
}
}
graphics_end_draw(graphics)?;
t += 0.02;
}
Ok(())
}