Most ways of putting text around a circle, like the rune ring of a magic circle, give every letter the same angle. Letters are not the same width, so the gaps change. In our Godot 4.7 test, 27 letters of the default font at 24 px, from 6 to 23 px wide, at equal angles around a circle of 120 px radius had gaps of 7.4 to 18.4 px. Equal steps sized from the average width made the wide letters overlap, with gaps from -3.9 to 7.1 px. The script below gives each letter an arc as wide as itself plus the gap: 2.00 px between every pair, or 13.37 px all the way round with fill_circle.
The code
Add a Node2D, attach this script, and set text, radius and font_size in the Inspector. It is a @tool script, so the ring shows in the editor too. The letters stand on the circle facing outward, starting at start_degrees, where -90 is the top. Turn on fill_circle to spread them all the way round.
@tool
extends Node2D
## Text around a circle, like the rune ring of a magic circle, with the same gap between every pair of letters.
## Each letter gets an arc as wide as the letter itself, so a W and an I each take their own room.
@export var text := "AEGIS OF THE WANDERING MOON":
set(v):
text = v
queue_redraw()
@export var radius := 120.0:
set(v):
radius = v
queue_redraw()
@export var font: Font ## empty = the default font
@export var font_size := 24:
set(v):
font_size = v
queue_redraw()
@export var spacing := 2.0 ## pixels between letters, along the circle
@export var start_degrees := -90.0 ## where the first letter starts: -90 is the top
@export var fill_circle := false ## spread the letters all the way round
@export var color := Color.WHITE
func _font() -> Font:
return font if font else ThemeDB.fallback_font
## Returns [letter, angle of its centre in radians, its width] for every letter. The gap used is in gap_used.
var gap_used := 0.0
func layout() -> Array:
var f := _font()
var widths: Array[float] = []
var total := 0.0
for i in text.length():
var w := f.get_char_size(text.unicode_at(i), font_size).x
widths.append(w)
total += w
gap_used = spacing
if fill_circle and text.length() > 0:
gap_used = (TAU * radius - total) / text.length()
var out := []
var along := 0.0
for i in text.length():
var a := deg_to_rad(start_degrees) + (along + widths[i] * 0.5) / radius
out.append([text[i], a, widths[i]])
along += widths[i] + gap_used
return out
func _draw() -> void:
var f := _font()
for g in layout():
var a: float = g[1]
draw_set_transform(Vector2(cos(a), sin(a)) * radius, a + PI * 0.5)
draw_char(f, Vector2(-g[2] * 0.5, 0.0), g[0], font_size, color)
draw_set_transform(Vector2.ZERO)
What we measured
The words AEGIS OF THE WANDERING MOON, 27 letters with the spaces, in Godot's default font at 24 px: 6.0 to 23.0 px wide, 393 px in all, on a circle of 120 px radius, 754 px round. We measured the gap along the circle from each letter to the next. Two runs gave the same numbers.
- The same angle for every letter, spread over the whole circle: gaps from 7.4 to 18.4 px.
- The same angle for every letter, sized from the average width plus 2 px: gaps from -3.9 to 7.1 px, so some letters overlap.
- The script with 2 px spacing: every gap 2.00 px. The text covers 212 of the 360 degrees.
- The script with
fill_circle: every gap 13.37 px, from the last letter back to the first too. - The script at 60 px radius: 445 px of text on a circle 377 px round, so the first and last letters ended up 408 degrees apart and the text ran over itself.
- The node drawn in a scene: 869 lit pixels, so the letters render.
Why it happens
An angle on a circle is a length: the angle times the radius. Giving every letter the same angle gives every letter the same length, so a narrow I sits in a big space and a W fills its space edge to edge. Using each letter's own width from the font, Font.get_char_size(), for its arc keeps the space between letters the same. To fill the circle, share what is left of the circle equally between the gaps.
What to change
spacing: pixels between letters, measured along the circle.- The text runs over itself when it is longer than the circle: make the radius bigger or the font smaller. The 60 px test above shows how it looks in numbers.
- Each letter uses its own width, so kerning pairs like AV are not pulled closer.
- Spinning the ring: a Node2D that spins at the same speed for hours. A big magic circle texture that sparkles when small: mipmaps for a spinning magic circle.
Ready-made magic circles: PD Sigil Forge Pro generates magic circles in 8 styles and exports large PNGs, SVG and spinning animations.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: PD Sigil Forge Pro generates magic circles in 8 styles and exports large PNGs, SVG and spinning animations.
More how-tos: Auras, rings, beams and weather
- Light shaft cards without the bright edge-on line
- Stretch a bolt sprite from the caster to the target
- Space lights, posts or coins evenly along a Path3D
- Stop a big spinning texture from looking grainy when it is drawn small
- God rays without volumetric fog
- Dark horror fog that works in Compatibility
- Magic aura particles that circle a character
- Charge-up particles that fly in to the middle
- Particle ring standing up instead of flat
- 2D particles from a sprite's shape
- A glowing circle on the ground
- A loot beam that never goes flat
- Chain lightning between enemies
- A tower's attack range ring
- Enemy vision cone with a "!" when it spots you
- Rain that follows the camera
- Rain falling through the roof
- Snow particles not falling
- orbit_velocity not working in 3D: use tangential_accel
- Rain falls through the player
- Snow that stays on roofs
- Emit particles along a Path3D
- Ambient particles in many places from one emitter
- Keep a buff aura on until the last buff really runs out
- Spin a magic circle forever at the same speed
- Space flying swords, shields or orbs evenly around a character for any count