the next day, I came up with this solution.
The idea is pretty simple. You'll need to have a knowledge of how sine curves are drawn on graphs.
We won't need any transformation matrices for this.
1. The co-ordinate system is same as traditional, but the origin is at the bottom-center of the page.
So, Y is always positive and X can be both be positive and negative upto a certain extent.
2. Co_eff is a constant value which constrains the maximum X co-ordinate of the road in order to
fit it within the view. It is used as the amplitude of the sine curve.
First of all, I decided that that only full sine curves (one total period) will be used to avoid complexity.
This also gave me one added advantage of smoothness of the curves even when one sine curve ends and a new one is drawn.
This are the steps for generating the first curve … The rest will follow similarly...
1. Generate a random value (within a suitable range) and store it as y1
This y1 value is the (relative) height (distance in the y direction) at which one full sine curve
2. Now, as we know, sine curves have a period of 2⊼ radians.
But, in our case, the sine curve should start exactly at the current point and terminate exactly at the next
point (0,y1) [relative to the current point].
So, we need to find a variable named "value" such that y1=2⊼*value
We will use a factor of (1/value) with the independent variable [here y-coordinate]
(as the curves are drawn along y-axis, so the x-coordinate of the initial and final
point doesn’t change. So, we don’t care about the x-coordinate)
3. Now, draw the curve “ x=co_eff*sin(y/value) ” starting from the initial point.
It will look like this: