scanning #1
78
src/main.rs
78
src/main.rs
@@ -1,38 +1,61 @@
|
||||
use core::f32;
|
||||
use std::{io, time::{Duration, Instant}};
|
||||
|
||||
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;
|
||||
let amp_mod = 5.;
|
||||
// Dot position
|
||||
let y_offset = screen_height() / 2.0;
|
||||
let mut x_offset = 0.0;
|
||||
let x_mod = 5.0;
|
||||
let mut x_offset = screen_width();
|
||||
|
||||
// selection box
|
||||
// Selection box
|
||||
let mut inital_x_pos = 0.;
|
||||
let mut inital_y_pos = 0.;
|
||||
|
||||
// Tooling
|
||||
let mut show_debug = false;
|
||||
let mut last_frame = Instant::now();
|
||||
let mut px_per_ms: f32 = 0.5;
|
||||
|
||||
loop {
|
||||
clear_background(BLACK);
|
||||
if show_debug {
|
||||
|
||||
let delta_time = last_frame.elapsed().as_millis() as f32;
|
||||
|
||||
if x_offset >= screen_width() {
|
||||
x_offset = 0.;
|
||||
} else {
|
||||
x_offset = x_offset + delta_time * px_per_ms;
|
||||
}
|
||||
|
||||
let x = 0.+x_offset;
|
||||
let y = 0.+y_offset;
|
||||
draw_circle(x, y, 3.0, GREEN);
|
||||
|
||||
fn text(text: &str, index: usize) {
|
||||
let index = index as f32;
|
||||
let text_h = 20.0;
|
||||
let text_margin = 20.0;
|
||||
draw_text(&format!("Amplitude: {}, Freqency {}, X Offset {}", amp, freq, x_offset) , text_margin, text_h*1. +text_margin, text_h, WHITE);
|
||||
draw_text(&format!("Cursor {:?}, Last Click {:?}", mouse_position(), (inital_x_pos, inital_y_pos)) , text_margin, text_h*2. +text_margin, text_h, WHITE);
|
||||
draw_text(text, text_margin, text_h*index+text_margin, text_h, WHITE);
|
||||
}
|
||||
if show_debug {
|
||||
text(&format!("FPS {}", get_fps()), 0);
|
||||
text(&format!("Pos {:?}", (x,y)), 1);
|
||||
text(&format!("Cursor {:?}, Last Click {:?}", mouse_position(), (inital_x_pos, inital_y_pos)), 2);
|
||||
text(&format!("px/ms {px_per_ms}"), 3);
|
||||
}
|
||||
|
||||
// toggle debug box
|
||||
if is_key_pressed(KeyCode::LeftControl) {
|
||||
if is_key_pressed(KeyCode::D) {
|
||||
show_debug = !show_debug;
|
||||
}
|
||||
|
||||
if is_key_pressed(KeyCode::Up) {
|
||||
px_per_ms += 0.1;
|
||||
}
|
||||
if is_key_pressed(KeyCode::Down) {
|
||||
px_per_ms -= 0.1;
|
||||
}
|
||||
// selection box
|
||||
if is_mouse_button_pressed(MouseButton::Left) {
|
||||
(inital_x_pos, inital_y_pos) = mouse_position();
|
||||
@@ -46,33 +69,8 @@ async fn main() {
|
||||
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, 3.0, GREEN);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
last_frame = Instant::now();
|
||||
next_frame().await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user