OK after looking through your code, I don't see any instance of you drawing off the screen. All your coordinates for the circles are within your 1200X1200 screen, and the only thing that could even cause them to draw offscreen is your translate() method you call in drawFlower(). So an easy fix to make sure that doesn't cause your circles to move offscreen is a conditional statement like I mentioned before wrapped around your entire drawFlower() method. So here's your modified drawFlower() method:
Code:
void drawFlower(float x,float y,float rad) {
if(x+rad > 0 && x-rad < width && y+rad > 0 && y-rad < height){
pushMatrix();
translate(x,y);
scale(rand/300);
for(float i=0; i<11; i++) {
for(int j = 0; j < 0.4; j += random(32)) {
for(int k = 0; k < 40; k ++) {
// ellipseMode(CORNER);
ellipse(cx1,cy1,cx2/k,cx2/k);
rotate(radians(1360/num)+0.0003);
}
}
rotate(radians(360/num)+0.0003);
}
// restore last saved copy of world matrix
popMatrix();
}
}
The if() statement I wrapped around your entire method will test the incoming x and y coordinates. By taking the coordinates and adding rad to them, we will make sure that if any part of a circle is not visible in the viewable area, it is never drawn, thus eliminating offscreen, non-viewable circles. There is only one problem with this. You never actually use the "rad" variable you pass into drawFlower()! So it's essentially useless. Instead, you define the size of your circles with cx2/k. So you would have to modify your code a bit to get the if() statement in the right spot, or just pass a radius value to drawFlower().
Some other things I noticed about your code. The first for() loop you call in draw() is completely useless. It's not actually doing anything because you're only looping once, meaning your executing everything within it once per frame. So just remove it and you'll get the exact same result. Also, your two for() loops under that are a waste too. Since your xx and yy for() loops are the exact same thing and result in the exact same values, just get rid of one and use the same variable for both arguments when you call drawFlower(). So you could just call drawFlower(xx-100,xx-100,random(0.5,1)); and you would get the exact same result. This eliminates the need for the yy for() loop. Also, to get my if() statement to work with the coordinates + radius, you need to call ellipseMode(CENTER) in the setup(), so we're drawing circles from the center and not the corner.
OK...did I get it this time!?