Created
December 13, 2016 22:00
-
-
Save nothke/b3c1a2f12f8c48973e0809b8566c3a04 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using System.Collections; | |
public class PreviewPerlin : MonoBehaviour | |
{ | |
public int samples = 5000; | |
public float previewLength = 10; | |
public float xValue = 1; | |
public float offset = 0; | |
public float frequency = 1; | |
public float gain = 1; | |
void OnDrawGizmos() | |
{ | |
samples = Mathf.Clamp(samples, 2, int.MaxValue); | |
Vector3 lastPoint = Vector3.zero; | |
float dist = previewLength / (float) samples; | |
for (int i = 0; i < samples + 1; i++) | |
{ | |
float height = (-0.5f + Mathf.PerlinNoise(xValue, offset + frequency * dist * i)) * gain; | |
Vector3 thisPoint = new Vector3(dist * i, height); | |
if (i != 0) | |
Gizmos.DrawLine(lastPoint, thisPoint); | |
lastPoint = thisPoint; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment