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 › PShape width/height not working as expected
Page Index Toggle Pages: 1
PShape width/height not working as expected? (Read 1461 times)
PShape width/height not working as expected?
Jun 5th, 2010, 3:38am
 
Hi all,

This is my first post on here, hope it's in the right place.

I've been messing about for hours with WorldMap svg trying to get it to display in the center of a window.

the height and width reported back to me don't seem correct to me. Can any one tell me what i'm doing wrong?

the SVG is available here: upload.wikimedia.org/wikipedia/commons/0/03/BlankMap-World6.svg

this is my code, as you can see i'm setting the width/height of my window based on the information form the PShape:

PShape world;
PShape country;

void setup() {
 world = loadShape("BlankMap-World6.svg");
 
 size((int)world.width, (int)world.height);

 noStroke();
 smooth();
 noLoop();
}

void draw() {
 background(255);
 fill(0);
 world.disableStyle();
 
 for(int i = 0; i < world.getChildCount(); i++) {
   country = world.getChild(i);
   country.disableStyle();
   
   String countryName = country.getName();
   println(countryName);
   
   if (countryName != null
       && !(countryName.equals("ocean"))) {    
     fill(random(63, 127));
     country.scale(0.3);
     shape(country, 0, 0);    
   }
 }
}
Re: PShape width/height not working as expected?
Reply #1 - Jun 5th, 2010, 4:03am
 
The width and height of a PShape (actually available only for the SVG as a whole, not the individual shapes) is provided by the SVG file itself, it is not computed. So if it is inaccurate (I haven't checked) it can be unusable.
Re: PShape width/height not working as expected?
Reply #2 - Jun 5th, 2010, 4:09am
 
thanks for your quick response PhiLo.

i'm sitting here trying to think of a way of computing the actual size of the svg but my brain can't do it.

is there a method for doing so?
Re: PShape width/height not working as expected?
Reply #3 - Jun 5th, 2010, 4:54am
 
Not really since that's a vector format, so it can have any size you want.
Now, the shapes are defined at a given scale, since they are made out of points placed in a plane, so the positions of the points have to be relative to a given scale. (clumsy explanation...)
In other words, when we have a "M9.904,47.16 c0,0-1.809-18.447,27.851-9.766 c0,0-0.724-5.787,6.872-6.149" shape definition, we can find out a max and a min of the x and y values, which can give an idea of the size of the definition of the shape (rough, since a Bézier curve can go beyond its definition points).
Page Index Toggle Pages: 1