this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: draw a hexagon

+38 -1
+38 -1
src/main.zig
··· 3 3 4 4 const rl = @import("raylib"); 5 5 6 + const Point = struct { x: i32, y: i32 }; 7 + const HexCell = struct { inner_radius: f32, center: Point }; 8 + 9 + fn calculate_hex_corners(center: Point, size: f32, _i: usize) Point { 10 + const i: f32 = @floatFromInt(_i); 11 + const angle_deg = 60 * i; 12 + const angle_rad = std.math.degreesToRadians(angle_deg); 13 + 14 + const x_offset: i32 = @intFromFloat(size * std.math.cos(angle_rad)); 15 + const y_offset: i32 = @intFromFloat(size * std.math.sin(angle_rad)); 16 + 17 + return Point{ .x = center.x + x_offset, .y = center.y + y_offset }; 18 + } 19 + 20 + fn draw_hex(hex: HexCell) void { 21 + var corners: [6]Point = undefined; 22 + for (0..6) |i| { 23 + const corner = calculate_hex_corners(hex.center, hex.inner_radius, i); 24 + corners[i] = corner; 25 + rl.drawCircle(corner.x, corner.y, 5.0, .black); 26 + } 27 + 28 + for (0..6) |i| { 29 + const start = corners[i]; 30 + const end = corners[@mod(i + 1, corners.len)]; 31 + 32 + rl.drawLine(start.x, start.y, end.x, end.y, .black); 33 + } 34 + } 35 + 6 36 pub fn main() anyerror!void { 7 37 // Initialization 8 38 //-------------------------------------------------------------------------------------- ··· 22 52 // TODO: Update your variables here 23 53 //---------------------------------------------------------------------------------- 24 54 55 + const cell = HexCell{ .inner_radius = 50.0, .center = .{ 56 + .x = 100, 57 + .y = 100, 58 + } }; 59 + 25 60 // Draw 26 61 //---------------------------------------------------------------------------------- 27 62 rl.beginDrawing(); ··· 29 64 30 65 rl.clearBackground(.white); 31 66 32 - rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray); 67 + draw_hex(cell); 68 + 69 + //rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray); 33 70 //---------------------------------------------------------------------------------- 34 71 } 35 72 }