# Array of extruded shapes is too slow

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

``````add_library('extruder')

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)
``````
1 Like

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! 1 Like

Thank you,

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

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.

1 Like

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?

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

``````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.

2 Likes

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.

``````add_library('extruder')

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)
popMatrix()

``````

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

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

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')

def draw():
background(-1)

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

Perfect, do I understand correctly that defining geometry in the setup() function, 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/. 3 Likes