Drawing_circles script (filled or not filled)

How to find or create sprites, graphics, sounds and music.

Drawing_circles script (filled or not filled)

Postby Hblade » Thu Feb 19, 2015 2:30 am

Here's how you can draw circles using a script I made.

Code: Select all
#define pi 3.14159265359

void draw_circle_filled(int X, int Y, int R, int G, int B, double A, double rad, int smooth)
{
    double i;
    moveto(X, Y);
    setpen(R, G, B, A, 3+smooth);
    for(i=0;i<pi*2;i+=pi/rad/(pi/3))
    {
        moveto(X, Y);
        lineto(X+cos(i)*rad, Y+sin(i)*rad);
    }
}
void draw_circle(int X, int Y, int R, int G, int B, double A, double rad, int smooth)
{
    double i;
    moveto(X, Y);
    setpen(R, G, B, A, 1+smooth);
    for(i=0;i<pi*2;i+=pi/rad/(pi))
    {
        putpixel(X+cos(i)*rad, Y+sin(i)*rad);
    }
}


Copy and paste this to the global code area in game-editor.

to draw a non-filled Circle, use this:

draw_circle(x, y, r, g, b, tra, radius, smoothing);
circle1.png



the smoothing value makes it slightly larger.

to make a filled circle, use this:
draw_circle_filled(x, y, r, g, b, tra, radius, smoothing);

circle2.png




likewise the smoothing value makes it smoother.


Screenshots:

seen above.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Drawing_circles script (filled or not filled)

Postby tvz » Thu Feb 19, 2015 7:38 am

Thanks for sharing this, i did not know how to fill a circle, but now i do.

I could not resist so i am asking, Could you draw the circle or just a straight line which is Anti-aliased? I tried doing it once but the results were strange/unsuccessful.
I was inactive on forums due exams
I have not left.
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Drawing_circles script (filled or not filled)

Postby Hblade » Thu Feb 19, 2015 10:14 am

I can try
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Drawing_circles script

Postby themightymekon » Sat Mar 21, 2015 12:23 pm

Thanks Hblade,

for that script. It will save me and others a bit of work, when we want to place a circle which maybe alters its radius, colour or other attributes.

I wrote a tutorial years ago, which described the principle. It may have used a slightly different code for the calculation.

If I can dig that up, I will try and attach it for anyone who is interested.



Regards, themightymekon :idea:
User avatar
themightymekon
 
Posts: 40
Joined: Sat May 10, 2014 11:29 am
Score: 2 Give a positive score


Return to Game Resources

Who is online

Users browsing this forum: No registered users and 1 guest

cron