Last active
August 29, 2015 13:56
-
-
Save mortennobel/8818563 to your computer and use it in GitHub Desktop.
ASCII visualization (used for debugging 2d scalar fields)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <array> | |
#include <algorithm> | |
#include <functional> | |
using namespace std; | |
// assumes that values returned by data is normalized between 0.0 and 1.0 | |
string get_grayscale_image(int width, int height, function<float(int,int)> data){ | |
const int size = 10; | |
const array<char,size+1> ascii {" .:-=+*#%@"}; | |
string res = ""; | |
for (int y=0;y<height;y++){ | |
for (int x=0;x<width;x++){ | |
float value = data(x,y); | |
float clampedValue = max(0.0f,min(1.0f, value)); | |
int mappedInt = min(size-1,(int)(clampedValue*10)); | |
res += ascii[mappedInt]; | |
} | |
res += "\n"; | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment