Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Last active November 6, 2019 13:44
Show Gist options
  • Save TheCuttlefish/5c25536277ca37d25fb81d4f203aa573 to your computer and use it in GitHub Desktop.
Save TheCuttlefish/5c25536277ca37d25fb81d4f203aa573 to your computer and use it in GitHub Desktop.
Lorenz attractor
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LorenzoAttractor : MonoBehaviour
{
float x0, y0, z0, h, a, b, c, depth;
float steps;
void Start()
{
x0 = Random.Range(0f, 1f);
y0 = Random.Range(0f, 20f);
z0 = Random.Range(0, 10f);
h = 0.01f;
a = 10f;
b = 28f;
c = 8f / 3f;
depth = 0;
}
void Update()
{
if(steps < 100000)
{
steps++;
float x1 = x0 + h * a * (y0 - x0);
float y1 = y0 + h * (x0 * (b - z0) - y0);
float z1 = z0 + h * (x0 * y0 - c * z0);
Color colour = new Color( Mathf.Sin(steps / 100), Mathf.Sin(steps / 200), Mathf.Sin(steps / 300));
Debug.DrawLine(new Vector3(x0, y0, z0) * 1.2f, new Vector3(x0, y0, z0) * 100.1f, colour, 100);
x0 = x1;
y0 = y1;
z0 = z1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment