2 Replies - 3390 Views - Last Post: 14 August 2008 - 12:41 AM Rate Topic: -----

#1 Pontus   User is offline

  • Cattlebruiser

Reputation: 18
  • View blog
  • Posts: 612
  • Joined: 28-December 06

Perlin Noise

Posted 13 August 2008 - 01:48 PM

Hi,

I think I've got some perlin noise working (not sure). Its 22:42 now, I'm kinda tired. Here's what i get:
-0.614514 -0.226321  0.053733  0.228152  0.314069  0.300499  0.121103 -0.136784 -0.469094 -0.937431 
 0.621641  0.471056  0.219821 -0.142469 -0.618700 -1.189526 -1.834159 -2.638149 -3.485322 -4.382685 
 1.530250  0.831761  0.054852 -0.785659 -1.689693 -2.700335 -3.731424 -4.789687 -5.914028 -7.060840 
 1.285504  0.234337 -0.880578 -1.986551 -3.090959 -4.194898 -5.325507 -6.402001 -7.446577 -8.455884 
-0.364385 -1.473501 -2.534411 -3.569206 -4.542142 -5.436679 -6.262686 -7.007408 -7.648925 -8.214657 
-2.871655 -3.697566 -4.386805 -4.976111 -5.466606 -5.835929 -6.081578 -6.231981 -6.259090 -6.110443 
-5.211807 -5.390396 -5.445025 -5.360833 -5.170956 -4.866053 -4.372600 -3.790525 -3.131097 -2.366189 
-6.057539 -5.501166 -4.852149 -4.085396 -3.174011 -2.189578 -1.151687  0.002891  1.274685  2.575476 
-4.608814 -3.398098 -2.167816 -0.914472  0.383345  1.827292  3.225406  4.605771  5.993749  7.490348 
-0.785658  0.612526  2.046198  3.493935  4.876094  6.194302  7.558663  8.791742  9.942856  11.024901 



I need to convert these values into a number between 0 and 255, how do I do this? I'm just too tired to think of something...

All help is appreciated.

Greetings

Robin

Is This A Good Question/Topic? 0
  • +

Replies To: Perlin Noise

#2 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Perlin Noise

Posted 13 August 2008 - 02:53 PM

heres my take on it. Normalize the data between 0 and 1 and then multiply by 255:
#include <iostream>
#include <iomanip>
using namespace std;

int normailzeData(double data[], int size);
int displayData(double data[], int size);
int main() {
	double theData[] = {
	-0.614514 -0.226321,  0.053733,  0.228152,  0.314069,  0.300499,  0.121103, -0.136784, -0.469094, -0.937431,
	0.621641,  0.471056,  0.219821, -0.142469, -0.618700, -1.189526, -1.834159, -2.638149, -3.485322, -4.382685,
	1.530250,  0.831761,  0.054852, -0.785659, -1.689693, -2.700335, -3.731424, -4.789687, -5.914028, -7.060840,
	1.285504,  0.234337, -0.880578, -1.986551, -3.090959, -4.194898, -5.325507, -6.402001, -7.446577, -8.455884,
	-0.364385, -1.473501, -2.534411, -3.569206, -4.542142, -5.436679, -6.262686, -7.007408, -7.648925, -8.214657,
	-2.871655, -3.697566, -4.386805, -4.976111, -5.466606, -5.835929, -6.081578, -6.231981, -6.259090, -6.110443,
	-5.211807, -5.390396, -5.445025, -5.360833, -5.170956, -4.866053, -4.372600, -3.790525, -3.131097, -2.366189,
	-6.057539, -5.501166, -4.852149, -4.085396, -3.174011, -2.189578, -1.151687,  0.002891,  1.274685,  2.575476,
	-4.608814, -3.398098, -2.167816, -0.914472,  0.383345,  1.827292,  3.225406,  4.605771,  5.993749,  7.490348,
	-0.785658,  0.612526,  2.046198,  3.493935,  4.876094,  6.194302,  7.558663,  8.791742,  9.942856,  11.024901
	};
//	double theData[] = {11, 12, 10, 3, 4, 6, 9, 8, 7};
    int size = sizeof(theData)/sizeof(double);
    int intData[size];
	normailzeData(theData, size);
	cout << "The corrected data: " << endl;
   	for (int i = 0; i < size; ++i) {
		intData[i] = theData[i] * 255;
		cout << setw(6) << intData[i]  << (((i + 1)  % 5) ? " ": "\n");
    }	
	cout << endl;	
	system("pause");
	return 0;
}

int normailzeData(double data[], int size) {
	//step #1, find minimum and maximum
	double minimum = data[0], maximum = data[0];
	for (int i = 1; i < size; ++i) {
		if (data[i] > maximum) { maximum = data[i]; }
		if (data[i] < minimum) { minimum = data[i]; }
    }
    cout << "Maximum: " << maximum << endl;
    cout << "Minimum: " << minimum << endl;
    //step #2, normalize the data between 0 and 1.
   	for (int i = 0; i < size; ++i) {
		data[i] = (data[i]  - minimum)/(maximum - minimum);
		cout << setw(10) << data[i]  << (((i + 1)  % 5) ? " ": "\n");
    }
    cout << endl;
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

#3 Pontus   User is offline

  • Cattlebruiser

Reputation: 18
  • View blog
  • Posts: 612
  • Joined: 28-December 06

Re: Perlin Noise

Posted 14 August 2008 - 12:41 AM

Ty, I'll give it a try. Does it look like coherent noise to you?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1