When you run this code it draws a linear line and a ball that jumps around with ‘a’ and ‘d’. The line is drawn in the for loop. Running this works just fine, but if you change the conditional in the for loop to 1250 instead of 1251 the entire thing slows way down. If you continue to reduce the number in the conditional, it gradually starts running faster until somewhere around 300 the lag barely noticeable. I am using shape drawing and vertex because I am drawing non linear functions pixel by pixel, but after troubleshooting found that the same problem happens with just a basic linear line. Also, I found that in this problematic range, if you drop the strokeWeight down to 1, it runs smoothly, but above that 1251 cutoff, any stroke works. Tried running it on 2 different computers and it did not make a difference. This only happens when I run P2D.
int playerY = 500;
int playerX = 500;
float xv = 0;
float yv = 0;
void setup(){
fullScreen(P2D,SPAN);
}
void draw(){
frameRate(165);
background(0);
fill(255);
ellipse(playerX,playerY,15,15);
yv +=0.4;
playerX+=xv;
playerY+=yv;
beginShape();
noFill();
stroke(255);
strokeWeight(3);
for (int d = 0; d < 1251; d ++) { //here
vertex(d,d);
}
endShape();
}
void keyPressed() {
if (key == 'd'||key == 'a') {
yv = -10;
if (key=='d') {
xv += 10;
} else {
xv -= 10;
}
}
}