We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all
I'm working on a project which shows a map of Northern Ireland. Right now I'm trying to work on an opening sequence where only the lough shows, and when clicked the counties grow from nothing. The problem I'm having is that everything grows from the corner, and I'm not quite sure how to constrain the scales so that the PShapes don't become larger than I need them to be.
Anyone have any advice firstly on how to scale up and down from the centre point of each PShape, and secondly how to constrain the scales?
Thanks a million!
Answers
Please share your code -- it is hard to know what you mean by "constrain the scale."
Re:
Look at shapeMode() -- e.g. shapeMode(CENTER):
Other options if your shape data is not encoded in a centered way include using shape(s, x, y), translate(), and/or PShape.translate(). For details see previous related discussions:
Re:
You could use
constrain()
ormax()
.This is a simplified version of it. Right now, only the red shape shrinks down when clicked, and it shrinks into the top left corner. I'm trying to make it shrink and grow from a central point, rather than into the corner, and once I get that working, I can apply it to more shapes.
I also want some more shapes to grow from nothing (if that makes sense) but I can only figure out how to make them keep growing, rather than stop when they've reached a maximum size.
I'm sure there's a really simple way to do this that I've maybe missed somewhere.
Thanks
The links I shared above are perfect for this situation -- your lough.vertex() coordinates aren't centered around 0,0 -- you can fix this in any of the ways mentioned (translating, or shifting the coordinates). See this thread for a detailed example of how to fix:
Hi Jeremy. Thanks for getting back to me. I've tried applying the code in the above example, but I've somehow ended up with a tiny square in the centre of the screen. I thought it was maybe something to do with the scale for loop, but removing it or adjusting the parameters doesn't seem to have done anything. Is there something I've missed somewhere?
Notice you are calling translate twice.
Also you need to call beginShape() and endShape() when using vertex.
Kf
Hi there
Thanks to everyone for all your help. I have eventually got it scaling to a point I have defined but I had to go down a rather different route to get it working lol, by scaling and translating. As always, one problem solved is another problem gained, as my code now won't delete previous iterations of the shape. Has anyone ever encountered this before?
I believe if you ad
background(150);
as the first line in setup, your current problem should be solved.Kf
Awesome, thanks for all the help everyone! Seem to have it doing what I need it to now