Skip to content

Instantly share code, notes, and snippets.

@underdoeg
Last active July 22, 2020 16:26
Show Gist options
  • Save underdoeg/0a8f0a5c62c788a7775096d8dfccbcde to your computer and use it in GitHub Desktop.
Save underdoeg/0a8f0a5c62c788a7775096d8dfccbcde to your computer and use it in GitHub Desktop.
Draw a circle within Godot
tool
extends Control
var color_internal:Color = Color.red
export var color:Color = color_internal setget _set_color, _get_color
var res_internal:int = 50
export var resolution:int = res_internal setget _set_resolution, _get_resolution
func draw_circle_filled(center:Vector2, radius:Vector2, color:Color, numPoints:int = 50):
var width:float = 8
var points = PoolVector2Array()
points.resize(numPoints+1)
for i in range(numPoints+1):
var angle = deg2rad((i % 360) / float(numPoints) * 360.0)
points.set(i, center + Vector2(cos(angle), sin(angle)) * radius)
draw_colored_polygon(points, color, PoolVector2Array(), null, null, true)
func _get_color() -> Color:
return color_internal
func _set_color(c:Color) -> void:
color_internal = c
update()
func _get_resolution() -> int:
return res_internal
func _set_resolution(r:int) -> void:
res_internal = r
update()
func _draw():
draw_circle_filled(rect_size * .5, rect_size * .5, color_internal, res_internal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment