Page 1 of 1
draw a circle
Posted: Sun Sep 20, 2015 2:30 pm
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
Re: draw a circle
Posted: Thu Sep 24, 2015 3:34 pm
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 } }
}
Re: draw a circle
Posted: Sun Sep 27, 2015 2:33 pm
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
Re: draw a circle
Posted: Tue Sep 29, 2015 12:49 pm
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