summaryrefslogtreecommitdiff
path: root/src/procedural/generator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/procedural/generator.cc')
-rw-r--r--src/procedural/generator.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/procedural/generator.cc b/src/procedural/generator.cc
new file mode 100644
index 0000000..3d969ba
--- /dev/null
+++ b/src/procedural/generator.cc
@@ -0,0 +1,56 @@
+// This file is part of the 64k demo project.
+// It implements basic procedural texture generators.
+
+#include "procedural/generator.h"
+#include <cmath>
+#include <cstdlib>
+
+namespace procedural {
+
+// Simple noise generator
+// Params[0]: Seed (optional, if 0 uses rand())
+// Params[1]: Intensity (0.0 - 1.0)
+void gen_noise(uint8_t* buffer, int w, int h, const float* params,
+ int num_params) {
+ float intensity = (num_params > 1) ? params[1] : 1.0f;
+ if (num_params > 0 && params[0] != 0) {
+ srand((unsigned int)params[0]);
+ }
+
+ for (int i = 0; i < w * h; ++i) {
+ uint8_t val = (uint8_t)((rand() % 255) * intensity);
+ buffer[i * 4 + 0] = val; // R
+ buffer[i * 4 + 1] = val; // G
+ buffer[i * 4 + 2] = val; // B
+ buffer[i * 4 + 3] = 255; // A
+ }
+}
+
+// Simple grid generator
+// Params[0]: Grid Size (pixels)
+// Params[1]: Line Thickness (pixels)
+void gen_grid(uint8_t* buffer, int w, int h, const float* params,
+ int num_params) {
+ int grid_size = (num_params > 0) ? (int)params[0] : 32;
+ int thickness = (num_params > 1) ? (int)params[1] : 2;
+
+ if (grid_size < 1)
+ grid_size = 32;
+
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ bool on_line = ((x % grid_size) < thickness) ||
+ ((y % grid_size) < thickness);
+
+ int idx = (y * w + x) * 4;
+ uint8_t val = on_line ? 255 : 0;
+
+ buffer[idx + 0] = val;
+ buffer[idx + 1] = val;
+ buffer[idx + 2] = val;
+ buffer[idx + 3] = 255;
+ }
+ }
+}
+
+} // namespace procedural