# how plot a circle in Array?

## Recommended Posts

Hi, this is for a math experts!

If you have an array[64][64] empty (the size is hiphotetics..., can be any size)

All position is initialy empty or zero.

How to plot this circles in this array (center is a red dot).

a] plot a full circle in array
b] plot a half circle in array
c] plot a inclinade half circle

Someone have any idea?

```#include <Array.au3>

Global \$iSize = 32
Global \$aArray[\$iSize][\$iSize]
Global \$aCenter[2] = [Floor(\$iSize / 2), Floor(\$iSize / 2)]

plot_circle(\$aCenter[0], \$aCenter[1], \$aCenter[0])

_ArrayDisplay(\$aArray)

Func plot_circle(\$iXX, \$iYY, \$iRadius, \$iMode = 0)
Switch \$iMode
Case 0 ; full circle
Case 1 ; half circle
Case 2 ; inclinade half circle
EndSwitch

EndFunc   ;==>plot_circle```

Br, Luigi

Edited by Luigi

Visit my repository

##### Share on other sites

Why on hell do you want to "draw" into an array?

Anyhow, here we go:

```#include <Array.au3>

Global Const \$fPi = ACos(-1), \$fD2R = \$fPi / 180
Global \$aGfxArray[21][21]

DrawEllipseToArray(\$aGfxArray, 10) ;full ellipse
_ArrayDisplay(\$aGfxArray, "full ellipse")

Global \$aGfxArray[21][21]
DrawEllipseToArray(\$aGfxArray, 10, 90, 270) ;half ellipse
_ArrayDisplay(\$aGfxArray, "half ellipse")

Global \$aGfxArray[21][21]
DrawEllipseToArray(\$aGfxArray, 10, 90 - 45, 270 - 45) ;inclinade half ellipse

Func DrawEllipseToArray(ByRef \$aArray, \$iRadius, \$iStartAngle = 0, \$iEndRadius = 359, \$iColor = 0xFF00FF00, \$iColor_Center = 0xFFFF0000)
Local \$d, \$iW2 = Int(UBound(\$aArray, 2) / 2), \$iH2 = Int(UBound(\$aArray, 1) / 2), \$iX, \$iY
For \$d = \$iStartAngle To \$iEndRadius
\$iX = Round(\$iW2 + Sin(\$d * \$fD2R) * \$iRadius, 0)
\$iY = Round(\$iH2 + Cos(\$d * \$fD2R) * \$iRadius, 0)
\$aArray[\$iY][\$iX] = \$iColor
Next
\$aArray[\$iH2][\$iW2] = \$iColor_Center
EndFunc```

Pay attention to the function DrawEllipseToArray - it has no error checks!

Edited by UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

Thank you UEZ! Its work!

Visit my repository

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...