Open alexmozaidze opened 1 year ago
I made something Currently only works to draw lines. If you wanted to draw a filled ellipse then set the thickness number to something big (like 100, 1000 just filles the entire screen) however it takes more space than specified. Heres the same ellipse but with more thickness:
Here's the code:
fn draw_ellipse_line(center_x:f32,center_y:f32,rx:f32,ry:f32,num_segments:u32,thickness:f32,color:Color) {
for i in 0..num_segments {
let angle = 2.0 * std::f32::consts::PI * (i as f32) / (num_segments as f32);
let x = center_x + rx * angle.cos();
let y = center_y + ry * angle.sin();
draw_circle(x,y,thickness,color);
}
}
Example usage:
#[macroquad::main("Draw Ellipse")]
async fn main() {
const WIDTH: f32 = 800.0;
const HEIGHT: f32 = 600.0;
const CENTER_X: f32 = WIDTH / 2.0;
const CENTER_Y: f32 = HEIGHT / 2.0;
const RX: f32 = 100.0;
const RY: f32 = 200.0;
const NUM_SEGMENTS: u32 = 1000;
loop {
clear_background(BLACK);
draw_ellipse_line(CENTER_X,CENTER_Y,RX,RY,NUM_SEGMENTS,1.0,RED);
next_frame().await;
}
}
Code was referred from OpenGl/ellipse.cpp
Circles are cool and all, but aren't ellipses just plain cooler? I made a tic tac toe game just because, and it heavily depends on the window being a square, simply because I use circles. Using ellipses would mitigate this issue. I want my ellipses. plez