Code: Select all
// bitmap variables
int width = 128;
float aawidth = 2;
// algo variables
int sprockets = 7;
int centeroffset = 1;
// default color
this.pixel.r = 1;
this.Pixel.g = 1;
this.pixel.b = 1;
this.Pixel.A = 0;
//
// other variables
float this_angle;
int this_sprocket;
float normalx, normaly;
float distance;
float aadist = aawidth / width;
float angle =( 2 * PI )/ sprockets;
float maxdist = cos( angle / 2.0 )* 0.5;
float center = 0.5 -( 1.0 * centeroffset / width );
//
// determine angle of current pixel to center
if( this.x - 0.5 >= 0 )
this_angle = atan2(( this.x - 0.5 ),( this.y - center ));
else
this_angle = PI + atan2(( 0.5 - this.x ),( center - this.y ));
// determine sprocket of current pixel
this_sprocket = (( this_angle )/ angle );
// calculate normal of current sprocket
normalx = sin(( angle * this_sprocket )+( angle / 2.0 ));
normaly = cos(( angle * this_sprocket )+( angle / 2.0 ));
// calculate distance of current pixel by dot product with normal
distance =(( this.x - 0.5 )* normalx )+(( this.Y - center )* normaly );
// set alpha accordingly
if( distance < maxdist ) this.pixel.a = ( maxdist - distance )/ aadist;
this.Pixel.R *= this.Pixel.A;
this.Pixel.G *= this.Pixel.A;
this.Pixel.B *= this.Pixel.A;