drawing points

This commit is contained in:
bronku 2026-02-15 23:03:40 +01:00
parent 37febeafc3
commit 91bcc8884f

View file

@ -1,12 +1,32 @@
use raylib::prelude::*; use raylib::prelude::*;
const WINDOW_WIDTH: i32 = 640;
const WINDOW_HEIGHT: i32 = 480;
fn convert_coordinates(pos_x: f32, pos_y: f32) -> (i32, i32) {
return (
((WINDOW_WIDTH as f32) * ((pos_x + 1.0) / 2.0)) as i32,
((WINDOW_HEIGHT as f32) * ((pos_y + 1.0) / 2.0)) as i32,
);
}
fn draw_point(d: &mut RaylibDrawHandle, pos_x: f32, pos_y: f32) {
const POINT_SIZE: i32 = 3;
let (window_x, window_y) = convert_coordinates(pos_x, pos_y);
d.draw_rectangle(window_x, window_y, POINT_SIZE, POINT_SIZE, Color::RED);
}
fn main() { fn main() {
let (mut rl, thread) = raylib::init().size(640, 480).title("Hello, World").build(); let (mut rl, thread) = raylib::init().size(WINDOW_WIDTH, WINDOW_HEIGHT).build();
while !rl.window_should_close() { while !rl.window_should_close() {
let mut d = rl.begin_drawing(&thread); let mut d = rl.begin_drawing(&thread);
draw_point(&mut d, -0.5, -0.5);
draw_point(&mut d, 0.5, -0.5);
draw_point(&mut d, 0.5, 0.5);
draw_point(&mut d, -0.5, 0.5);
d.clear_background(Color::WHITE); d.clear_background(Color::WHITE);
d.draw_text("Hello, world!", 12, 12, 20, Color::BLACK);
} }
} }