# Is my fractal optimized? Could it animate?

**URL:** <https://discourse.processing.org/t/is-my-fractal-optimized-could-it-animate/28845>\
**Category:** Coding Questions\
**Created:** [March 25, 2021, 7:32pm UTC](https://discourse.processing.org/t/is-my-fractal-optimized-could-it-animate/28845 "2021-03-25T19:32:55Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [March 26, 2021, 12:44pm UTC](https://discourse.processing.org/t/is-my-fractal-optimized-could-it-animate/28845/4 "2021-03-26T12:44:33Z")

</div>

> [@rodsn](#):
>
> I am trying to implement a recursive system.

> [@rodsn](#):
>
> Can i implement some kind of delay between the instances of the fractal?

If you would like to implement a recursion and animate it, one possible strategy would be as follows:

- Within the recursive function, save the specifications of each part of the fractal as data rather than actually draw it.
- From within `setup()`, call the recursive function. The data will then get saved.
- Call `frameRate()` to set the rate of the animation.
- From `draw()`, fetch the specifications for one part of the fractal during each frame, and render that part.
- Call `noLoop()` after all parts of the fractal have been rendered.

I like Python, and so used Python Mode to implement @josephh’s circles fractal based on the above strategy. Here’s the code:

```auto
params = [] # each item will be a list of specs for a circle
def setup():
    size(400, 400)
    background(255)
    noFill()
    frameRate(10)
    recursive_circle(width / 2, height / 2, 200, 4)

def draw():
    if frameCount <= len(params):
        item = params[frameCount - 1]
        circle(item[0], item[1], item[2])
    else:
        noLoop()

def recursive_circle(x, y, d, level):
    # params.append([x, y, d])
    if level == 0:
        # base case; do nothing
        pass
    else:
        # recursive case
        recursive_circle(x - d / 2, y, d / 2, level - 1)
        recursive_circle(x, y - d / 2, d / 2, level - 1)
        recursive_circle(x + d / 2, y, d / 2, level - 1)
        recursive_circle(x, y + d / 2, d / 2, level - 1)
    params.append([x, y, d])

```

Here’s a screen capture of the process partway through its execution:

 ![CircleFractal](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ab2b657a1a1cc7a065b66bf662d639edf8a2a740.png)

---

_[View the full topic](https://discourse.processing.org/t/is-my-fractal-optimized-could-it-animate/28845)._
