I just programmed a sine-curve without using dbpro build-in math-functions, just with additions and multiplications. While it is not really useful (except for those who plan programming a 4K demo in C
), it might still be interesting. I used a natural physical principle in the calculation, so I did not really find it out myself.
rem MrKohlenstoff's pseudo-great Sine-Code
set display mode 640,480,32
sync on
sync rate 250
rem Achsis
ink 0xFF606060,0
line 0, 110, 640, 110
line 0, 290, 640, 290
ink 0xFFFFFFFF,0
line 0, 200, 640, 200
GenSin()
rem Visualization:
for x = 1 to 360
ink 0xFFFF0000,0
dot x, 200 - 90*_sin(x)
dot x+360, 200 - 90*_sin(x)
sync
next x
repeat
sync
until escapekey()
rem Sin-Constants
#constant k = 0.000303
#constant sinscale = 0.0173
function GenSin()
dim v(360) as float
dim _sin(360) as float
v(0) = 1.0
_sin(0) = 0.0
for x = 1 to 360
v(x) = v(x-1) - k*_sin(x-1)
_sin(x) = _sin(x-1) + v(x)
next x
for x = 0 to 360
_sin(x) = _sin(x) * sinscale
next x
undim v(0)
endfunction