Chaotic Motion  1.0
ShowAllChaos.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 
14 public class ShowAllChaos : MonoBehaviour {
15 
16  public GameObject chaosPrefab;
17  public float gridSpacing = 30f;
18 
19  public Material[] materials;
20 
21  // Use this for initialization
22  void Start () {
23  int count = ChaosEqnFactory.GetEquations().Count;
24  int gridSize = Mathf.CeilToInt(Mathf.Sqrt((float) count));
25  int row = 0;
26  int col = 0;
27  int materialCount = 0;
28  // set position in grid
29  if (materials.Length == 0 ) {
30  Debug.Log("Need to specify materials");
31  }
32  Vector3 origin = new Vector3(-gridSpacing*gridSize/2, gridSpacing*gridSize/2, 0f);
33  for (int i=0; i < count; i++) {
34  Vector3 p = transform.position + origin;
35  p.x += gridSpacing * row;
36  p.y -= gridSpacing * col;
37 
38  GameObject chaosSystem = Instantiate<GameObject>(chaosPrefab, p, Quaternion.identity);
39  chaosSystem.transform.parent = transform;
40  ChaoticMotion cm = chaosSystem.GetComponentInChildren<ChaoticMotion>();
41  cm.selectedEqn = i;
42  cm.timeZoom = cm.GetEquation().GetSlideshowSpeed();
43  cm.Init();
44  // Use the specified materials to color the attractor trails differently
45  foreach ( LineRenderer lr in cm.GetComponentsInChildren<LineRenderer>()) {
46  lr.sharedMaterial = materials[materialCount];
47  }
48  Text t = chaosSystem.GetComponentInChildren<Text>();
49  t.text = cm.GetEquation().GetName();
50  // advance to next grid slot
51  row++;
52  if (row >= gridSize) {
53  row = 0;
54  col++;
55  }
56  materialCount++;
57  if (materialCount >= materials.Length)
58  materialCount = 0;
59  Debug.Log("mc= " + materialCount);
60  }
61 
62  }
63 
64 }
Sample code to invoke a Chaos prefab for all equations provided by the factory and locate them in an ...
Definition: ShowAllChaos.cs:14
int selectedEqn
Number of chaos system to evolve (w.r.t. ChaosFactory list)
float timeZoom
Time scale (>0)
static List< ChaosEqn > GetEquations()
Returns a List of Equation objects. A singleton reference list is provided for the inspector script t...
Chaotic motion. Evolve the user specified chaotic system with the parameters held by the ChaoticSyste...
override void Init()
Init the equation using the selected equation and parameter bundle.