# Making my float increase then decrease so that my ellipses grows and then shrinks

**URL:** <https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701>\
**Category:** Coding Questions\
**Created:** [August 12, 2021, 6:28pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701 "2021-08-12T18:28:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [August 12, 2021, 6:28pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/1 "2021-08-12T18:28:33Z")

</div>

Here is the code I use to make ellipses grow and then shrink. I have already declared vision as a float with the starting value 0;

```auto

  if (circleIsShrinking) vision = vision -0,2;
  else vision = vision +0,2;
  
 
  if (vision == 0 || vision == 150) circleIsShrinking = !circleIsShrinking;
			
		print (vision);

```

I also tried

```auto
if (vision < 0 || vision > 150) circleIsShrinking = !circleIsShrinking;

```

but it does not work.  
In both cases the vision does not even start to increase in size

---

<div class="post-metadata">

**Author:** ![BrendanL](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/brendanl/32/14076_2.png) [@BrendanL](https://discourse.processing.org/u/BrendanL)\
**Post date:** [August 12, 2021, 7:35pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/2 "2021-08-12T19:35:53Z")

</div>

If you increment and decrement by 0.2 you might never get exactly 0 or 150. A good paper to read about this is [What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html).

---

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [August 12, 2021, 8:34pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/3 "2021-08-12T20:34:23Z")

</div>

I did take that into consideration so I used the \< and \> once too but it did not work either

---

<div class="post-metadata">

**Author:** ![BrendanL](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/brendanl/32/14076_2.png) [@BrendanL](https://discourse.processing.org/u/BrendanL)\
**Post date:** [August 12, 2021, 10:00pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/4 "2021-08-12T22:00:06Z")

</div>

Wait, you’re using “-0,2” and “+0,2” with commas between the digits? I don’t think that will work because Java and therefore Processing wants you to use periods to separate the whole part of a number from the fractional part of a number. So in essence your code is adding “+0” or “-0” to `vision` instead of 2 tenths.

---

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [August 12, 2021, 10:04pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/5 "2021-08-12T22:04:57Z")

</div>

I dont completely understand. You said im adding 0 to vision, so how do I add 0,2 instead?

---

<div class="post-metadata">

**Author:** ![BrendanL](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/brendanl/32/14076_2.png) [@BrendanL](https://discourse.processing.org/u/BrendanL)\
**Post date:** [August 12, 2021, 10:13pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/6 "2021-08-12T22:13:20Z")

</div>

Use “0.2” or “-0.2” not “0,2” or “-0,2”

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 12, 2021, 11:02pm UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/8 "2021-08-12T23:02:07Z")

</div>

@Kenga123456 hi

something like this ?

```auto
int inc = 1;
int x =0; 
void setup() { 
  size(600, 600);
  ellipseMode(CENTER);
} 
void draw() { 
  background(222); 
  x= x + inc; 
  fill(0,0 , 222);
    ellipse(300, 300, x, x); 
  if (x >= 400|| x <= 0 ) { 
    inc = inc * -1;
  }
}

```

---

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [August 13, 2021, 8:00am UTC](https://discourse.processing.org/t/making-my-float-increase-then-decrease-so-that-my-ellipses-grows-and-then-shrinks/31701/9 "2021-08-13T08:00:51Z")

</div>

Yup that worked, though I also had to fix some problems within the entire program first. Thank you!
