Why circle disappears at y-coordinates ~ 250

``````void setup() {
size(500,500);
background(0);
}
void draw() {
loop();
float y=500+(-90*millis()/1000+(10*millis()*millis()/2/1000000));
float D=25;
float x = 0+15*millis()/1000;
float yc = y;
float xc=x;
background(0);
if (y >500) {
yc = -y;
}
if (x >500) {
xc = -x;
}
circle(xc, yc, D);
print(millis());
if (millis()/1000>100){noLoop();}

}
``````

Your y value jumps from 254.0 to -1891.0. This is because you call millis() twice. I replaced your code with

``````  float millis = millis();
float y=500+(-90*millis/1000+(10*millis*millis/2/1000000));
``````

Try that.

1 Like

Hello,

This was in my Drafts and a late response… it may still be helpful to some.

It is because the math is exceeding the maximum value of an integer at some point in the code:

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

This code shows what happens to `y1` when `millis()` (an integer) is greater than 14654:

The above code shows where the point of concern is in the code.

You are using `millis()/1000` for time.

Consider using this floating point division in your code along with floating point math throughout:

`float t = millis()/1000.0; // Result is floating point`

Use this if you intend to use integer math with 1 sec increments:

`float t = millis()/1000; // Result is an integer`

Your code will look much cleaner and identifiable as the equation to a parabola:

`float y = 20*t*t -100*t+ 200;`

`:)`