This commit is contained in:
Oliver Atkinson
2024-10-01 13:23:43 -06:00
commit c1d7da689a
5 changed files with 449 additions and 0 deletions

46
src/main.rs Normal file
View File

@@ -0,0 +1,46 @@
use macroquad::prelude::*;
#[macroquad::main("InputKeys")]
async fn main() {
let mut freq = 0.1;
let mut amp = 50.0;
let freq_mod = 0.001;
let amp_mod = 5.;
let y_offset = screen_height() / 2.0;
let mut x_offset = 0.0;
let x_mod = 5.0;
loop {
clear_background(LIGHTGRAY);
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);
}
if is_key_down(KeyCode::PageUp) {
freq += freq_mod;
}
if is_key_down(KeyCode::PageDown) {
freq -= freq_mod;
}
if is_key_down(KeyCode::Up) {
amp += amp_mod;
}
if is_key_down(KeyCode::Down) {
amp -= amp_mod;
}
if is_key_down(KeyCode::Left) {
x_offset += x_mod;
}
if is_key_down(KeyCode::Right) {
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
}
}