-1

I want to write my own Anti Aliasing Algorithm in C#. My picture has only two colors; black and white.

On Wikipedia (https://en.wikipedia.org/wiki/Spatial_anti-aliasing) I found the following pseudecode:

Define function PlotAntiAliasedPoint ( number x, number y )
    For roundedx = floor ( x ) to ceil ( x ) do
         For roundedy = floor ( y ) to ceil ( y ) do
              percent_x = 1 - abs ( x - roundedx )
              percent_y = 1 - abs ( y - roundedy )
              percent = percent_x * percent_y
              DrawPixel ( coordinates roundedx, roundedy, color percent (range 0-1) )

How do I implement this pseudocode in C#?

Tim Hovius
  • 721
  • 6
  • 16
  • 2
    It looks fairly self-explanatory. What specifically do you need help with? – Jashaszun Jun 29 '16 at 22:55
  • I dont understand the line `For roundedx = floor ( x ) to ceil ( x ) do` – Tim Hovius Jun 29 '16 at 22:57
  • 3
    It's just a normal `for` loop, like you would see in Python or Java or Javascript or C or C++, or ... really most languages. `for (int roundedx = Math.Floor(x); roundedx <= Math.Ceiling(x); roundedx++) { /* rest of stuff */ }` – Jashaszun Jun 29 '16 at 23:02
  • I think the article on Wikipedia is lacking some information about the variables. It's not obvious what are x and y and why they are decimal. At the first glance if (x,y) would be a point on an image for example (1024 x 768) I would think that x is an integer between 0 and 1024 and y an integer between 0 and 768 and the rounding would not make sense. So I don't understand why this question has negative rating. I can see why some people (myself included) have problems understanding this pseudocode algorithm. – Cristian Rusanu Jul 07 '17 at 09:23

1 Answers1

0
private void PlotAntiAliasedPoint(decimal x, decimal y)
{
  for (var roundedx = Math.Floor(x); roundedx <= Math.Ceiling(x); roundedx++)
  {
    for (var roundedy = Math.Floor(y); roundedy <= Math.Ceiling(y); roundedy++)
    {
      var percent_x = 1 - Math.Abs(x - roundedx);
      var percent_y = 1 - Math.Abs(y - roundedy);
      var percent = percent_x*percent_y;
      //DrawPixel(coordinates roundedx, roundedy, color percent(range 0 - 1))
    }
  }
}