Line2D Bracket Generation

I am attempted to use Line2D to draw a bracket for a tournament based on the number of applicants. I want it to look like the following:

I would like some sort of algorithm to add a point for each applicant in a vertical line, and then build in from there, but I am unsure of how to do this without the entire thing being connected looking like a bunch of boxes. What would be the most ideal way of creating this?

I’m not sure, I understand this…? You already know about Line2D, so where exactly are you facing any problems here? :thinking:

I was struggling to find a way to add the entire bracket without every single point being connected, but I ended up figuring it out

Nice! If you got the time, maybe share your solution here? You never know who else might have the same (or a similar) problem and stumbles across this post. :slight_smile:

Sure thing! Below if my current implementation. If you have any tips on how to optimize please let me know:

extends VBoxContainer

var sizeAnchor = 8
var participants = 8
var newParticipants
var line
var playerName
var newLine = Vector2(100, 100)
var stepY = 400

func based_log(base, x) → float:
return (log(x) / log(base))

func next_log(base, x) → int:
var first = based_log(base, x)
return base ** ceil(first)

func _ready():
playerName =
playerName.position.x = playerName.position.x + 300
playerName.add_theme_font_size_override(“HELLO”, 50)
playerName.text = “SHEET”

while participants != 1:
	for i in participants / 2:
		line =
	# First Round
		line.add_point(Vector2(newLine.x, newLine.y + stepY*i))
		line.add_point(Vector2(newLine.x + 100, newLine.y + stepY*i))
		line.add_point(Vector2(newLine.x + 100, newLine.y * 3 + stepY*i))
		line.add_point(Vector2(newLine.x, newLine.y * 3 + stepY*i))

	newLine.x = newLine.x + 100
	newLine.y = newLine.y * 2
	stepY = stepY * 2
	newParticipants = participants / 2
	participants = newParticipants
line.add_point(Vector2(newLine.x, newLine.y + (100*sizeAnchor/2)))
line.add_point(Vector2(newLine.x, newLine.y))
line.add_point(Vector2(newLine.x + 100, newLine.y))

After your post, I thought to myself: “Wouldn’t this be an ideal situation to write a custom container node for?” And… so I did?!

Now, was this an ideal situation for a custom container? Hell no! I wasted way more time on this than I anticipated, and frankly, I’m not even sure if it will be all that useful to anyone. On one hand, it’s too specific to be a general purpose tool like the built-in containers, on the other hand it probably isn’t specific enough to satisfy all requirements one might have with tournament brackets.

But well, at the off-chance that you (or anyone else) might find this useful anyway, I’m sharing it here.