We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I have a problem here, I have a Particle object that can be around 20 differents shapes (the shapes are limited), so in my constructor i do a random(0,20) and then on the draw method i pick the correct shape with something like this: generate(){ if(type == 0) {
rect();
circle()
} else if(...){ circle(); circle();
} else if(){ triangle(); rect(); circle();
} }
I know this is akward and a big performance flaw, so i need to do something to:
Thanks and sorry for the english
Have a good day
Answers
Hello ! Can you post your code because it's really hard to figure out what you re trying to do from your description
If I understood correctly, I think
PShape
can do it for you, see:before I thought in using an interface. The PShape seem s abetter way, but as iit s done... You might want to look at
Hey _vk! Thanks but this are compound shapes, rects in rects for example and PShape doesn't allow me to do that.
Hey tlecoz! it's something like this, sorry but it's in Spanish:
void generate(){
if (tipo == 0) { // Figura 0 rect(x, y, wescala, wescala);
}
Subtipos are some elements that share some characteristics with Tipos, for example tipo 1 es a RECT and subtipos use that rect, and so.
I can get rid of subtipos doing more tipos (doesn't really matter) I just did it that way because i tought it could help me reusing code.
Have you looked at the other code? The one with the Interface.
Yes _vk, but if I do that i should create a new shape class for each possible shape i have right? For example, I have rect, rect-rect, rect-rect-rect, rectangle, and so on. Maybe i get it wrong
Yes I think so.
And what about this one ?
: )