draw a circle

Pixilang programming language
Post Reply
kmatze
Posts: 47
Joined: Wed Jun 22, 2011 12:36 am

draw a circle

Post by kmatze »

high NR,
how can i draw a simple circle with pixilang (1.6, 2.0 or 3.5) like as

Draw a circle : circle( x1, y1, raduis, color )

for line and box there is a command/function:

Draw a line : line( x1, y1, x2, y2, color )

Draw a rectangle: box( x, y, xsize, ysize, color )

Thanks and greetings - kmatze
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: draw a circle

Post by NightRadio »

Hi!
Please try this:

Code: Select all

fn circle( $x, $y, $radius, $color )
{
    $steps = 128
    $i = 0 while $i <= $steps
    {
        $r = M_PI * 2 * ( $i / $steps )
        $xx = $x + cos( $r ) * $radius
        $yy = $y + sin( $r ) * $radius
        if $i > 0
        {
            line( $prev_x, $prev_y, $xx, $yy, $color )
        }
        $prev_x = $xx
        $prev_y = $yy
        $i + 1
    }
}

start_timer( 0 )

while 1
{
    t = get_timer( 0 ) / 1000
    transp( 32 )
    clear( BLACK )
    transp( 255 )
    circle( 0, 0, sin( t ) * 100, WHITE )
    frame()
    while get_event() { if EVT[ EVT_TYPE ] == EVT_QUIT { halt } }
}
kmatze
Posts: 47
Joined: Wed Jun 22, 2011 12:36 am

Re: draw a circle

Post by kmatze »

NightRadio wrote:Hi!
Please try this:

Code: Select all

fn circle( $x, $y, $radius, $color )
{...}
thanks, that's a wonderful solution.
Is it possible to create standard functions circle and fcircle in next version of pixilang in addition to box and fbox?

That would be great.

Thanks and greeting - kmatze
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: draw a circle

Post by NightRadio »

Is it possible to create standard functions circle and fcircle in next version of pixilang in addition to box and fbox?
Actually i don't think it is necessary, because you always can create it out of basic Pixilang blocks (line, fbox, etc.), like in the example above :)
I think we just need some additional library with advanced graphics functions. It is already available for OpenGL mode: lib/gl_primitives.pixi
Post Reply