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.


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”


@Kenga123456 hi

something like this ?

int inc = 1;
int x =0; 
void setup() { 
  size(600, 600);
void draw() { 
  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