Animated ball
This commit is contained in:
+8
-16
@@ -9,23 +9,15 @@ fn view(app: &App) {
|
||||
|
||||
draw.background().color(PLUM);
|
||||
|
||||
draw.rect().color(STEEL_BLUE);
|
||||
|
||||
let points = (0..50).map(|i| {
|
||||
let x = i as f32 - 25.0;
|
||||
let point = pt2(x, x.sin()) * 20.0;
|
||||
(point, RED)
|
||||
});
|
||||
draw.polyline().weight(3.0).points_colored(points);
|
||||
let sine = (app.time()*3.0).sin();
|
||||
let slowersine = (app.time()).sin();
|
||||
|
||||
let radius = 160.0;
|
||||
let step = 45;
|
||||
let points = (0..=360).step_by(step).map(|i| {
|
||||
let radian = deg_to_rad(i as f32);
|
||||
let x = radian.cos() * radius;
|
||||
let y = radian.sin() * radius;
|
||||
(pt2(x, y), LIGHT_STEEL_BLUE)
|
||||
});
|
||||
let boundary = app.window_rect();
|
||||
|
||||
draw.polygon().points_colored(points).x_y(-100.0, -200.0);
|
||||
let x = map_range(sine, -1.0, 1.0, boundary.left(), boundary.right());
|
||||
let y = map_range(slowersine, -1.0, 1.0, boundary.bottom(), boundary.top());
|
||||
|
||||
|
||||
draw.ellipse().color(STEEL_BLUE).x_y(x, y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user