# Fade in/out effect

**URL:** <https://discourse.processing.org/t/fade-in-out-effect/11483>\
**Category:** Coding Questions\
**Created:** [May 22, 2019, 2:25am UTC](https://discourse.processing.org/t/fade-in-out-effect/11483 "2019-05-22T02:25:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![clueless\_coder](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@clueless\_coder](https://discourse.processing.org/u/clueless_coder)\
**Post date:** [May 22, 2019, 2:25am UTC](https://discourse.processing.org/t/fade-in-out-effect/11483/1 "2019-05-22T02:25:06Z")

</div>

So I have this code and I’m trying to make the text fade in and out. I could make in fade in but I couldn’t make it fade out. Could anyone help me?

```auto
int t=10; //transparency
void setup()
{
  size(200,200);
}
void draw()
{
  if(t<=255)
  {
    t=t+1;
    fill(23,45,67,t);
    text("help",10,100);
  }
  else if(t>255)
  {
    t=t-1;
    fill(23,45,67,t);
    text("help",10,100);
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 22, 2019, 2:35am UTC](https://discourse.processing.org/t/fade-in-out-effect/11483/2 "2019-05-22T02:35:15Z")

</div>

hi,  
besides that a code is better readable if it is formatted,  
you need to work on the  
if else…  
[https://processing.org/reference/else.html](https://processing.org/reference/else.html)

and best is you use a println("");  
to check how any logic you code turn out.

or other way could be to take out the text("",x,y);  
after the if () fill…  
and make it a

```auto
text("help, t: "+t,10,100);

```

---

<div class="post-metadata">

**Author:** ![clueless\_coder](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@clueless\_coder](https://discourse.processing.org/u/clueless_coder)\
**Post date:** [May 22, 2019, 2:45am UTC](https://discourse.processing.org/t/fade-in-out-effect/11483/3 "2019-05-22T02:45:17Z")

</div>

sorry! I wasn’t sure how to keep the format since I’ve just made an account but maybe it’s easier to understand now. I’m not sure how to fix my ‘if’ statement because to my understanding, the value of t would keep adding until it reaches 255, and will start to decrease once it hits over 255. I’m not sure if there’s anything wrong with that logic, so maybe you could help me check over my line of thinking?

---

<div class="post-metadata">

**Author:** ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)\
**Post date:** [May 22, 2019, 5:52am UTC](https://discourse.processing.org/t/fade-in-out-effect/11483/4 "2019-05-22T05:52:57Z")

</div>

Explanation

Why the text couldnt fade out is caused by if else logic.  
When t reached 256 (t \> 255), it will back to 255 and then it will be back again to 256, because it does qualified to enter the `else` part where the t should be greater than 255. When t is 255 it enters `if` part rather than `else` part  
So after the text faded in, it will be back and forth between 255 and 256.

Try

> [@kll](#):
>
> text("help, t: "+t,10,100);

@kll has posted or  
Print the `t` to see what happen

---

<div class="post-metadata">

**Author:** ![clueless\_coder](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@clueless\_coder](https://discourse.processing.org/u/clueless_coder)\
**Post date:** [May 22, 2019, 3:37pm UTC](https://discourse.processing.org/t/fade-in-out-effect/11483/5 "2019-05-22T15:37:03Z")

</div>

Thank you for clarifying that! I’ll try to fix my ‘if’ and check the value of t
