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
draw a circle
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: draw a circle
Hi!
Please try this:
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 } }
}
Re: draw a circle
thanks, that's a wonderful solution.NightRadio wrote:Hi!
Please try this:Code: Select all
fn circle( $x, $y, $radius, $color ) {...}
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
- NightRadio
- Site Admin
- Posts: 3955
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: draw a circle
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 :)Is it possible to create standard functions circle and fcircle in next version of pixilang in addition to box and fbox?
I think we just need some additional library with advanced graphics functions. It is already available for OpenGL mode: lib/gl_primitives.pixi