I think all of us who have used COS() and SIN() from one time to another find it rather difficult to get "clean" numbers, that is, to bounce around from one end of the negative spectrum, to positive, and back again to exactly where you started.
I wrote this routine to use for my own stuff but you can work it too if you like.
It's a simple array from 0-255 called MySin(), in it, it starts at -255, works to positive 255, and back again, in a very clean curved calculation that does not involve any math other than adding and subtracting coefficient numbers.
[16x16] | |
mysin={} n=-255 a=0 p=0 repeat print(p.." "..n) repeat flip() until btn(4) mysin[p]=n mysin[127-p]=-n mysin[128+p]=-n mysin[255-p]=n n+=a a+=.128 p+=1 until p>=64 cls() for i=0,255 do pset(i/2,64+mysin[i]/8) end for i=0,255 do print(i.." "..mysin[i]) repeat flip() until btn(4) end |
As you can see by reading every fractional value back, it is flawless in its calculations. You have a true and perfect mirror for both negative and positive values. Watch especially when the index passes 64 and 127 and compare both the negative and positive numbers.
HOPE THIS HELPS !
[Please log in to post a comment]