aboutsummaryrefslogtreecommitdiff
path: root/src/km-draw.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-02-05 00:22:15 -0500
committerPaul Duncan <pabs@pablotron.org>2019-02-05 00:22:15 -0500
commitf557d1f49a2914c6084dd18efc783395228d8ce0 (patch)
tree51111fc899f01956cbab948b87c241478576870d /src/km-draw.c
parentb5065ea43cb13c0b553874305b53963176c70f59 (diff)
downloadkmeans-f557d1f49a2914c6084dd18efc783395228d8ce0.tar.bz2
kmeans-f557d1f49a2914c6084dd18efc783395228d8ce0.zip
mv *.[hc] src/
Diffstat (limited to 'src/km-draw.c')
-rw-r--r--src/km-draw.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/km-draw.c b/src/km-draw.c
new file mode 100644
index 0000000..ddf1b26
--- /dev/null
+++ b/src/km-draw.c
@@ -0,0 +1,31 @@
+#include <stdint.h> // size_t
+#include "util.h"
+#include "km.h"
+
+void
+km_set_draw(
+ const km_set_t * const set,
+ uint8_t * const rgb,
+ const size_t width,
+ const size_t height,
+ const int dot_size,
+ const uint32_t color
+) {
+ for (size_t i = 0; i < set->num_rows; i++) {
+ const float *row = km_set_get_row(set, i);
+
+ for (int yo = 0; yo < dot_size; yo++) {
+ for (int xo = 0; xo < dot_size; xo++) {
+ const int x = (width - 1) * row[0] - dot_size / 2 + xo,
+ y = (height - 1) * row[1] - dot_size / 2 + yo,
+ ofs = 3 * (width * y + x);
+
+ if (x >= 0 && x < (int) width && y >= 0 && y < (int) height) {
+ rgb[ofs + 0] = (color & 0xff0000) >> 16;
+ rgb[ofs + 1] = (color & 0x00ff00) >> 8;
+ rgb[ofs + 2] = (color & 0x0000ff);
+ }
+ }
+ }
+ }
+}