-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstroke_2d.rs
More file actions
66 lines (52 loc) · 1.74 KB
/
stroke_2d.rs
File metadata and controls
66 lines (52 loc) · 1.74 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
use processing_glfw::GlfwContext;
use processing::prelude::*;
use processing_render::render::command::DrawCommand;
fn main() {
sketch().unwrap();
exit(0).unwrap();
}
fn sketch() -> error::Result<()> {
let mut glfw_ctx = GlfwContext::new(600, 300)?;
init(Config::default())?;
let surface = glfw_ctx.create_surface(600, 300)?;
let graphics = graphics_create(surface, 600, 300, TextureFormat::Rgba16Float)?;
let joins = [
StrokeJoinMode::Round,
StrokeJoinMode::Miter,
StrokeJoinMode::Bevel,
];
while glfw_ctx.poll_events() {
graphics_begin_draw(graphics)?;
graphics_record_command(
graphics,
DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.15, 0.15, 0.2)),
)?;
graphics_record_command(graphics, DrawCommand::StrokeWeight(12.0))?;
for (i, &join) in joins.iter().enumerate() {
let x = 30.0 + i as f32 * 190.0;
let y = 50.0;
graphics_record_command(graphics, DrawCommand::StrokeJoin(join))?;
let hue = i as f32 * 0.3;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgb(0.3 + hue, 0.5, 0.8 - hue)),
)?;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgb(1.0, 0.9, 0.3)),
)?;
graphics_record_command(
graphics,
DrawCommand::Rect {
x,
y,
w: 150.0,
h: 180.0,
radii: [0.0; 4],
},
)?;
}
graphics_end_draw(graphics)?;
}
Ok(())
}