Anti-Aliased Circle

Share your ZGE-development tips and techniques here!

Moderator: Moderators

Post Reply
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Anti-Aliased Circle

Post by Kjell »

:idea:

A BitmapExpression generated Anti-Aliased Circle ( for square Bitmaps ).

Code: Select all

// Default Pixel values

this.Pixel.R = 1;
this.Pixel.G = 1;
this.Pixel.B = 1;
this.Pixel.A = 0;

// Calculate the radius of the current Pixel from the center

Radius = sqrt(pow(0.5-X-0.5/BitmapSize,2)+pow(0.5-Y-0.5/BitmapSize,2));

// Function for Pixels that are in the Anti-Aliased outer circle

if(Radius<0.5 && Radius>=0.5-AAWidth/BitmapSize){
  this.Pixel.A = (0.5-Radius)*BitmapSize/AAWidth;
}

// Aliased inner circle

if(Radius<0.5-AAWidth/BitmapSize){
  this.Pixel.A = 1;
}
Have fun ~
K
Attachments
AA1.gif
AA1.gif (2.98 KiB) Viewed 6312 times
AA4.gif
AA4.gif (4.7 KiB) Viewed 6312 times
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Looks good Kjell! AAWidth and BitmapSize are constants and their unit is pixels I presume?
Thanks for this first post in Tips'n'Tricks!
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hej Ville,

That's correct. The BitmapSize constant should be 256 when using a 256x256 Bitmap, and AAWidth represents the width in Pixels of the soft-edge / gradient.

K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

thanks Kjell.., I was thinking to do a plain circle with a clamp,. but this is even better with nice edges,. sweet!

What are you working on ? I for one would love to see a demo,. <knudge, knudge> contact me through email if you don't want to post it public,. .

peace
iterationGAMES.com
Post Reply