Drawing functions: drawing circles and more...

You must understand the Game Editor concepts, before post here.

Drawing functions: drawing circles and more...

Postby asmodeus » Wed Dec 10, 2008 9:00 pm

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.
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

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

Postby jimmynewguy » Fri Dec 12, 2008 11:02 pm

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
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

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

Postby asmodeus » Sat Dec 13, 2008 11:15 am

Here is the ged file.
drawing.zip
(2.08 KiB) Downloaded 140 times
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

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

Postby jimmynewguy » Sun Dec 14, 2008 2:30 pm

thanx pretty neat i never knew how to do that :D :mrgreen:
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

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

Postby BloodRedDragon » Fri Feb 13, 2009 9:05 pm

I don't get this. I tried copying the exact same code into my game and it does not recognise the variable "drawRectangle"
Help!
Current projects:
Techno-Tank Arena: on hold
Techno-Tank SuperPortal (working title): 0.1%
Bowels of Galaxies: 35% (was a bit too optimistic)
User avatar
BloodRedDragon
 
Posts: 123
Joined: Tue Jan 29, 2008 10:07 pm
Location: The Underworld
Score: 5 Give a positive score

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

Postby skydereign » Sat Feb 14, 2009 3:02 am

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
                }
            }
        }
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby Bee-Ant » Sun Feb 15, 2009 11:38 am

Great :shock:
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest