X-Axis runs horizontally at the center for the image for which Y = 100.
We will declare some variables.
$width=800; // Width of the Image Canvas
$height=200; // Height of the canvas
$steps=2; // The Jump in value of X - Axis for each loop.
Step: In the script the amount of movement of X axis in each loop. You can see we draw line between two coordinates and the value of 2nd coordinate is taken from the first.
Note that this value of the $step determines the sharpness of the curves. Higher the value of step less will be the sharpness. Similarly with less number of steps more looping is required so sharpness of the curve increases.
No of loops required.
To draw the curve we will use the loop and the loop will take one upper limit which is taken from this formula.
As we start from left edge ( X=0 ) so number of steps required is total width divided by steps taken in each loop.
How the curve is drawn
We used one for loop to draw lines between two coordinates. To draw this line we will use imageline function which takes two coordinates to draw line between them.
On next iteration of the loop, the 1st coordinate takes the values of 2nd coordinate of previous iteration of the loop.
For example in one loop the first coordinate is x1=20,y1=25 . Our 2nd Coordinate is x2=23,y2=27. IN the next loop we will have x1=23,y1=27, so the line will start from where we left at previous loop.
We know that sin value varies between -1 and +1. SIN(90) = 1 and SIN(270)=-1.
So our curve will reach its peak at SIN(90) which should be within our top of the image. So we will use one multiplier to adjust the height of the curve.