Drawing concentric rectangles

BlitzMax Forums/BlitzMax Programming/Drawing concentric rectangles

ImaginaryHuman(Posted 2006) [#1]
Assuming that I'm using a pixmap, I've made a simple routine that goes through every pixel in the pixmap and draws pixels of a color which is basically the distance from the center. So the middle is white and then it is surrounded by concentric circles gradually fading out, and all pixels in the pixmap are filled. The radius can be different in X and Y (ie both have scaling) to allow ellipses.

I need to do the same thing but so that the end result is a rectangle (or square with separate x/y stretching). I cannot see how to do it. It must do the same pass through all the pixels and at each pixel should perform some calculation to render the pixel based on - in some way - the distance from the center, but not to produce circles. I do not want to draw lots of filled rectangles on top of each other, each pixel in the destination must be touched once only.

Whereas Sqr((XDiff*XDiff)+(YDiff*YDiff)) gives circles, what would give rectangles?


Dreamora(Posted 2006) [#2]
For rectangles you could use your ellipse calculations.

Because the bounding rectangle of such an ellipse exactly defines the rectangle and its color you are looking for :)

rectangles are just a simplified version of the ellipse, because the only values you calculate are the ones directly on the x and y axis.


ImaginaryHuman(Posted 2006) [#3]
Um, yeah. lol Finding bounding boxes sounds way overcomplicated. I needed to do away with the whole ellipse thing.

Actually I figured it out:

Max(XDiff,YDiff)

creates a rectangle, although I found I had to swap the x and y scale factors around to make it stretch correctly. I figured it was something simple but I wasn't getting it right with Min(XDiff,YDiff) (creates a `cross`, kinda of an inversed square).