- Edited
Hello. Please help me apply a radial gradient to a centered polygon. Now everything looks as I intended. But there is one unsolved problem: In this line poly.uv = _Points.scale(poly.polygon, Vector2(0.6, 0.6)),
I took the number 0.6 from my head. I don't understand if it is really correct and how to get it mathematically. Thank you![
` var width = 600
var gradient = Gradient.new()
gradient.colors = PackedColorArray([Color.RED, Color.GREEN])
var texture = GradientTexture2D.new()
texture.fill = GradientTexture2D.FILL_RADIAL
texture.fill_from = Vector2(0.5, 0.5)
texture.fill_to = Vector2(1, 1).normalized()
texture.gradient = gradient
texture.width = width
texture.height = width
var poly = Polygon2D.new()
poly.polygon = PackedVector2Array([Vector2(-width/2, -width/2), Vector2(width/2, -width/2), Vector2(width/2, width/2),Vector2(-width/2, width/2)])
poly.texture_offset = Vector2(width, width)/2
poly.uv = _Points.scale(poly.polygon, Vector2(0.6, 0.6))
poly.texture = texture
poly.position = Vector2(1500, 500)
add_child(poly)`