I have a project where I have to make an interactive graphics program

I am trying to create shapes that can be placed with key binds and then saved in an ArrayList. The hardest thing I’m having trouble with right now is how to edit the shapes’ size and location after I have placed them. I want to use a slider to edit the size of the selected shape.

sounds like a shape program. You could use a line class to create the shapes providing the are line dependent, theyre’ll be alternatives for beziers elipses etc.

But essentialy

for(int i=0;i<shapes.size();i++){
for(int j=0;j<shapes.get(i).line;j++){
   drawLine()

}
}

where your class will take

class shape{
   shape(int x, int y, ind w, int h){
   this.x = x;
   this.y = y;
   this.h = h;
   this.w = w;
   calc center of shape() so you can stretch rotate shape later

}

shape.draw(){
//drawshape
}

shape.hover(){
//hover logic
}

shape.pointHover(){
//point hover logic
}

shape.vertexHover(){
//vertex hover logic
}
}

How do I implement it for a slider im currently just using a simple controll p5 slider I found.

shape.stretch(){
   shape.width = slider.getValue();
   //here you would have to consider how the shape is made and stretch the points that make the vertexes,
}

//be aware in the previous response I incorrectly called edges vertexes

Place : drag with mouse add same value to each corner

Size: use scale() command; make points therefore in a way that you place all points around 0,0

1 Like

So what I want to accomplish now is how do I select a particular shape that I have drawn on the canvas and then proceed to only change the size of that particular shape with the slider.

1 Like

Okay, when you have multiple shapes calculate the center of each shape (store Center in class for example and update when needed). The center is the average of all points, so x1+x2+x3…/n, same for y1+y2…

  • User clicks, check for nearest center (for loop)

  • Store the index of selected shape

  • And use scale() only with that one.

2 Likes