# I need help coming up with a very simple little polymorphism animation

**URL:** <https://discourse.processing.org/t/i-need-help-coming-up-with-a-very-simple-little-polymorphism-animation/6291>\
**Category:** Coding Questions\
**Created:** [December 4, 2018, 7:25pm UTC](https://discourse.processing.org/t/i-need-help-coming-up-with-a-very-simple-little-polymorphism-animation/6291 "2018-12-04T19:25:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![starkid](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@starkid](https://discourse.processing.org/u/starkid)\
**Post date:** [December 4, 2018, 7:25pm UTC](https://discourse.processing.org/t/i-need-help-coming-up-with-a-very-simple-little-polymorphism-animation/6291/1 "2018-12-04T19:25:33Z")

</div>

I need to make a very simple and small animation using polymorphism. I have looked at examples and watched video but most of them are too complicated or large, and I want something small. Any suggestions on what I could do and how to go about doing it? Thanks.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [December 5, 2018, 12:12am UTC](https://discourse.processing.org/t/i-need-help-coming-up-with-a-very-simple-little-polymorphism-animation/6291/2 "2018-12-05T00:12:40Z")

</div>

```auto
abstract class BaseObject {
  float x, y;
  BaseObject(){
    x = random(width);
    y = random(height);
  }
  abstract void draw();
}

class Sqa extends BaseObject {
  void draw(){
    fill(0,0,200);
    rect(x,y,20,20);
  }
}

class Tri extends BaseObject {
  void draw(){
    fill(0,200,0);
    triangle(x,y+20,x+10,y,x+20,y+20);
  }
}

class Dot extends BaseObject {
  void draw(){
    fill(200,0,0);
    ellipse(x+10,y+10,20,20);
  }
}

BaseObject[] shapes = new BaseObject[3];

void setup(){
  size(200,200);
  noStroke();
  shapes[0] = new Sqa();
  shapes[1] = new Tri();
  shapes[2] = new Dot();
  for( int i = 0; i < 3; i++){
    shapes[i].x = 40 + 50 *i;
    shapes[i].y = 90;
  }
}

void draw(){
  background(0);
  for( int i = 0; i < 3; i++){
    shapes[i].draw();
  }
}

```

Here we have a “small” example of polymorphism. While it may seem like our array only has three “`BaseObject`” objects in it, in fact the three shapes are only pretending to be `BaseObject`s so that they fit in the array - they are actually three very different types of objects that can pretend to be Basic Shapes because they extend on its definition!

---

<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:** [December 7, 2018, 1:02am UTC](https://discourse.processing.org/t/i-need-help-coming-up-with-a-very-simple-little-polymorphism-animation/6291/3 "2018-12-07T01:02:48Z")

</div>

An interesting exercise along these lines would would be to apply TfGuy44s example to the RegularPolygon demo sketch, changing the function into classes. Simple, shared assumptions are easy to turn into a base.

[https://processing.org/examples/regularpolygon.html](https://processing.org/examples/regularpolygon.html)
