Is there a way to draw a partial circle (like a pie slice)

mutazoid

Member
Is there a way to draw a partial circle. So the end result will look like a pacman or pie slice?

Thanks.
:)
 
G

Galax

Guest
This is based around health bars but you can make it useful for what you're making. Have fun!

Code:
/// draw_pie(x ,y ,value, max, colour, radius, transparency)

if (argument2 > 0) { // no point even running if there is nothing to display (also stops /0
    var i, len, tx, ty, val;
    
    var numberofsections = 60 // there is no draw_get_circle_precision() else I would use that here
    var sizeofsection = 360/numberofsections
    
    val = (argument2/argument3) * numberofsections
    
    if (val > 1) { // HTML5 version doesnt like triangle with only 2 sides
    
        draw_set_colour(argument4);
        draw_set_alpha(argument6);
        
        draw_primitive_begin(pr_trianglefan);
        draw_vertex(argument0, argument1);
        
        for(i=0; i<=val; i++) {
            len = (i*sizeofsection)+90; // the 90 here is the starting angle
            tx = lengthdir_x(argument5, len);
            ty = lengthdir_y(argument5, len);
            draw_vertex(argument0+tx, argument1+ty);
        }
        draw_primitive_end();
        
    }
    draw_set_alpha(1);
}
To call it then do
Code:
draw_pie(x ,y ,health, 100, c_red, 20, 1)
 

mutazoid

Member
Im still very bad at understanding scripts but I got this to draw a circle, but Im not seeing anyway to control amount of the circle I want it to draw.
 

obscene

Member
I don't like the way either of these scripts work. The better idea would be to draw a primitive. Your first point is the center of the pie. The rest of the points would be determined with lengthdir functions with the radius of the pie and a series of angles from the minimum and maximum angle of the slice. The more precise you wanted the round Edge to be the more points you would need.
 
J

Jmation

Guest
Here is a quick version that works. Just create a segment sprite or just a line then duplicate it, rotating 1 degree until you build a circle.

Code:
create event
==============
//how far to build pie/circle
pie_degrees=270;

draw event
===========
//starting angle for pie creation
start_angle=0;
//repeat until pie is built
repeat pie_degrees
    {
    //draw segment of pie--I created a 1 degree pie segment sprite with the centre at top left
    draw_sprite_ext(spr_pie_section,0,x,y,1,1,start_angle,c_white,1);
    //offset to draw next sprite
    start_angle+=1;
 
    }
 
Last edited by a moderator:

simes007us

Member
Dumb question. How do you get this to fill the other way? It currently fills counter clockwise and I would like clockwise.

Thanks,

Simon
 

Nidoking

Member
You'd change start_angle+=1 to start_angle-=1.
You could also make it a script that lets you pass in start_angle as well as pie_degrees.
 
Top