SHOW:
|
|
- or go back to the newest paste.
1 | PPR = 1440 * 4 # decoder position steps per revolution | |
2 | ||
3 | # reduce x modulo n, but giving result in range(base,base+n) rather than range(0,n). | |
4 | - | def mod( x, n, base ): |
4 | + | # default output range is -n/2..n/2-1 (if n even) or -(n-1)/2..(n-1)/2 (if n odd). |
5 | def mod( x, n, base=-(n//2) ): | |
6 | return ( x - base ) % n + base | |
7 | ||
8 | - | position += mod( shmem.position - position, 2**32, -2**31 ) |
8 | + | |
9 | position += mod( shmem.position - position, 2**32 ) | |
10 | ||
11 | angle = position * 360 / PPR |