> For the complete documentation index, see [llms.txt](https://docs.settlers-united.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.settlers-united.com/s4-lua-api-de/tutorials/code-snippets/all-points-in-a-circle-hexagon.md).

# All Points in a circle/ring (hexagon)

## circle(x, y, radius, func)                    ![](/files/UdLMrJ93c2eLmDQfTvJE)

Führt die Funktion `func` auf der gesamten **Fläche** des Kreises (Hexagons) um die angegebenen Koordinaten im entsprechenden `radius` aus.

* `radius`: 0 nur aktuelles Feld, 1 für den ersten umliegenden Kreis, usw.
* `func`: wird mit den Parametern x,y des jeweiligen Punktes der Fläche aufgerufen

<details>

<summary>Beispiel: circle(x, y, radius, func)</summary>

```lua
function createSlimeball(x, y)
  Effects.AddEffect(Effects.SLIMEBALL, Sounds.NO_SOUND, x, y, 0)
end

function new_game()
    circle(128, 128, 5, createSlimeball)
end
```

oder in kurz und unleserlich

```lua
function new_game()
  circle(128,128,5,function(x,y)
                    Effects.AddEffect(Effects.SLIMEBALL,Sounds.NO_SOUND,x,y,0)
                  end
  )
end
```

```lua
function circle(x, y, radius, func)
    local r = radius + 1
    local xorig = x
    local yorig = y
    local iterations = 2 * r - 1
    local i = iterations
    local left = r - 1
    local right = 0
    while i > 0 do
        local cx = xorig - left;
        local cy = yorig + r - i;
        while cx <= xorig + right do
            func(cx,cy)
            cx = cx + 1
        end
        if right == r - 1 then
            left = left - 1
        else
            right = right + 1
        end
        i = i - 1
    end
end
```

</details>

## ring(x, y, radius, func)                       ![](/files/14tCT1OjKqtEV3eXYfeN)

Führt die Funktion `func` auf dem **Umkreis** (Hexagons) um die angegebenen Koordinaten im entsprechenden `radius` aus.

* `radius`: 0 nur aktuelles Feld, 1 für den ersten umliegenden Kreis, usw.
* `func`: wird mit den Parametern x,y des jeweiligen Punktes des Umkreises aufgerufen

<details>

<summary>Beispiel: ring(x, y, radius, func)</summary>

```lua
function createSlimeball(x,y)
  Effects.AddEffect(Effects.SLIMEBALL,Sounds.NO_SOUND,x,y,0)
end

function new_game()
    ring(128,128,5,createSlimeball)
end
```

oder in kurz und unleserlich

```lua
function new_game()
  ring(128,128,5,function(x,y)
                    Effects.AddEffect(Effects.SLIMEBALL,Sounds.NO_SOUND,x,y,0)
                  end
  )
end
```

```lua
function ring(x, y, radius, func)
  local r = radius + 1
  local xorig = x
  local yorig = y
  local iterations = 2 * r - 1
  local i = iterations
  local left = r - 1
  local right = 0
  local row = 0
  while i > 0 do
    local cx = xorig - left
    local cy = yorig + r - i
    local last = (xorig + right) - cx
    local col = 0
    while cx <= xorig + right do
      if row == 0 or row == iterations - 1 then
        func(cx, cy)
      elseif col == 0 or col == last then
        func(cx, cy)
      end
      cx = cx + 1
      col = col + 1
    end
    if right == r - 1 then
      left = left - 1
    else
      right = right + 1
    end
    i = i - 1
    row = row + 1
  end
end
```

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.settlers-united.com/s4-lua-api-de/tutorials/code-snippets/all-points-in-a-circle-hexagon.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
