-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f23aec7
commit bbe949e
Showing
13 changed files
with
228 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
use nannou::prelude::*; | ||
use std::any::Any; | ||
|
||
fn main() { | ||
nannou::sketch(view).run() | ||
} | ||
|
||
fn view(app: &App) { | ||
// Begin drawing | ||
let draw = app.draw(); | ||
draw.background().color(WHITE); | ||
|
||
// Clear the background to blue. | ||
draw.background().color(CORNFLOWER_BLUE); | ||
|
||
// Draw a purple triangle in the top left half of the window. | ||
let win = app.window_rect(); | ||
let num_bars = 20; | ||
let bar_width = win.w() / num_bars as f32; | ||
|
||
for i in 0..num_bars { | ||
let x = map_range(i, 0, num_bars, win.left(), win.right()); | ||
let y = map_range(i, 0, num_bars, win.top(), win.bottom()); | ||
|
||
draw.rect() | ||
.x_y(x, y) | ||
.w_h(bar_width, win.h() / num_bars as f32) | ||
.color(BLACK); | ||
} | ||
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().elapsed_seconds(); | ||
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(PALE_GOLDENROD) | ||
.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(DARK_GREEN) | ||
.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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.