boxxofrobots
Well-known member
I have a simplex noise generator that has been shown to reliably produce values between -1 and 1, yet when I run this I get values out of range. Can someone explain what I might be doing wrong?
It is invoked using this:
Code:
#include "perlinFunctions.h"
#include "SimplexNoise.h"
#include <Arduino.h>
extern SimplexNoise perlin; // Declare the perlin object
void getPerlinDisplayValues(double xSize, double ySize, double xOffset, double yOffset, double scale, uint8_t* tableData) {
double startX = xOffset - ((xSize / 2) * scale);
double startY = yOffset + ((ySize / 2) * scale);
for (int y = 0; y < ySize; y++) {
for (int x = 0; x < xSize; x++) {
double perlinX = startX + (x * scale);
double perlinY = startY - (y * scale);
uint8_t noiseValue = map(perlin.noise(perlinX, perlinY),-1,1,0,255);
int index = y * xSize + x;
tableData[index] = noiseValue;
}
}
}
It is invoked using this:
Code:
uint8_t* displayValues = new uint8_t[xDisplay * yDisplay];
perlin.init(3); // ALWAYS CALL PERLIN.INIT BEFORE CALLING PERLIN.NOISE!
startTime = micros();
getPerlinDisplayValues(xDisplay, yDisplay, xOffset, yOffset, scale, displayValues);
printElapsedTime();