class help!
in
Programming Questions
•
2 years ago
I designed a class that draws a man but when i call it in my program the arms and legs are huge, and grow to the end of the screen but when I call it independently it works?
class that I am using is below (commented out was stuff I tried but did not work)
class Man {
float tempx,tempy,x,y,lx,ly,rx,ry,speed;
Man(float x, float y, float lx, float ly, float rx, float ry) {
//tempx=x;
//tempy=y;
//this.x=x;
//this.y=y;
//this.ry=ry;
// this.ax=ax;
// this.ay=ay;
//speed = 1;
}
void display() {
noStroke();
fill(252, 226,187);
//head
ellipse(x,y,20,50);
//eyes
fill(255);
ellipse(x+5,y,10,10);
ellipse(x+15,y,10,10);
//nose
fill(252, 226,187);
ellipse(x+20,y+10,30,10);
//neck
rect(x-2,y+20,5,20);
//shirt
fill(255,0,0);
rect(x-10,y+40,20,20);
//left leg
stroke(5);
fill(0,255,0);
line(x,y+60,lx, ly+20);
//right leg
line(x+5,y+60,rx+5,ry+20);
//arm
line(x,y+40,x-10,100);
}
void move() {
y += random(-1,1);
//ly +=random(-1,1);
//ry += random(-1,1);
//lx +=speed+ random(-1,1);
// rx +=speed +random(-1,1);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This is how I call it in the program
Man movMan;
void setup() {
movMan= new Man(350,250,350,250,350,250);
}
void draw() {
movMan.move();
movMan.display();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This is it seperatly as a function:
void setup() {
size(500,500);
}
void draw() {
man(200,50,200,100,200,100);
}
void man(float xc,float yc,float lxc,float lyc,float rxc,float ryc) {
noStroke();
fill(252, 226,187);
//head
ellipse(xc,yc,20,50);
//eyes
fill(255);
ellipse(xc+5,yc,10,10);
ellipse(xc+15,yc,10,10);
//nose
fill(252, 226,187);
ellipse(xc+20,yc+10,30,10);
//neck
rect(xc-2,yc+20,5,20);
//shirt
fill(255,0,0);
rect(xc-10,yc+40,20,20);
//left leg
stroke(5);
fill(0,255,0);
line(xc,yc+60,lxc, lyc+20);
//right leg
line(xc+5,yc+60,rxc+5,ryc+20);
//arm
line(xc,yc+40,xc-10,100);
}
1