From d4f820e37bbb6571af4587adb2a3b3519d76849a Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sat, 5 Oct 2024 08:28:22 +0200 Subject: Draw triangles and lines --- examples/graph.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 examples/graph.c (limited to 'examples/graph.c') diff --git a/examples/graph.c b/examples/graph.c new file mode 100755 index 0000000..c7b2877 --- /dev/null +++ b/examples/graph.c @@ -0,0 +1,66 @@ +#if 0 /* +#/ ================================================================ +#/ +#/ graph.c +#/ +#/ ================================================================ +#/ +#/ Self-compilation shell script +#/ +SRC=${0##*./} +BIN=${SRC%.*} +gcc \ + -Wall -Wextra -Werror -pedantic \ + -Wno-old-style-declaration \ + -Wno-missing-braces \ + -Wno-unused-variable \ + -Wno-unused-but-set-variable \ + -Wno-unused-parameter \ + -Wno-overlength-strings \ + -O3 \ + -fsanitize=undefined,address,leak -mshstk \ + -lX11 -lm \ + -o $BIN $SRC && \ + ./$BIN $@ && rm $BIN +exit $? # */ +#endif + +#include "../graphics.c" + +i32 main(i32 argc, c8 **argv) { + (void) argc; + (void) argv; + + platform = (Platform) { + .title = "Graph", + .frame_width = 960, + .frame_height = 720, + }; + + u32 WHITE = u32_from_rgb(1.f, 1.f, 1.f); + u32 BLACK = u32_from_rgb(0.f, 0.f, 0.f); + u32 RED = u32_from_rgb(1.f, 0.f, 0.f); + u32 BLUE = u32_from_rgb(0.f, 0.f, 1.f); + + p_init(); + + while (!platform.done) { + p_wait_events(); + + i64 x = platform.frame_width / 2; + i64 y = platform.frame_height / 2; + + fill_rectangle(OP_SET, WHITE, 0, 0, platform.frame_width, platform.frame_height); + + fill_triangle(OP_SET, RED, 100, 100, 200, 100, 150, 200); + + fill_line(OP_SET, BLUE, 100, 300, 300, 500, 30); + + fill_ellipse(OP_SET, BLACK, x - 140, y - 100, 280, 200); + + p_render_frame(); + } + + p_cleanup(); + return 0; +} -- cgit v1.2.3