// 256 steps for 360 degrees #define deg_90 64 #define deg_180 128 #define deg_270 192 /* table of sine values from 0 to 90 degrees */ const unsigned sine_table[] = { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 59, 62, 65, 67, 70, 73, 75, 78, 80, 82, 85, 87, 89, 91, 94, 96, 98, 100, 102, 103, 105, 107, 108, 110, 112, 113, 114, 116, 117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 125, 126, 126, 126, 126, 126 }; int do_div(int n, unsigned d) { int r = n / d; return(r); } /* temp values used becuase of compiler limitations */ /* returns the sine of an angle + 128 */ unsigned sine(unsigned a, unsigned scale) { if (a < 64) // first quad { int s = do_div(sine_table[a], scale); return(128 + s); } else if (a < 128) // first quad (mirror x) { int s = do_div(sine_table[127 - a], scale); return(128 + s); } else if (a < 192) // third quad offset 180 degrees { int s = do_div(sine_table[a - 128], scale); return(128 - s); } else // forth quad mirror x { int s = do_div(sine_table[255 - a], scale); return(128 - s); } } /* enf of sin */