# Entering two different outputs inside one variable?

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)

return diameter/2

def circle_x(x,diameter, left_border):

def circle_y(y, diameter, top_border):

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)
``````
1 Like

There are different ways you could approach this, but Iâ€™ve tried to deviate as little as possible from your code. Hereâ€™s a working version for the x-coordinates:

``````def circle_x(x):
if x-diameter/2 < left_border:
elif x+diameter/2 > right_border:
return x

...

def draw():
...
ellipse(circle_x(mouseX), ...
``````

Your `diameter`, `top_border`, `bottom_border`, `left_border`, and `right_border` variables are in the global scope, so thereâ€™s no need to pass them to your functions. Also, you might prefer to use the `circle()` function if youâ€™re not drawing ellipses. Itâ€™s fairly new to Processing, but itâ€™s handy.

3 Likes

It helped a lot! Thanks for keeping it simple, since I am trying to do it as my own work and I donâ€™t want to risk violating any of my school policies or seem like as if itâ€™s cheating.

1 Like

Glad to hear, and good luck, @macedorrn.

Keep in mind that if you want to, for example, say â€śthis is homework, so please no complete answersâ€ť then you can just add that to your initial post and forum members should respect it.

2 Likes

Okay, good to know!
Thank you!

Hi @macedorrn â€“ just FYI, we updated our homework FAQ â€“ you are still encouraged to ask future homework related questions if you follow the guidelines!

2 Likes

I think the page is down or something, because I canâ€™t access it.

Sorry â€“ I think that fixed the link.