I am working on a program where a circle must be drawn only within the walls(4 rectangles on the borders), I managed to get the circle to be drawn inside two walls(right and top borders), but the other remaining two it still goes through them. I thought that I could use a mix of logical operators inside ellipse(), and in circle_y and circle_x too, and return two different outputs, but no success. I would really appreciate if someone enlighten me on this problem.
diameter = 50
top_border = 50
bottom_border = 250
left_border = 50
right_border = 350
def setup():
size(400,300)
def circle_radius(diameter):
return diameter/2
def circle_x(x,diameter, left_border):
return max(x, left_border + circle_radius(diameter))
def circle_y(y, diameter, top_border):
return max(y, top_border + circle_radius(diameter))
def draw():
global diameter, top_border, bottom_border, left_border, right_border
background(100,50,0)
fill(50,25,0)
#draws all 4 borders
rect(0,0, width, top_border)
rect(0,bottom_border, width, height)
rect(0,0,left_border,height)
rect(right_border,0,width, height)
#draws circle
fill(255,0,0)
ellipse(circle_x(mouseX,diameter,left_border),circle_y(mouseY,diameter, top_border),diameter, diameter)