# Entering two different outputs inside one variable?

**URL:** <https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849>\
**Category:** Processing.py\
**Tags:** homework\
**Created:** [February 16, 2020, 1:03am UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849 "2020-02-16T01:03:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![macedorrn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/macedorrn/32/8097_2.png) [@macedorrn](https://discourse.processing.org/u/macedorrn)\
**Post date:** [February 16, 2020, 1:03am UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/1 "2020-02-16T01:03:14Z")

</div>

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.

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [February 16, 2020, 1:47am UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/2 "2020-02-16T01:47:18Z")

</div>

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:

```auto
def circle_x(x):
    if x-diameter/2 < left_border:
        return left_border + circle_radius(diameter)
    elif x+diameter/2 > right_border:
        return right_border - circle_radius(diameter)
    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()`](https://processing.org/reference/circle_.html) function if you’re not drawing ellipses. It’s fairly new to Processing, but it’s handy.

---

<div class="post-metadata">

**Author:** ![macedorrn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/macedorrn/32/8097_2.png) [@macedorrn](https://discourse.processing.org/u/macedorrn)\
**Post date:** [February 16, 2020, 5:52am UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/3 "2020-02-16T05:52:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 16, 2020, 11:56pm UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/4 "2020-02-16T23:56:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![macedorrn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/macedorrn/32/8097_2.png) [@macedorrn](https://discourse.processing.org/u/macedorrn)\
**Post date:** [February 17, 2020, 1:21am UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/5 "2020-02-17T01:21:49Z")

</div>

Okay, good to know!  
Thank you!

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 29, 2020, 5:47pm UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/6 "2020-03-29T17:47:44Z")

</div>

Hi @macedorrn – just FYI, we updated our [homework FAQ](https://discourse.processing.org/faq#homework) – you are still encouraged to ask future homework related questions if you follow the guidelines!

---

<div class="post-metadata">

**Author:** ![macedorrn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/macedorrn/32/8097_2.png) [@macedorrn](https://discourse.processing.org/u/macedorrn)\
**Post date:** [April 7, 2020, 5:19pm UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/7 "2020-04-07T17:19:14Z")

</div>

I think the page is down or something, because I can’t access it.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 7, 2020, 9:39pm UTC](https://discourse.processing.org/t/entering-two-different-outputs-inside-one-variable/17849/8 "2020-04-07T21:39:20Z")

</div>

Sorry – I think that fixed the link.
