summaryrefslogtreecommitdiff
path: root/examples/triangles.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/triangles.c
parent8d463f89f1918b820ae3b0c2455ad9f27b6a8b27 (diff)
add line drawing, add triangles.c
Diffstat (limited to 'examples/triangles.c')
-rw-r--r--examples/triangles.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/triangles.c b/examples/triangles.c
new file mode 100644
index 0000000..f995574
--- /dev/null
+++ b/examples/triangles.c
@@ -0,0 +1,38 @@
+#include "../sponge.h"
+
+#define SPEED_ABS (2)
+#define GRID_SIZE (10)
+
+
+static int32_t offset = 0;
+static int32_t speed = SPEED_ABS;
+
+void init() {}
+
+void draw_frame(sponge_Texture c) {
+ sponge_clear(c, 0xFF000000);
+ offset += speed;
+
+ if (offset > 30) {
+ speed = -SPEED_ABS;
+ } else if (offset < -30) {
+ speed = SPEED_ABS;
+ }
+
+ int32_t offset_x = c.width / GRID_SIZE;
+ int32_t offset_y = c.height / GRID_SIZE;
+
+ for (int i = 0; i < GRID_SIZE; i++) {
+ for (int j = 0; j < GRID_SIZE; j++) {
+ int32_t x = i * offset_x;
+ int32_t y = j * offset_y + offset;
+
+ sponge_draw_triangle_col3(
+ c,
+ x, y + offset_y,
+ x + offset_x, y,
+ x + (offset_x / 4), y + (offset_y / 4),
+ 0xFFFF0000, 0xFF00FF00, 0xFF0000FF);
+ }
+ }
+}