using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MicrowaveRenderer : MonoBehaviour {

    public LineRenderer lineRenderer;
    public Transform catodoIzq, catodoDer;
    public int waveResolution = 2;
    public AnimationCurve rayDeployCurve;

    public float noise1Amplitude, noise1Frecuency, noise2Amplitude, noise2Frecuency;

	// Use this for initialization
	void Start () {
        lineRenderer = GetComponent<LineRenderer>();
        lineRenderer.numPositions = waveResolution +1;

        lineRenderer.widthMultiplier = 0.3f;

        /*
        lineRenderer.SetPosition(0, Vector3.zero);
        lineRenderer.SetPosition(1, Vector3.one);
        */
    }
	
	// Update is called once per frame
	void Update () {

        noise2Frecuency = Mathf.PerlinNoise(Time.time, Time.time) * 50;


        for (int i = 0; i <= waveResolution; i++)
        {
            Vector3 positionClean = Vector3.Lerp(catodoIzq.position, catodoDer.position, (float)i / waveResolution);
            Vector3 noise1 = transform.TransformDirection(new Vector3(Mathf.PerlinNoise(Time.time*2 + i * noise1Frecuency, 0f) - 0.5f, Mathf.PerlinNoise(0f, Time.time*2 +  i * noise1Frecuency) - 0.5f, 0f));
            Vector3 noise2 = transform.TransformDirection(new Vector3(Mathf.PerlinNoise(Time.time * noise2Frecuency + i * noise2Frecuency, 0f) - 0.5f, Mathf.PerlinNoise(0f, Time.time* noise2Frecuency + i * noise2Frecuency) - 0.5f, 0f));
            lineRenderer.SetPosition(i, positionClean + (noise1 * noise1Amplitude * rayDeployCurve.Evaluate((float)i/waveResolution)) + (noise2 * noise2Amplitude * rayDeployCurve.Evaluate((float)i / waveResolution)));
        }
    
	}
}
