Auto generate circular tilemap?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Christoffer

Hi people! i need some assistance, how would i go about auto generating a round / circular tilemap ? i already have 2 for loops that make a square grid and change the color depending on that noise value it has, but what i want is this tilemap to be a perfect circle.
Thanks!

:bust_in_silhouette: Reply From: Christoffer

This was answered by TwistedTwigleg at the forums
Forumlink

You’ll probably need to use a normal tile, but place tiles in a
circular pattern instead of a square. That way the map appears to be
circular, while in reality it is still a square Tilemap.

There are several different ways you could generate a circular shape
within a Tilemap, but the easiest is probably to check if the tile
position is within the radius of the circle for every tile in the
loops.

Something like this, assuming the center of the circle is the origin
of the Tilemap (untested):

# This defines how many tiles are roughly within the radius of the circle
const CIRCLE_RADIUS = 10
for x in range(0, tilemap_width):
    for y in range(0, tilemap_height):
        var tile_coords = Vector2(x, y)
        if tile_coords.length() <= CIRCLE_RADIUS:
            # The tile is within the radius of the circle, so add a tile here
            # (or whatever you need to do for tiles within the circle's radius)
            place_tile(x, y)
        else:
            # The tile is not within the radius of the circle, so ignore the tile
            pass

That said, it is not going to be a perfect circle, as the edges will
still be made up of many square tiles. If you want something closer to
a perfect circle, you’ll need to have the edges of the circle use
differently shaped tiles so it appears smoother. I would suggest
looking at something like Marching Squares (Wikipedia) and/or Godot’s
auto tile functionality (KidsCanCode).