We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › get rid of data recording outside the image
Page Index Toggle Pages: 1
get rid of data recording outside the image (Read 674 times)
get rid of data recording outside the image
Jun 11th, 2009, 6:28am
 
hi,
I am trying to get rid of data which falls outside the image window.
since i'm recording pretty complex generative stuff to PDF, many recorded parts fall outside my stage, senslessly eating up ram...
i wonder if something like the Pimage class mask() would do it...?
thanks!
Re: get rid of data recording outside the image
Reply #1 - Jun 11th, 2009, 6:38am
 
I think you just need to throw in some boundaries for your draw methods. So say you're drawing a ton of ellipses or rectangles or something. Just use something like:

Code:

int x, y; //coordinates of your shapes or whatever you're drawing
if(x < 0){
  x = 0;
} else if(x > width){
  x = width;
}

if(y < 0){
  y = 0;
} else if(y > height){
  y = height;
}

//then draw your stuff with your x/y coordinates


If your graphics are mainly (or all) generative, then you'll just need to test the outcomes of your math formulas for those boundaries. Did I get this right? Is that what you were asking?  Huh
Re: get rid of data recording outside the image
Reply #2 - Jun 11th, 2009, 10:52am
 
thanks! ...i thought about this, but often i work with large circles which need to be visible only a tiny part at the edge but the centers are far outside and so this concept doesn't really work. i was looking for something what relly cuts off every overlapping vector, sometimes in illustrator i've seen this...
Re: get rid of data recording outside the image
Reply #3 - Jun 11th, 2009, 11:03am
 
Well you could always move your boundaries outside the display window a little bit. So instead of 0 to width, you could use boundaries of something like -100 to width+100. And if you don't want your circles to overlap, just measure for their radii. So when you want to draw a circle, you would basically test it against the locations and radii of all your other circles through some sort of for() loop. I'm still not positive I know what you're wanting to do. Maybe explain it a little more or show me a screen shot or something. I'm glad to help, but I've having trouble understanding just what exactly your problem is.
Re: get rid of data recording outside the image
Reply #4 - Jun 11th, 2009, 11:47am
 
thank you for being with my problem!
here is some of the latest: http://www.flickr.com/photos/lumicon/3615293954/
you are right, i can do that to a certain amount. ...but the good thing about these random pattern are often some really large pieces and what touch only a bit the visible area.
anyway, meanwhile i have so many strange for structures screwed into each other that it'll be a boring job to limit all drawn elements;)
Re: get rid of data recording outside the image
Reply #5 - Jun 11th, 2009, 12:05pm
 
OK, I see. Very beautiful. I love your choice of colors. I see what you are saying about the circles on the edge, but adding those boundaries will still help eliminate circles that are completely off-screen and useless. Just expand the boundaries to a point where the largest circles can still be seen no matter where they are drawn (even if their center is off-screen).
Re: get rid of data recording outside the image
Reply #6 - Jun 11th, 2009, 12:21pm
 
thank you!Smiley ...yeah, i'll definitely do that next, there is quite much stuff outside... what i don't understand in your script is:
Code:

if(x < 0){
  x = 0;
} else if(x > width){
  x = width;
}

if(y < 0){
  y = 0;
} else if(y > height){
  y = height;
}


why x = 0; and x=width; wouldn't it just reposition the objects rather than removing them completely?

my ultimate dream would be something like a unique script what would be adoptable for all sorts of animations without much x y calculation
maybe with a invisible rect stage size and collision detection or something like this...? i didn't work with collision detection yet. what do you think would it be possible?
Re: get rid of data recording outside the image
Reply #7 - Jun 11th, 2009, 12:50pm
 
Now that I see your project and understand more what you are trying to accomplish, that original code wouldn't be what you want. As you said, you would basically be repositioning off-screen circles, and you'd get a ton of overlap right on your display window borders (which might actually produce a cool effect  Wink). What you probably need to do instead, is just eliminate those circles altogether. So when you calculate your formula for the circles, you'll want to do something like this:

Code:

// assuming you are using a custom method
void drawCircle(){
    float x = (your formula);
    float y = (your formula);
   
    if(x > 0 && x < width && y > 0 && y < height){
         ellipse(x, y, yourHeight, yourWidth);
    }
}


So now you are calculating your circles, but you're not drawing them unless their potential location lies within the viewable area. So in your case, you may expand the boundaries like we talked about, but adding a conditional statement like the one above will remove the chance that a circle is drawn off screen.
   
Re: get rid of data recording outside the image
Reply #8 - Jun 11th, 2009, 1:34pm
 
hm, ...the thing is i need this cut off circles for my composition and because the random size comes to the position and the localisation point is (CENTER), i don't see a solution like this. no single circle should be lost or shifted when only a tiny bit visible on stage...

ok, i additionally have to read out the random size and ad the radius to the width thing..., this i will do, and i guess i'll get rid of some...
Re: get rid of data recording outside the image
Reply #9 - Jun 11th, 2009, 2:07pm
 
I guess I still just don't really understand where you're going with this. Maybe give me some code for one of the circle types. Like show me a method that is drawing circles off screen, and how you want to fix it.
Re: get rid of data recording outside the image
Reply #10 - Jun 12th, 2009, 4:06am
 
that would be very helpful!Smiley ...i didn't do anything on that yet because i'm fighting with another bug. when i make ellipseModer(CORNER) it records only white pdf files??? very strange.
anyway here is the code basic:
Code:
import processing.pdf.*; 
PImage a;
float h,cx1,cy1,cx2,cy2;
float num;
float rand;


void setup()
{
size(1200,1200);
background(255);
frameRate(12);
smooth();
beginRecord(PDF,"bugtest.pdf");
}

void draw()
{

rand = (mouseX);

for(int i=0; i<1; i++) {
initFlower();

for (int yy=200; yy<=1200; yy +=200){
for (int xx=200; xx<=1200; xx +=200){

fill(255,111); // fill(pix,mouseY/4);
stroke(0,random(250));
strokeWeight (random (0.5,1));
drawFlower(xx-100,yy-100,random(0.5,1));

}
}
}
}


void drawFlower(float x,float y,float rad) {
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();
}




void initFlower() {
num=(int)random(9,29);
h=random(150,200);
cx1=random(0,200);
cy1=random(0,h/2);
cx2=random(0,100);
cy2=random(h/2, h);
}


void keyPressed() {
if (key == ' ') {
endRecord();
exit();
}
}





Re: get rid of data recording outside the image
Reply #11 - Jun 12th, 2009, 6:53am
 
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!?  Roll Eyes
Re: get rid of data recording outside the image
Reply #12 - Jun 12th, 2009, 7:42am
 
perfect! thank you so much!Smiley
..about the sensless for structures i noticed too, but when i took them out the result seemd much simpler...

could you help me one more thing please, ..try changing the ellipse center mode to corner and make a ercord, ...it doesnt record???
Page Index Toggle Pages: 1