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

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;

``````
if (circleIsShrinking) vision = vision -0,2;
else vision = vision +0,2;

if (vision == 0 || vision == 150) circleIsShrinking = !circleIsShrinking;

print (vision);
``````

I also tried

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

1 Like

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.

3 Likes

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

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.

1 Like

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

Use β0.2β or β-0.2β not β0,2β or β-0,2β

3 Likes

something like this ?

``````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;
}
}

``````

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

1 Like