I am trying to make a bit of code that will randomly choose four points, one on each quadrant of the coordinate plane, and then draw a blue quadrilateral that connects the points. Eventually I would expand on it to randomly generate a small lake-like structure but I'm starting simple because I'm new. When I use 3 points to make a triangle it works fine, but adding a fourth point causes it to not draw at all. What am I missing?
Here is my code that is attached to my node2d
extends Node2D
#this will be the minimum distance from the origin of any point of the quadrilateral
export (int) var min_dist_from_origin = 20
#likewise, this is the max
export (int) var max_dist_from_origin = 100
#define a function to return a vector2 point in a given quadrant
func point_def(quad, mi, mx):
var pt = Vector2()
if (quad == 1) or (quad == 2):
pt.y = int(rand_range(mi,mx)) * (-1)
if (quad == 1) or (quad == 3):
pt.x = int(rand_range(mi,mx)) * (-1)
if (quad == 2) or (quad == 4):
pt.x = int(rand_range(mi,mx))
if (quad == 3) or (quad == 4):
pt.y = int(rand_range(mi,mx))
return pt
func _draw():
var box = PoolVector2Array()
# plot the first point in the first quadrant
box.append(point_def(1, min_dist_from_origin, max_dist_from_origin))
# plot the point in the next quadrant
box.append(point_def(2, min_dist_from_origin, max_dist_from_origin))
# plot the next point in the next quadrant
box.append(point_def(3, min_dist_from_origin, max_dist_from_origin))
### I can comment this part out and it will draw a triangle
box.append(point_def(4, min_dist_from_origin, max_dist_from_origin))
# draw our box
draw_colored_polygon(box,Color(0,0,255,1))
print(box)