-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcurves.rs
More file actions
105 lines (88 loc) · 3.11 KB
/
curves.rs
File metadata and controls
105 lines (88 loc) · 3.11 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
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(800, 400)?;
init(Config::default())?;
let surface = glfw_ctx.create_surface(800, 400)?;
let graphics = graphics_create(surface, 800, 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.04, 0.04, 0.06)),
)?;
graphics_record_command(graphics, DrawCommand::NoFill)?;
graphics_record_command(graphics, DrawCommand::StrokeWeight(1.5))?;
for i in 0..20 {
let y_base = 20.0 + i as f32 * 15.0;
let phase = t + i as f32 * 0.3;
let amp = 30.0 + (i as f32 * 0.5).sin() * 20.0;
let v = 0.3 + (i as f32 / 20.0) * 0.5;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgb(v * 0.6, v, (v * 1.2).min(1.0))),
)?;
graphics_record_command(
graphics,
DrawCommand::Bezier {
x1: 0.0,
y1: y_base,
x2: 250.0,
y2: y_base + amp * phase.sin(),
x3: 550.0,
y3: y_base - amp * (phase * 1.3).cos(),
x4: 800.0,
y4: y_base,
},
)?;
}
graphics_record_command(graphics, DrawCommand::StrokeWeight(0.8))?;
for i in 0..8 {
let y_base = 50.0 + i as f32 * 40.0;
let phase = t * 0.7 + i as f32 * 0.5;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgba(1.0, 0.6, 0.2, 0.4)),
)?;
graphics_record_command(
graphics,
DrawCommand::Curve {
x1: -50.0,
y1: y_base + 40.0 * phase.sin(),
x2: 200.0,
y2: y_base + 30.0 * (phase * 1.2).cos(),
x3: 600.0,
y3: y_base - 30.0 * (phase * 0.8).sin(),
x4: 850.0,
y4: y_base + 20.0 * phase.cos(),
},
)?;
}
graphics_record_command(graphics, DrawCommand::StrokeWeight(0.3))?;
graphics_record_command(
graphics,
DrawCommand::StrokeColor(bevy::color::Color::srgba(1.0, 1.0, 1.0, 0.08)),
)?;
for i in 0..20 {
let y = 20.0 * i as f32;
graphics_record_command(
graphics,
DrawCommand::Line {
x1: 0.0,
y1: y,
x2: 800.0,
y2: y,
},
)?;
}
graphics_end_draw(graphics)?;
t += 0.012;
}
Ok(())
}