Page 1 of 1

Drawing functions: drawing circles and more...

PostPosted: Wed Dec 10, 2008 9:00 pm
by asmodeus
I think, there aren't enough drawing functions in GE, so I made a little script with some basic colors and two functions: drawRectangle(x1, y1, x2, y2), drawCircle(x, y, r).
Here is the script:
Code: Select all
#define RED 255, 0, 0
#define GREEN 0, 255, 0
#define BLUE 0, 0, 255
#define YELLOW 255, 255, 0
#define PURPLE 255, 0, 255
#define AQUA 0, 0, 255
#define ORANGE 255, 127, 0
#define WHITE 255, 255, 255
#define BLACK 0, 0, 0
#define DARKRED 127, 0, 0
#define DARKGREEN 0, 127, 0
#define DARKBLUE 0, 127, 0
#define DARKYELLOW 127, 127, 0
#define DARKPURPLE 127, 0, 127
#define DARKAQUA 0, 0, 255
void drawCircle(double xpos, double ypos, double r)
{
  int xp, yp;
  for(yp=floor(ypos)-ceil(r);yp<ceil(ypos)+ceil(r);yp++)
   for(xp=floor(xpos)-ceil(r);xp<ceil(xpos)+ceil(r);xp++)
    if(sqrt(pow(max(xpos, xp)-min(xpos, xp), 2)+pow(max(ypos, yp)-min(ypos, yp), 2))<=r) putpixel(xp, yp);
}
void drawRectangle(double x1, double y1, double x2, double y2)
{
  int xp, yp;
  if(max(x1, x)-min(x1, x2)<max(y1, y2)-min(y1, y2)) // draw vertical lines
  {
    for(xp=min(x1, x2);xp<max(x1, x2);xp++)
    {
      moveto(xp, min(y1, y2));
      lineto(xp, max(y1, y2));
    }
  }
  else // draw horizontal lines
  {
    for(yp=min(y1, y2);yp<max(y1, y2);yp++)
    {
      moveto(min(x1, x2), yp);
      lineto(max(x1, x2), yp);
    }
  }
}

You have to copy it to a global code.

Maybe I will try to make some more functions and constants for it.

And, what do you think about this? Do you think, I could have made the circle functions myself (and even better), do you think, you can need my functions and constants? Please tell me your opinions. You could also make suggestions for more functions and constants, that I could try to make.

Re: Drawing functions: drawing circles and more...

PostPosted: Fri Dec 12, 2008 11:02 pm
by jimmynewguy
can you put this in a .ged file, for some reason i cant get it to work.......... :oops:
i posted the code in global and i tried to draw a circle on a canvas, and nothing happend srry :P

Re: Drawing functions: drawing circles and more...

PostPosted: Sat Dec 13, 2008 11:15 am
by asmodeus
Here is the ged file.
drawing.zip
(2.08 KiB) Downloaded 140 times

Re: Drawing functions: drawing circles and more...

PostPosted: Sun Dec 14, 2008 2:30 pm
by jimmynewguy
thanx pretty neat i never knew how to do that :D :mrgreen:

Re: Drawing functions: drawing circles and more...

PostPosted: Fri Feb 13, 2009 9:05 pm
by BloodRedDragon
I don't get this. I tried copying the exact same code into my game and it does not recognise the variable "drawRectangle"
Help!

Re: Drawing functions: drawing circles and more...

PostPosted: Sat Feb 14, 2009 3:02 am
by skydereign
xenie357, not sure if you still need this but here it is. It just tells it not to put a pixel if it is in a smaller circle.
Code: Select all
void drawCircle(double xpos, double ypos, double r, double R) // Note there is another variable, R is the radius of the inner/smaller 'cut out' circle
{
    int xp, yp;
    for(yp=floor(ypos)-ceil(r);yp<ceil(ypos)+ceil(r);yp++)
    {
        for(xp=floor(xpos)-ceil(r);xp<ceil(xpos)+ceil(r);xp++)
        {
            if(sqrt(pow(max(xpos, xp)-min(xpos, xp), 2)+pow(max(ypos, yp)-min(ypos, yp), 2))<=r)  // This says put a pixel if it is within the circle, radius of r
            {
                if(sqrt(pow(max(xpos, xp)-min(xpos, xp), 2)+pow(max(ypos, yp)-min(ypos, yp), 2))>=R)  // This says put a pixel if it is outside of the 'cut out' circle,  radius R
                {
                         putpixel(xp, yp);  // Puts the actual pixels in
                }
            }
        }
    }
}

Re: Drawing functions: drawing circles and more...

PostPosted: Sun Feb 15, 2009 11:38 am
by Bee-Ant
Great :shock: