You can use ctrl-t in processing (not the forum) to get auto-indents. Use it prior to posting.
When using translate( mouseX, mouseY ); you want to place your shape at 0,0 because here is the mouse: shape(s, 0, 0); or even shape(s, -60, -100); to place the center of the shape over the mouse.
You can surround this section with pushMatrix and popMatrix to isolate it from the rest of the Sketch OR place the section at the end of draw(), because when draw() restarts 60 times per second, the Matrix gets resetted,
New version 1 : Sketch with translate to move the shape
PShape s;
void setup() {
size (500, 400);
background(167);
s = createShape();
s.beginShape();
s.stroke(255, 80, 244);
s.fill(203, 68, 99);
s.strokeWeight(2);
s.vertex(30, 140);
s.vertex(50, 140);
s.vertex(50, 160);
s.vertex(100, 110);
s.vertex(80, 110);
s.vertex(80, 90);
s.endShape(CLOSE);
}
void draw() {
background(167);
stroke(139, 75, 97);
fill(95, 260, 61);
strokeWeight(2);
ellipse(150, 100, 20, 20);
ellipse(200, 260, 20, 20);
ellipse(270, 100, 20, 20);
ellipse(350, 260, 20, 20);
ellipse(390, 100, 20, 20);
translate( mouseX, mouseY );
shape(s, -60, -100);
}
New version 2
New version with an array for the points
PShape s;
PVector[] list = new PVector[5];
void setup() {
size (500, 400);
background(167);
for (int i=0; i<3; i++) {
list[i] = new PVector ( 150 + i*110, 100);
}
for (int i=3; i<list.length; i++) {
list[i] = new PVector ( 150 + (i-3)*110, 260);
}
s = createShape();
s.beginShape();
s.stroke(255, 80, 244);
s.fill(203, 68, 99);
s.strokeWeight(2);
s.vertex(30, 140);
s.vertex(50, 140);
s.vertex(50, 160);
s.vertex(100, 110);
s.vertex(80, 110);
s.vertex(80, 90);
s.endShape(CLOSE);
}
void draw() {
background(167);
stroke(139, 75, 97);
fill(95, 260, 61);
strokeWeight(2);
for (PVector pv : list ) {
ellipse(pv.x, pv.y, 20, 20);
}
translate( mouseX, mouseY );
shape(s, -60, -100);
}
Here is a new version 3
where you have to click the mouse and the shape flies to this position
Also, you have a collision check between shape and first point (can you do the check for all points?)
PShape s;
PVector[] list = new PVector[5];
float x=-30;
float y=-70;
// for moving:
float newX, newY;
boolean move=false;
float t=0;
//---------------------------------------------------
void setup() {
size (500, 400);
background(167);
// make point array
for (int i=0; i<3; i++) {
list[i] = new PVector ( 150 + i*110, 100);
}
for (int i=3; i<list.length; i++) {
list[i] = new PVector ( 150 + (i-3)*110, 260);
}
// make shape
s = createShape();
s.beginShape();
s.stroke(255, 80, 244);
s.fill(203, 68, 99);
s.strokeWeight(2);
s.vertex(30, 140);
s.vertex(50, 140);
s.vertex(50, 160);
s.vertex(100, 110);
s.vertex(80, 110);
s.vertex(80, 90);
s.endShape(CLOSE);
}
void draw() {
background(167);
stroke(139, 75, 97);
fill(95, 260, 61);
strokeWeight(2);
for (PVector pv : list ) {
ellipse(pv.x, pv.y, 20, 20);
}
if (move) {
x=lerp(x, newX, t);
y=lerp(y, newY, t);
t+=0.01;
if (t>=0.99)move=false;
}
// translate( mouseX, mouseY );
shape(s, x, y);
if (dist(x+60, y+110, list[0].x, list[0].y) < 32) {
println("hit");
}
}
void mousePressed() {
newX=mouseX-60;
newY=mouseY-110;
move=true;
t=0;
}
//