#
In this tutorial for DarkBASIC Professional I will demonstrate how to use Interpolation to draw a curve between two points in 2D space. This method is used to create natural looking mountainous regions and other graphical features. The same method can also be applied to acceleration curves, decleveration curves, tracking with camera's and even in prediction models. This tutorial focuses on the easiest of these methods the cosine method.
sync on
backdrop on
color backdrop 0
randomize 54673
dim ylist(10) as integer
for x = 0 to 10 ylist(x) = RND(128) + 300
next x
do
ink rgb(0, 255, 0), 0
x = 0
for y = 0 to 9
for z = 1 to 64
inc x
dot x, InterpolateCosine(ylist(y), ylist(y+1), z)
next z
next y ink rgb(255, 0, 0), 0 x = 0
for y = 0 to 10
dot x, ylist(y)
circle x, ylist(y), 4
inc x, 64
next y
sync
loop
Function InterpolateCosine(y1#, y2#, mu#)
mu2# = (1-cos(mu#*3.13159265))/2
output# = (y1#*(1-mu2#)+y2#*mu2#)
EndFunction output#