瀏覽代碼

Tweak the style of output

rexim 3 年之前
父節點
當前提交
04b5f07bd6
共有 2 個文件被更改,包括 7 次插入14 次删除
  1. 5 3
      config.h
  2. 2 11
      main.c

+ 5 - 3
config.h

@@ -3,12 +3,14 @@
 
 #define WIDTH 20
 #define HEIGHT 20
-#define PPM_SCALER 25
-#define PPM_COLOR_INTENSITY 200
 #define BIAS 20.0
-#define SAMPLE_SIZE 25
+#define SAMPLE_SIZE 75
 #define TRAIN_PASSES 2000
 
+#define PPM_SCALER 25
+#define PPM_COLOR_INTENSITY 255
+#define PPM_RANGE 10.0
+
 #define DATA_FOLDER "data"
 
 #define TRAIN_SEED 69

+ 2 - 11
main.c

@@ -57,15 +57,6 @@ void layer_fill_circle(Layer layer, int cx, int cy, int r, float value)
 
 void layer_save_as_ppm(Layer layer, const char *file_path)
 {
-    float min = FLT_MAX;
-    float max = FLT_MIN;
-    for (int y = 0; y < HEIGHT-1; ++y) {
-        for (int x = 0; x < WIDTH-1; ++x) {
-            if (layer[y][x] < min) min = layer[y][x];
-            if (layer[y][x] > max) max = layer[y][x];
-        }
-    }
-
     FILE *f = fopen(file_path, "wb");
     if (f == NULL) {
         fprintf(stderr, "ERROR: could not open file %s: %m\n",
@@ -77,11 +68,11 @@ void layer_save_as_ppm(Layer layer, const char *file_path)
 
     for (int y = 0; y < HEIGHT * PPM_SCALER; ++y) {
         for (int x = 0; x < WIDTH * PPM_SCALER; ++x) {
-            float s = (layer[y / PPM_SCALER][x / PPM_SCALER] - min) / (max - min);
+            float s = (layer[y / PPM_SCALER][x / PPM_SCALER] + PPM_RANGE) / (2.0f * PPM_RANGE);
             char pixel[3] = {
+                (char) floorf(PPM_COLOR_INTENSITY * (1.0f - s)),
                 (char) floorf(PPM_COLOR_INTENSITY * (1.0f - s)),
                 (char) floorf(PPM_COLOR_INTENSITY * s),
-                0,
             };
 
             fwrite(pixel, sizeof(pixel), 1, f);