-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
draw.rs
48 lines (39 loc) · 1.28 KB
/
draw.rs
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
use nannou::prelude::*;
fn main() {
nannou::sketch(view).run()
}
fn view(app: &App, frame: Frame) {
// Begin drawing
let draw = app.draw();
// Clear the background to blue.
draw.background().color(CORNFLOWERBLUE);
// Draw a purple triangle in the top left half of the window.
let win = app.window_rect();
draw.tri()
.points(win.bottom_left(), win.top_left(), win.top_right())
.color(VIOLET);
// Draw an ellipse to follow the mouse.
let t = app.time;
draw.ellipse()
.x_y(app.mouse.x * t.cos(), app.mouse.y)
.radius(win.w() * 0.125 * t.sin())
.color(RED);
// Draw a line!
draw.line()
.weight(10.0 + (t.sin() * 0.5 + 0.5) * 90.0)
.caps_round()
.color(PALEGOLDENROD)
.points(win.top_left() * t.sin(), win.bottom_right() * t.cos());
// Draw a quad that follows the inverse of the ellipse.
draw.quad()
.x_y(-app.mouse.x, app.mouse.y)
.color(DARKGREEN)
.rotate(t);
// Draw a rect that follows a different inverse of the ellipse.
draw.rect()
.x_y(app.mouse.y, app.mouse.x)
.w(app.mouse.x * 0.25)
.hsv(t, 1.0, 1.0);
// Write the result of our drawing to the window's frame.
draw.to_frame(app, &frame).unwrap();
}