So, I needed this for my current Tier 2 WIP and worked it out in Tier1 because it was easier to do that testing and prototyping there.
In my WIP, I will take the curve and rotate it to the correct position. But that code is a little more complex and currently uses custom structs and classes.
Anyway, play with the wl# value to make the curve longer or shorter and amp# to change the height:
// define all the variables used
dim xpnts#[720] as float
dim ypnts#[720] as float
x# as float
y# as float
wl# as float
amp# as float
scrwid# as float
scrhih# as float
halfhih# as float
ticktop# as float
tickbot# as float
i as integer
l as integer
maxtick as integer
// get resolution and
scrwid# = GetDeviceWidth()
scrhih# = GetDeviceHeight()
// calculate some values
halfhih# = scrhih# / 2.0
ticktop# = halfhih# - 100.0
tickbot# = halfhih# + 100.0
maxtick = Floor(scrwid#/100.0)
// set resolution
setVirtualResolution(scrwid#, scrhih#)
// calculate the sine wave for
// one full wave
x# = 0.0
for i=1 to 360
// store X as a value from 0.0 to 1.0
xpnts#[i] = x# / 360.0
// store Y as a value from -1.0 to 1.0
ypnts#[i] = sin(x#)
// increment X
x# = x# + 1.0
next i
// now make the points to go back the other way
for i=361 to 720
xpnts#[i] = xpnts#[720-i+1]
ypnts#[i] = ypnts#[i-360]
next i
// make a dummy sprite (default size is 10x10)
spr = createSprite(0)
// set offset to center
SetSpriteOffset(spr,5.0,5.0)
// start at the first point
i = 1
// set the wavelength
wl# = 200.0
// set the amplitude
amp# = 40.0
// main loop
do
// set up for exit
if GetRawKeyPressed(27) then exit
// draw a center line and some ticks
DrawLine(0.0,halfhih#,scrwid#,halfhih#,255,255,255)
for l=1 to 10
DrawLine(0.0,halfhih#-l*10,scrwid#,halfhih#-l*10,128,128,128)
DrawLine(0.0,halfhih#+l*10,scrwid#,halfhih#+l*10,128,128,128)
next l
for l=0 to maxtick
DrawLine(l*100,ticktop#,l*100,tickbot#,255,255,255)
next l
// grab the points and apply amplitude and wave length
x# = xpnts#[i] * wl#
y# = ypnts#[i] * amp#
// position the sprite
setSpritePositionByOffset(spr, x#, y# + halfhih#)
// update point in curve
i = i + 1
// go back to start if at end
if i > 720 then i = 1
print("X="+str(x#,2))
print("Y="+str(y#,2))
sync()
loop
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master