@Christoffer said:
This example only makes the squares look like a pizza slice :P
i will look at this tomorrow and see if i can figure out what to do next :)
After looking at the code and running it in a test project, I realized the code only calculates in the bottom right quadrant of the circle, which is why it produces a pizza slice. :sweat_smile:
Adding a few more loops fixes it. I also moved the process into a function and wrote the code so the starting position, radius, and tile ID are easily changeable.
extends TileMap
func _ready():
make_tilemap_circle(Vector2(0, 0), 10, 0);
func make_tilemap_circle(center_position, radius, tile_id=0):
# The right half of the circle:
for x in range(center_position.x, center_position.x + radius):
# The bottom right half of the circle:
for y in range(center_position.y, center_position.y + radius):
var relative_vector = Vector2(x, y) - center_position;
if (relative_vector.length() < radius):
self.set_cell(x, y, tile_id);
# The top right half of the circle
for y in range(center_position.y - radius, center_position.y):
var relative_vector = center_position - Vector2(x, y);
if (relative_vector.length() < radius):
self.set_cell(x, y, tile_id);
# The left half of the circle
for x in range(center_position.x - radius, center_position.x):
# The bottom left half of the circle:
for y in range(center_position.y, center_position.y + radius):
var relative_vector = Vector2(x, y) - center_position;
if (relative_vector.length() < radius):
self.set_cell(x, y, tile_id);
# The top left half of the circle
for y in range(center_position.y - radius, center_position.y):
var relative_vector = center_position - Vector2(x, y);
if (relative_vector.length() < radius):
self.set_cell(x, y, tile_id);