public SphereLine(float x, float y, int resolution) { path = new PolylinePath(); for (int i = 0; i < resolution; i++) { path.AddPoint(0, 0); } this.x = x; this.y = y; }
void Start() { squiggleAudio = GetComponent <SquiggleAudio>(); squiggleManager = transform.parent.GetComponent <SquiggleManager>(); Vector3 position = FindStartingPoint(); path = new PolylinePath(); path.AddPoint(position.x, position.y); points.Add(position); deltas.Add(Vector3.zero); StartCoroutine(DrawLine()); }
public void OnRender(Camera cam) { // make sure we have a path and that it has at least 2 points if (path != null && path.Count > 1) { PolylinePath tempPath = new PolylinePath(); for (int i = Mathf.Max(1, startingIndex); i < path.Count; ++i) { // extract this point Vector3 previousPoint = path[i - 1].point; Vector3 currentPoint = path[i].point; // if we're not drawing if (!drawing) { float value = 0.0f; // animate the path float pct = i / (float)path.Count; // calculate arc-tangent from delta // FIXME: I would have assumed the inverse current-previous for the ATAN2, hmmm.... Vector3 deltaPoint = previousPoint - currentPoint; float atan = Mathf.Atan2(deltaPoint.y, deltaPoint.x); float sin = Mathf.Sin(atan); float cos = Mathf.Cos(atan); // figture out the index int spectrumIndex = (int)(pct * squiggleAudio.logSpectrum.Length); // use spectrum for radius value = squiggleAudio.logSpectrum[spectrumIndex]; // FIXME: do a proper FFT normalization float attenuation = 0.025f; // FIXME: replace random with a proper FFT using spectrum value float radius = Random.Range(-value * attenuation, value * attenuation); // float radius = value * attenuation; // apply to point currentPoint.x += radius * sin; currentPoint.y += radius * cos; } tempPath.AddPoint(currentPoint); // draw the label } // make sure we have more than one point if (tempPath.Count > 1) { // draw the line Draw.LineEndCaps = LineEndCap.Round; Draw.Polyline(tempPath, closed: false, thickness: thickness, Color.white); } } }
public virtual void OnDrawGizmos() { if (poly == null || !drawGizmos) { return; } PolylinePath path = new PolylinePath(); foreach (Vector2 v in poly.points) { path.AddPoints(poly.transform.TransformPoint(v)); } Draw.Polyline(path, true, gizmoScale / 4, lineColor); for (int i = 0; i < path.Count; i++) { Draw.Rectangle(path[i].point, gizmoScale, gizmoScale, pointColor); } }
private void Awake() { routePolyLinePath = new PolylinePath(); // a persistent one that can be modified instead of recreated all the time }