Resizing PShape objects with getChild()
The term getChild() implies the getting of an independent child object.
I've found this to be a little misleading.
Each rectangle has id: house, door, window.
The svg file shows:
- <svg
- width="388.57144"
- height="297.73553"
In the sketch I have:
- main = loadShape("drawing08.svg");
- house = main.getChild("house");
- door = main.getChild("door");
- window = main.getChild("window");
In a previous thread I mentioned that the x,y values of child shapes can be made absolute if translate and x,y values in the svg file are edited to zero.
When going a step further to modify the size of child shapes, I discovered that getChild is really getChildWithPage.
house.width also returns 388.57144.
door.width also returns 388.57144.
window.width also returns 388.57144.
If your code wants to modify the child shape size, it needs to recognize the Page size.
For example, to resize the house, this code works:
-
float hw = (main.width * w) / houseW;
- float hh = (main.height * h) / houseH;
-
hw and hh = values to be used in drawing
-
main.width and main.height = page size
- w and h = desired house width and height
-
houseW and houseH = original width and height of house shape
Parameters houseW and houseH, along with doorW, doorH, windowW and windowH must be manually entered in Processing from the svg file. It would be much easier if Processing provided the actual child shape dimensions found in the svg file (e.g. house.width = 300; door.width = 60; window.width = 100).
Summary.
As a beginner, I was disappointed that getChild() does not get a shape object that’s independent of the source page. When getChild() is utilized, do we really need to know about the source page size?
In the meantime, I’ve found ways to work around the location (x,y) and size (width,height) "problems" of child shapes. I’m providing this because I don’t see it explained anywhere else.
Please advise if there are simpler ways to do this.