# Changing a child classes characteristics

**URL:** <https://discourse.processing.org/t/changing-a-child-classes-characteristics/14731>\
**Category:** Coding Questions\
**Created:** [October 16, 2019, 12:51am UTC](https://discourse.processing.org/t/changing-a-child-classes-characteristics/14731 "2019-10-16T00:51:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SLINKYMAN](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@SLINKYMAN](https://discourse.processing.org/u/SLINKYMAN)\
**Post date:** [October 16, 2019, 12:51am UTC](https://discourse.processing.org/t/changing-a-child-classes-characteristics/14731/1 "2019-10-16T00:51:14Z")

</div>

I need to use inheritance for a project of mine. Currently, I Have been looking at this example code to create a person.

```auto
class Human implements Drawable{
  
  int armAngle = 0;
  int angleChange = 5;
  final int ANGLE_LIMIT = 135;

void draw()
{
  noStroke();
  fill(38, 38, 200);
  ellipse(73+x, 225+y, 40, 40); // head
  rect(50+x, 250+y, 50, 60); // body
  drawLeftArm();
  drawRightArm();
  rect(60+x, 300+y, 16, 50); // left leg
  rect(80+x, 300+y, 15, 50); // right leg
  
  fill(222, 222, 249);
  ellipse(80+x, 220+y, 8, 8); // left eye
  ellipse(65+x, 220+y, 8, 8); // right eye
  
 
}

void drawLeftArm()
{
  pushMatrix();
  translate(12, 32);
  rotate(radians(armAngle));
  rect(25+x, 220+y, 10, 45); // left arm
  popMatrix();
}

void drawRightArm()
{
  pushMatrix();
  translate(66, 32);
  rotate(radians(-armAngle));
  rect(37+x, 220+y, 10, 45); // right arm
  popMatrix();
}

```

In my Child class, I have this

```auto
class Child extends Human{

  void draw(){
   
    super.draw();
     }
}

```

Obviously my problem is my child class is just drawing an exact copy on top of my Human class but I can not figure out how to alter the child class without just copy pasting the code over again making the inheritence pointless. Ideally I would like to make the child smaller and beside the Human parent class. How would i go about this?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 16, 2019, 6:17am UTC](https://discourse.processing.org/t/changing-a-child-classes-characteristics/14731/2 "2019-10-16T06:17:59Z")

</div>

looks very good,  
just need to deal with x and y  
and please post a runable code if possible.

```auto
class Human {
  int armAngle = 0;
  int x,y;
  
  void draw() {
    move();
    push();
    translate(x,y);
    noStroke();
    fill(38, 38, 200);
    ellipse(73, 25, 40, 40); // head
    rect(50, 50, 50, 60); // body
    drawLeftArm();
    drawRightArm();
    rect(60, 100, 16, 50); // left leg
    rect(80, 100, 15, 50); // right leg

    fill(222, 222, 249);
    ellipse(80, 20, 8, 8); // left eye
    ellipse(65, 20, 8, 8); // right eye
    pop();
  }
  
  void move() {
    x += 1;
    if ( x > width ) x = 0;
    //y = 100;
    armAngle += 5;
  }

  void drawLeftArm() {
    pushMatrix();
    translate(52, 52);
    rotate(radians(armAngle));
    rect(-5, 0, 10, 45); // left arm
    popMatrix();
  }

  void drawRightArm() {
    pushMatrix();
    translate(96, 52);
    rotate(radians(-armAngle));
    rect(-5, 0, 10, 45); // right arm
    popMatrix();
  }
}

class Child extends Human {
  void draw() {
    super.draw();
  }
}

Child one = new Child();
Child two = new Child();

void setup() {
  size(500,500);
  one.y = 100;
  two.y = 300;
  two.x = 200;
}

void draw() {
  background(200,200,0);
  one.draw();
  two.draw();
}

```

thanks, follow @quark

> **repair and add color and size**
>
> ```auto
> class Human {
> private int armAngle = 0;
> public int x,y,dx=0,dy=0;
> public color colf = color(38, 38, 200);
> public float big=1.0;
>   
> void draw() {
> move();
> pushMatrix();
> translate(x,y);
> scale(big);
> noStroke();
> fill(colf);
> ellipse(73, 25, 40, 40); // head
> rect(50, 50, 50, 60); // body
> drawLeftArm();
> drawRightArm();
> rect(60, 100, 16, 50); // left leg
> rect(80, 100, 15, 50); // right leg
> 
> fill(222, 222, 249);
> ellipse(80, 20, 8, 8); // left eye
> ellipse(65, 20, 8, 8); // right eye
> popMatrix();
> }
>   
> void move() {
> x += dx;
> if ( x > width ) x = 0;
> y += dy;
> if ( y > height ) y = 0;
> armAngle += 5;
> }
> 
> void drawLeftArm() {
> pushMatrix();
> translate(52, 52);
> rotate(radians(armAngle));
> rect(-5, 0, 10, 45); // left arm
> popMatrix();
> }
> 
> void drawRightArm() {
> pushMatrix();
> translate(96, 52);
> rotate(radians(-armAngle));
> rect(-5, 0, 10, 45); // right arm
> popMatrix();
> }
> }
> 
> class Child extends Human {
> void draw() {
> super.draw();
> }
> }
> 
> Child one = new Child();
> Child two = new Child();
> 
> void setup() {
> size(500,500);
> // set public things about Child/Human
> one.dx = 1;
> one.y = 100;
>   
> two.x = 200;
> two.dx = 2;
> two.y = 300;
> two.colf = color(200,0,200);
> two.big = 0.5;
> }
> 
> void draw() {
> background(200,200,0);
> one.draw();
> two.draw();
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 16, 2019, 7:13am UTC](https://discourse.processing.org/t/changing-a-child-classes-characteristics/14731/3 "2019-10-16T07:13:14Z")

</div>

@kll in the Human class draw method the `push` and `pop` should be `pushMatrix` and `popMatrix`

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 19, 2019, 5:04pm UTC](https://discourse.processing.org/t/changing-a-child-classes-characteristics/14731/4 "2019-10-19T17:04:08Z")

</div>

> [@SLINKYMAN](#):
>
> I can not figure out how to alter the child class without just copy pasting the code over again making the inheritence pointless.

What are you trying to accomplish in Child that Human does not do? If you want a child to be smaller, than Human should have a signature

```
Human.draw(myHeight)

```

…and draw based on that height. Or it has an int height property that is set when you call the myHuman = new Human(myheight) constructor. Then `Human mychild` doesn’t need inheritence – it is just a Human with a short height.

If you are trying to do something else with inheritance, what is it? At that point, you can override draw() in Child and write a new one, rather than (or in addition to) parameterizing it.
