The key to placing and moving a shape is deciding where on the shape the origin is. If your bezierCurve is a piece of paper, then 0,0 is its origin. The shape should grow, shrink, or stretch around that origin. Where should it be for your mushroom – is it in the upper-left corner, the center, the center-bottom? Right now, your points begin at 50,370 – that means everything is on the lower left of the origin, and when it grows it will move farther down and to the left.
Your tinymushroom function can then take arguments on where it should be drawn. This, for example, is drawn centered:
void tinyshroom(float x, float y){
translate(x, y);
rect(-5, -5, 10, 10);
translate(-x, -y);
}
You could use modes for that, like rectMode, but they only work for primitives.
void tinyshroom(float x, float y){
rectMode(CENTER);
rect(x, y, 10, 10);
}
If you wish, you can also use a push/pop to set translate, then unset it when you are done.
void tinyshroom(float x, float y){
pushMatrix();
translate(x, y);
rect(-5, -5, 10, 10);
popMatrix();
}
Scaling could also be controlled either by manually multiplying your coordinates …
void tinyshroom(float x, float y, float scaling){
pushMatrix();
translate(x, y);
rect(scaling*-5, scaling*-5, scaling*10, scaling*10);
popMatrix();
}
…or by using scale()
. It will be reset by popMatrix().
void tinyshroom(float x, float y, float scaling){
pushMatrix();
translate(x, y);
scale(scaling);
rect(-5, -5, 10, 10);
popMatrix();
}
So, putting it all together, here is a shape that you can draw anywhere, at any size (.5 for half size, 2 for double).
void draw(){
background(192);
tinyshroom(50, 50, 3);
tinyshroom(80, 80, 0.75);
tinyshroom(mouseX, mouseY, millis()%3000/1000.0);
}
void tinyshroom(float x, float y, float scaling){
pushMatrix();
translate(x, y);
scale(scaling);
rect(-5, -5, 10, 10);
popMatrix();
}