Object samples
This commit is contained in:
parent
073292b9de
commit
196d387c1f
|
|
@ -1,3 +1,4 @@
|
|||
use std::f32::consts::PI;
|
||||
use flo_draw::*;
|
||||
use flo_canvas::*;
|
||||
use glam::*;
|
||||
|
|
@ -10,6 +11,17 @@ use approx::assert_abs_diff_eq;
|
|||
|
||||
const DT: f32 = 0.1;
|
||||
|
||||
fn draw_loop(gc: &mut Vec<Draw>, mut pts: impl Iterator<Item=Vec2>) {
|
||||
gc.new_path();
|
||||
let Some(first) = pts.next() else { return; };
|
||||
gc.move_to(first.x, first.y);
|
||||
for pt in pts {
|
||||
gc.line_to(pt.x, pt.y);
|
||||
}
|
||||
gc.close_path();
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
with_2d_graphics(move || {
|
||||
let canvas = create_drawing_window("Refraction");
|
||||
|
|
@ -30,13 +42,36 @@ pub fn main() {
|
|||
draw_fan(gc, &tube, vec2(-500.0, 0.0), vec2(1.0, 0.0), 1.0);
|
||||
gc.stroke_color(Color::Rgba(1.0, 0.5, 0.0, 1.0));
|
||||
draw_fan_2(gc, &space, vec2(-500.0, 0.0), vec2(1.0, 0.0), 1.0);
|
||||
gc.stroke_color(Color::Rgba(0.0, 0.5, 1.0, 0.5));
|
||||
draw_fan(gc, &tube, vec2(0.0, -0.5 * tube.internal_halflength), vec2(1.0, 1.0), 1.0);
|
||||
gc.stroke_color(Color::Rgba(0.0, 0.5, 1.0, 1.0));
|
||||
draw_fan_2(gc, &space, vec2(0.0, -0.5 * tube.internal_halflength), vec2(1.0, 1.0), 1.0);
|
||||
draw_track(gc, &space, vec2(-500.0, 0.0), vec2(1.0, 0.2));
|
||||
draw_track(gc, &space, vec2(-500.0, 0.0), vec2(1.0, 0.5));
|
||||
draw_track(gc, &space, vec2(-0.5 * tube.inner_radius, -1.25 * tube.external_halflength), vec2(0.1, 1.0));
|
||||
|
||||
for y in [-1.25, -1.00, -0.85, -0.50, 0.00, 0.40, 0.70, 0.95, 1.05] {
|
||||
let pos = vec2(0.0, y * tube.external_halflength);
|
||||
gc.new_path();
|
||||
gc.circle(pos.x, pos.y, 5.0);
|
||||
gc.fill_color(Color::Rgba(0.0, 0.5, 1.0, 1.0));
|
||||
gc.fill();
|
||||
|
||||
gc.stroke_color(Color::Rgba(0.0, 0.0, 0.0, 0.5));
|
||||
draw_loop(gc, itertools_num::linspace(0.0, 2.0 * PI, 32).skip(1).map(|φ| {
|
||||
let dir = Vec2::from_angle(φ) * 20.0;
|
||||
let dir = space.flat_to_global(pos, dir);
|
||||
pos + dir
|
||||
}));
|
||||
gc.stroke_color(Color::Rgba(0.0, 0.5, 1.0, 0.5));
|
||||
draw_loop(gc, itertools_num::linspace(0.0, 2.0 * PI, 32).skip(1).map(|φ| {
|
||||
let dir = Vec2::from_angle(φ) * 20.0;
|
||||
let dir = space.flat_to_global(pos, dir);
|
||||
space.trace_step(Ray { pos, dir }).pos
|
||||
}));
|
||||
gc.stroke_color(Color::Rgba(0.5, 0.0, 1.0, 1.0));
|
||||
draw_loop(gc, itertools_num::linspace(0.0, 2.0 * PI, 32).skip(1).map(|φ| {
|
||||
let dir = Vec2::from_angle(φ);
|
||||
let dir = space.flat_to_global(pos, dir);
|
||||
space.trace_iter(Ray { pos, dir }).nth(20).unwrap().pos
|
||||
}));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user