# How to make a Sine wave generated from a unit circle with dynamic frequency and amplitude?

I want to create a Sine Wave generated from a unit circle in Unity whose amplitude and frequency can be dynamically changed by changing the speed and radius of the circle. Ex:

The result should look something like this(see pictures below) where one continuous curve shows the sustained changes in frequency and amplitude when looked over time:

I looked at the Unity Asset Store, there are a few wave generators, but none of them work with varying amplitude and frequency such that the resulting curve is one continuous curve where previous amplitudes and frequency still show in the editor.

Here is a very simple example: In the editor, you can define a curve to change the frequency and amplitude over time.

1. Create a cube and attach a Line Renderer to visualize the resulting sine curve
2. Attach the following `Sine` script
3. Change the values shown in the inspector.

I have hard time with the frequency, but with an amplitude curve with the keys {0,1}, {5,5}, {10,1}, I had the 1st sine curve youâ€™ve linked.

``````using UnityEngine;
using System.Collections;

public class Sine : MonoBehaviour
{
[SerializeField]
private AnimationCurve frequencyCurve;

[SerializeField]
private AnimationCurve amplitudeCurve;

[SerializeField]
private float xSpeed = 1;

private void Start()
{
frequencyCurve.postWrapMode = WrapMode.Loop;
amplitudeCurve.postWrapMode = WrapMode.Loop;
}

private void Update()
{
float t = Time.time;
float amplitude = amplitudeCurve.Evaluate( t );
float frequency = frequencyCurve.Evaluate( t );
float phase = 0;
float y = amplitude * Mathf.Sin( 2 * Mathf.PI * frequency * t + phase );

transform.position = Vector3.up * y + Vector3.right * xSpeed * t;
}
}
``````