Cosine

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
Post Reply
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Cosine

Post by marcelk »

My favourite method to do cosines and sines with just integer math.

Code: Select all

'Plot cosine
10 cls
20 input p:if p<1 goto 20
30 u=50*100:v=0:c=0
40 for x=0 to 159
50 y=68-u/100
60 poke y*256+x,c
70 u=u+v:v=v-u/p
80 next x
90 c=c+23:goto 40
Cosine.jpeg
Cosine.jpeg (166.19 KiB) Viewed 24525 times

It's stable in the sense that it seems to maintain its amplitude and period over many dozens of iterations. I'm always surprised that whenever I change line 70 to follow the "proper" update order, it immediately goes awry.

Code: Select all

70 t=u:u=u+v:v=v-t/p:'Bad
Post Reply