diff --git a/src/main.rs b/src/main.rs index d55ce2b..a966c90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ +use core::f32; + use macroquad::prelude::*; #[macroquad::main("InputKeys")] async fn main() { + // sin wave let mut freq = 0.1; let mut amp = 50.0; let freq_mod = 0.001; @@ -10,17 +13,45 @@ async fn main() { let mut x_offset = 0.0; let x_mod = 5.0; - loop { - clear_background(LIGHTGRAY); + // selection box + let mut inital_x_pos = 0.; + let mut inital_y_pos = 0.; + let mut show_debug = false; + + loop { + clear_background(BLACK); + if show_debug { + draw_text(&format!("Amplitude: {}, Freqency {}, X Offset {}", amp, freq, x_offset), 20.0, 40.0, 20.0, WHITE); + draw_text(&format!("Cursor {:?}, Last Click {:?}", mouse_position(), (inital_x_pos, inital_y_pos)), 20.0, 60.0, 20.0, WHITE); + } + + // toggle debug box + if is_key_pressed(KeyCode::LeftControl) { + show_debug = !show_debug; + } + + // selection box + if is_mouse_button_pressed(MouseButton::Left) { + (inital_x_pos, inital_y_pos) = mouse_position(); + } + if is_mouse_button_down(MouseButton::Left) { + + let (x, y) = mouse_position(); + let width = x - inital_x_pos; + let height = y - inital_y_pos; + + draw_rectangle(inital_x_pos, inital_y_pos, width, height, Color { r: 0.2, g: 0.1, b: 1., a: 0.5 }); + } + + // sin wave for x in 0..(screen_width() as i32) { let x = x as f32; let y = f32::sin(x * freq + x_offset)*amp + y_offset; - draw_circle(x, y, 5.0, YELLOW); + draw_circle(x, y, 3.0, GREEN); } - if is_key_down(KeyCode::PageUp) { freq += freq_mod; } @@ -40,7 +71,6 @@ async fn main() { x_offset -= x_mod; } - draw_text(&format!("Amplitude: {}, Freqency {}, X Offset {}", amp, freq, x_offset), 20.0, 40.0, 20.0, DARKGRAY); next_frame().await } }