perry@well.UUCP (Perry S. Kivolowitz) (12/03/85)
The following is an implementation of bresenham's circle algorithm specifically tailored for use in generating spherical surfaces. It was part of a posting I sent to net.micro.amiga which simulated a kinetic toy (ya know, the one with five steel balls. raise one on one side and...) I do diffuse and specular shading on surfaces constructed using the below routine. This routine is easily modified to produce circles instead of scan-line displacements. /* ** b r e s . c ** ** perry s. kivolowitz - ihnp4!ptsfa!well!perry ** ** not to be distritbuted for commercial use. any distribution ** must included this notice, please. ** ** generate radial displacements according to bresenham's circle ** algorithm. suitable for running twice, giving a fast spherical ** surface. ** */ bres(r , array) register short *array; register r; { register x , y , d; x = 0; y = r; d = 3 - 2 * r; while (x < y) { *(array + r - y) = x; *(array + r - x) = y; *(array + r + y - 1) = x; *(array + r + x - 1) = y; if (d < 0) d += 4 * x + 6; else d += 4 * (x - y--) + 10; x++; } if (x == y) { *(array + r - y) = x; *(array + r + y - 1) = x; } }