Skip to content

Instantly share code, notes, and snippets.

@nothke
Created December 13, 2016 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothke/b3c1a2f12f8c48973e0809b8566c3a04 to your computer and use it in GitHub Desktop.
Save nothke/b3c1a2f12f8c48973e0809b8566c3a04 to your computer and use it in GitHub Desktop.
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