draw a circle

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

draw a circle

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

Posts: 3099
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: draw a circle

Hi!

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

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