Initial commit
This commit is contained in:
55
Assets/scripts/perlinNoise.cs
Normal file
55
Assets/scripts/perlinNoise.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class perlinNoise : MonoBehaviour
|
||||
{
|
||||
public int seed = 0;
|
||||
private float offsetX = 0;
|
||||
private float offsetY = 0;
|
||||
|
||||
private float offsetX1 = 0;
|
||||
private float offsetY1 = 0;
|
||||
|
||||
private float offsetX2 = 0;
|
||||
private float offsetY2 = 0;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
if(seed == -1) { seed = (int) (Random.value * 1000000000); }
|
||||
Debug.Log(seed);
|
||||
|
||||
Random.InitState(seed);
|
||||
|
||||
offsetX = Random.value;
|
||||
offsetY = Random.value;
|
||||
|
||||
offsetX1 = Random.value;
|
||||
offsetY1 = Random.value;
|
||||
|
||||
offsetX2 = Random.value;
|
||||
offsetY2 = Random.value;
|
||||
|
||||
}
|
||||
|
||||
public float getNoise(float x, float y, int size)
|
||||
{
|
||||
float density = size / 32;
|
||||
//Debug.Log(size);
|
||||
//Debug.Log(density);
|
||||
//Debug.Log(x + " " + y);
|
||||
x *= density;
|
||||
y *= density;
|
||||
|
||||
float val1 = Mathf.PerlinNoise(x + offsetX, y + offsetY);
|
||||
float val2 = Mathf.PerlinNoise(x*2 + offsetX1, y*2 + offsetY1);
|
||||
float val3 = Mathf.PerlinNoise(x*8 + offsetX2, y*8 + offsetY2);
|
||||
|
||||
|
||||
float res = val1*0.7f+val2*0.4f+val3*0.3f;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user