2 using System.Collections;
3 using System.Collections.Generic;
8 List<double> values =
new List<double>();
11 bool textureNeedsToBeRegenerated =
true;
12 bool needsToBeResorted =
true;
24 public void addValue(
double val )
27 textureNeedsToBeRegenerated =
true;
28 needsToBeResorted =
true;
31 public Texture2D asTexture()
33 if (textureNeedsToBeRegenerated) {
39 public void setMinMaxPixelValues(
float min,
float max )
45 public void sortIntoBins(
int numOfBins )
47 bins =
new long[numOfBins];
48 binSize = (maxValue - minValue)/(
double)numOfBins;
49 this.numOfBins = numOfBins;
51 for (
int i = 1; i < values.Count; i++) {
52 if (values[i] < minValue || values[i] > maxValue)
54 int binIndex = (int)Math.Floor ((values[i] - minValue) / binSize + 0.5);
55 if (binIndex >= 0 && binIndex < numOfBins)
61 for (
int i = 0; i < numOfBins; i++) {
66 needsToBeResorted =
false;
69 public void generateTexture()
71 if (needsToBeResorted)
76 texture =
new Texture2D (numOfBins, texHeight, TextureFormat.ARGB32,
false,
true);
78 for (
int i = 0; i < numOfBins; i++) {
79 long height = (long)(texHeight-1) * bins [i] / max;
81 if (bins [i] > 0 && height == 0)
83 for (
int y = 0; y < height; y++)
84 texture.SetPixel (i, y, Color.white);
85 for (
int y = (
int)height; y < texHeight; y++) {
86 texture.SetPixel (i, y, Color.black);
90 textureNeedsToBeRegenerated =
false;