-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstroke_3d.rs
More file actions
143 lines (120 loc) · 4.61 KB
/
Copy pathstroke_3d.rs
File metadata and controls
143 lines (120 loc) · 4.61 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use processing_glfw::GlfwContext;
use bevy::math::{Vec2, Vec3};
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, 400)?;
init(Config::default())?;
let surface = glfw_ctx.create_surface(600, 400)?;
let graphics = graphics_create(surface, 600, 400, TextureFormat::Rgba16Float)?;
graphics_mode_3d(graphics)?;
transform_set_position(graphics, Vec3::new(200.0, 150.0, 350.0))?;
transform_look_at(graphics, Vec3::new(0.0, 0.0, 0.0))?;
let _light =
light_create_directional(graphics, bevy::color::Color::srgb(0.9, 0.85, 0.8), 800.0)?;
let mut angle: f32 = 0.0;
while glfw_ctx.poll_events() {
graphics_begin_draw(graphics)?;
graphics_record_command(
graphics,
DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.08, 0.08, 0.12)),
)?;
// thin wireframe box
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
graphics_record_command(graphics, DrawCommand::Translate(Vec2::new(-80.0, 0.0)))?;
graphics_record_command(graphics, DrawCommand::Rotate { angle })?;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgb(0.3, 0.4, 0.7)),
)?;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgb(1.0, 1.0, 1.0)),
)?;
graphics_record_command(graphics, DrawCommand::StrokeWeight(1.0))?;
graphics_record_command(
graphics,
DrawCommand::Box {
width: 60.0,
height: 60.0,
depth: 60.0,
},
)?;
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
// thick wireframe box
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
graphics_record_command(graphics, DrawCommand::Translate(Vec2::ZERO))?;
graphics_record_command(graphics, DrawCommand::Rotate { angle: angle * 0.7 })?;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgb(0.7, 0.3, 0.4)),
)?;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgb(1.0, 0.9, 0.2)),
)?;
graphics_record_command(graphics, DrawCommand::StrokeWeight(3.0))?;
graphics_record_command(
graphics,
DrawCommand::Box {
width: 50.0,
height: 70.0,
depth: 50.0,
},
)?;
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
// thick wireframe sphere
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
graphics_record_command(graphics, DrawCommand::Translate(Vec2::new(80.0, 0.0)))?;
graphics_record_command(graphics, DrawCommand::Rotate { angle: angle * 0.5 })?;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgb(0.3, 0.7, 0.4)),
)?;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgb(0.9, 0.4, 1.0)),
)?;
graphics_record_command(graphics, DrawCommand::StrokeWeight(2.0))?;
graphics_record_command(
graphics,
DrawCommand::Sphere {
radius: 35.0,
sectors: 16,
stacks: 12,
},
)?;
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
// wireframe-only sphere (no fill)
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
graphics_record_command(graphics, DrawCommand::Translate(Vec2::new(160.0, 0.0)))?;
graphics_record_command(
graphics,
DrawCommand::Rotate {
angle: -angle * 0.3,
},
)?;
graphics_record_command(graphics, DrawCommand::NoFill)?;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgb(0.2, 0.8, 1.0)),
)?;
graphics_record_command(graphics, DrawCommand::StrokeWeight(1.5))?;
graphics_record_command(
graphics,
DrawCommand::Sphere {
radius: 30.0,
sectors: 24,
stacks: 16,
},
)?;
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
graphics_end_draw(graphics)?;
angle += 0.015;
}
Ok(())
}