classes: if any of the subclasses is "used", please do this...
in
Programming Questions
•
3 years ago
I want to program a main class "objects" and subclasses "points", "lines", "triangles",...
In the class "objects" I set the strokeWeight, stroke and so on. In the subclass "points" for example, I display this point.
Now I'd like to program that if I have drawn a point or a line or a triangle or something like that, always when I make a new object in a subclass, the program gives out the name of the subclass "points", and the parameters for example x-y-z-position.. Furthermore I would like to program this automatically, so that if I press a button, that it makes me a point1, point 2, point 3..
and that's what I already have got: what can I do now and is there an easier way to do this?
- class Objekte{
int xpos, ypos, zpos, xpos1,ypos1, zpos1,xpos2,ypos2,zpos2;
float x1,x2,x3,y1,y2,y3,z1,z2,z3;
int farb=0, anpu=1;
float dicke=1;
-
void transparenz(int transpar) {
// transparenz=transpar
} - void groesse(int g) {
- dicke=g;
- }
- void farbe(color c) {
- farb=c;
}- void verschiebe(int dx, int dy, int dz) {
- xpos=xpos1+dx;
ypos=ypos1+dy;
zpos=zpos1+dz;
xpos2=xpos1+dx;
ypos2=ypos1+dy;
zpos2=zpos1+dz;
xpos1=xpos2;
ypos1=ypos2;
zpos1=zpos2;
// translate(dx,dy,dz);
}- void hide(){
background(255);
}
}
class Punkt extends Objekte {
Punkt(int x, int y, int z){
xpos=x;
ypos=y;
zpos=z;
xpos1=x;
ypos1=y;
zpos1=z;
}
void display(){
stroke(farb);
strokeWeight(dicke*5);
point(xpos,-ypos,zpos);
println("Punkt"+anpu+": ("+xpos+"/"+(-ypos)+"/"+zpos+")");
}
}
class Dreieck extends Objekte {
Dreieck(float x, float y, float s){
x1=x;
y1=y;
x2=x+s;
y2=y;
x3=x+s/2;
y3=y-sqrt(sq(s)-sq(s/2));
}
void display(){
stroke(farb);
strokeWeight(dicke);
triangle(x1,y1,x2,y2,x3,y3);
}
}}
1

) and I believe may be handled by some of the libraries. Once you find a solution you can drop it into the mouseOver() method of your subclass...