# Array of extruded shapes is too slow

**URL:** <https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414>\
**Category:** Processing.py\
**Created:** [September 10, 2018, 10:42am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414 "2018-09-10T10:42:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pop](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@pop](https://discourse.processing.org/u/pop)\
**Post date:** [September 10, 2018, 10:42am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/1 "2018-09-10T10:42:54Z")

</div>

Hello, this is my first post on here, so I hope I’m following the guidelines correctly.

I want to orbit around an array of simple extrusions obtained through the extruder library. The code works in theory, but orbiting with PeasyCam is super slow. Is there a more efficient way of doing this? Do the shapes have to be recalculated each time draw() updates the geometry or is there a way to store them somewhere?

Thank you

```auto
add_library('extruder')
add_library('peasycam')

def setup():
    size(800, 800, P3D)
    background(255)    
    cam = PeasyCam(this, 2000)
    cam.setMinimumDistance(100)
    cam.setMaximumDistance(1000)
    cam.lookAt(0,0,0,500)

circleList = []
def draw():
    e = extruder(this)
    background(255)    
    for i in range(10):
        for j in range(10):
            circle = createShape(ELLIPSE, i*10,j*10,20,20) 
            circleList.append(circle)
    for i in circleList:        
        cylinder = e.extrude(i,100, "box")
        shape(cylinder[0])

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 10, 2018, 10:53am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/2 "2018-09-10T10:53:32Z")

</div>

According to your double loop _i_ `range(10)` x _j_ `range(10)` in **draw()**, 100 PShape objects are **append()** to list _circleList_ non-stop at about 60 FPS! 😰

---

<div class="post-metadata">

**Author:** ![pop](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@pop](https://discourse.processing.org/u/pop)\
**Post date:** [September 10, 2018, 11:03am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/4 "2018-09-10T11:03:00Z")

</div>

Thank you,

emptying the list each time does not improve the situation, is there a more efficient strategy to solve the problem?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 10, 2018, 11:11am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/5 "2018-09-10T11:11:45Z")

</div>

The problem is not that the list is too big, that’s the fact that, as @GoToLoop said, you append too many shapes every frame.

So emptying your list won’t solve your problem.

---

<div class="post-metadata">

**Author:** ![pop](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@pop](https://discourse.processing.org/u/pop)\
**Post date:** [September 10, 2018, 11:19am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/6 "2018-09-10T11:19:16Z")

</div>

Thank you,  
I understand the entire strategy of the program is wrong. Is there a way to orbit around that shape, without having the program to crash?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 10, 2018, 11:34am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/7 "2018-09-10T11:34:53Z")

</div>

After reading your code properly, I think this is the slow part:

```auto
for i in circleList:        
        cylinder = e.extrude(i,100, "box")

```

What is it that you try to achieve axactly?

It seems that you want a cube of circle growing more and more right?  
If this is the case, what you can do is start with the shape you want. And instead of extruding it at every frame, you can just translate the back part of the shape.

---

<div class="post-metadata">

**Author:** ![pop](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@pop](https://discourse.processing.org/u/pop)\
**Post date:** [September 10, 2018, 11:41am UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/8 "2018-09-10T11:41:30Z")

</div>

No, I just wanted an array of fixed shapes, and to orbit around it. I know this is trivial, but don’t know how to do it.

---

<div class="post-metadata">

**Author:** ![pop](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@pop](https://discourse.processing.org/u/pop)\
**Post date:** [September 10, 2018, 12:11pm UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/9 "2018-09-10T12:11:43Z")

</div>

```auto
add_library('extruder')
add_library('peasycam')

def setup():
    size(800, 800, P3D)
    background(255)    
    cam = PeasyCam(this, 2000)
    cam.setMinimumDistance(100)
    cam.setMaximumDistance(1000)
    cam.lookAt(0,0,0,500)

def draw():
    circleList = []
    e = extruder(this)
    background(255)    
    circle = createShape(ELLIPSE, 10,10,20,20) 
    circleList.append(circle)
     
    cylinder = e.extrude(circle,100, "box")
    for i in range(20):
        for j in range(20):
            pushMatrix()
            translate(i*10,j*20,0)
            shape(cylinder[0])
            popMatrix()

```

This seems to work properly, translate is key. If there is a more efficient way please let me know

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 10, 2018, 1:01pm UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/10 "2018-09-10T13:01:17Z")

</div>

> [@pop](#):
>
> If there is a more efficient way please let me know.

```auto
"""
 Discourse.Processing.org/t/array-of-extruded-shapes-is-too-slow/3414/10
 Mod: GoToLoop (2018-Sep-10)
"""

add_library('extruder')
add_library('peasycam')

CIRCLES = 20
STEP_X, STEP_Y = 10, 20

RANGE_X = tuple(range(0, CIRCLES*STEP_X, STEP_X))
RANGE_Y = tuple(range(0, CIRCLES*STEP_Y, STEP_Y))

def setup():
    size(600, 600, P3D)
    smooth(8)

    fill(0xffFFFF00)
    stroke(0)
    strokeWeight(1.0)

    cam = PeasyCam(this, width)
    cam.setMinimumDistance(100)
    cam.setMaximumDistance(width<<2)
    cam.lookAt(width>>2, height>>2, 0, 500)

    global cylinder

    circle = createShape(ELLIPSE, 10, 10, 20, 20)
    cylinder = extruder(this).extrude(circle, 100, 'box')[0]

def draw():
    background(-1)

    for y in RANGE_Y:
        for x in RANGE_X: shape(cylinder, x, y)

```

---

<div class="post-metadata">

**Author:** ![pop](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@pop](https://discourse.processing.org/u/pop)\
**Post date:** [September 10, 2018, 1:12pm UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/11 "2018-09-10T13:12:16Z")

</div>

Perfect, do I understand correctly that defining geometry in the setup() function, saves computing power by not repeating the process indefinitely?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 10, 2018, 1:16pm UTC](https://discourse.processing.org/t/array-of-extruded-shapes-is-too-slow/3414/12 "2018-09-10T13:16:35Z")

</div>

> [@pop](#):
>
> … , saves computing power by not repeating the process indefinitely?

The more things we can pre-define within **setup()**, the less things are left for **draw()** to deal w/. 🖼
