Skip to content

Instantly share code, notes, and snippets.

@DV8FromTheWorld
Created February 12, 2015 19:24
Show Gist options
  • Select an option

  • Save DV8FromTheWorld/02cab94ac50737cef1ed to your computer and use it in GitHub Desktop.

Select an option

Save DV8FromTheWorld/02cab94ac50737cef1ed to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections.Generic;
public class pendulumVelocity : MonoBehaviour
{
List<float> list = new List<float> ();
public int numToGraph = 128;
public Transform bar;
public Transform[] bars;
public Transform barContainer;
// Use this for initialization
void Awake ()
{
bars = new Transform[numToGraph];
createGraph ();
//Screen.lockCursor = true;
}
// Update is called once per frame
void FixedUpdate ()
{
float velocityMag = rigidbody.velocity.magnitude;
graphVelocity (velocityMag);
}
void graphVelocity (float velocity)
{
if (list.Count > numToGraph) {
//list.Remove(0);
list.RemoveAt (0);
}
list.Add (velocity);
printList (list);
}
void printList (List<float> list)
{
for (int i = 0; i < numToGraph; i++) {
//double h = (double)(list[i]);
float height = list [i];
bars [i].localScale = new Vector3 (1, height, 1);
}
}
void createGraph ()
{
for (int i = 0; i < numToGraph; i++) {
Vector3 pos = barContainer.transform.position;
pos.x +=i;
bars [i] = Instantiate (bar, pos, Quaternion.identity) as Transform;
bars [i].parent = barContainer;
list.Add (0);
}
barContainer.transform.localScale = new Vector3 (2f, .48f, .12f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment