summaryrefslogtreecommitdiff
path: root/examples/line.c
diff options
context:
space:
mode:
authorkkard2 <[email protected]>2025-09-09 19:01:33 +0200
committerkkard2 <[email protected]>2025-09-09 19:01:33 +0200
commite47ed8959dd279df4524b69d3041af80a25bd66e (patch)
tree74dffb9e9b96b93040c37e46f85e4046fbc8a8c7 /examples/line.c
parent8d463f89f1918b820ae3b0c2455ad9f27b6a8b27 (diff)
add line drawing, add triangles.c
Diffstat (limited to 'examples/line.c')
-rw-r--r--examples/line.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/line.c b/examples/line.c
new file mode 100644
index 0000000..31724a9
--- /dev/null
+++ b/examples/line.c
@@ -0,0 +1,25 @@
+#include <math.h>
+
+#include "../sponge.h"
+
+#define PI ((float)3.14159265358979323846)
+#define SPEED (0.5f / 360.0f * 2 * PI)
+static float angle = 0.0f;
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+
+void init() {}
+
+void draw_frame(sponge_Texture c) {
+ sponge_clear(c, 0xFF000000);
+ angle += SPEED;
+
+ float x = sinf(angle);
+ float y = cosf(angle);
+ int32_t half = (int32_t)MIN(c.width, c.height) / 2;
+
+ sponge_draw_line(
+ c,
+ half + (int32_t)( x * (float)half), half + (int32_t)( y * (float)half),
+ half + (int32_t)(-x * (float)half), half + (int32_t)(-y * (float)half),
+ 0xFFFF00FF);
+}