# Is there any way to simplify this code...

… so that I don’t have to change from 90 to 180, to 270 and 360 degrees in their respective HPR? There should be an option to add 90º in each iteration of the sequence, but I’ve tried it with a function and I couldn’t…

``````def rotateTargets(self):

# Create Lerp intervals for each orbit target node to rotate all of the targets
# in a parallel sequence with easing
self.rotateTargets = Sequence(
Parallel(
LerpHprInterval(self.orbitNodes["orbit0"], 4, Point3(0, 0, 90), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit1"], 4, Point3(0, 90, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit2"], 4, Point3(0, 0, -90), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit3"], 4, Point3(0, -90, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit4"], 4, Point3(-90, 0, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit5"], 4, Point3(90, 0, 0), blendType = "easeInOut"),
name = "rotateTargets0"),
Parallel(
LerpHprInterval(self.orbitNodes["orbit0"], 4, Point3(0, 0, 180), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit1"], 4, Point3(0, 180, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit2"], 4, Point3(0, 0, -180), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit3"], 4, Point3(0, -180, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit4"], 4, Point3(-180, 0, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit5"], 4, Point3(180, 0, 0), blendType = "easeInOut"),
name = "rotateTargets1"),
Parallel(
LerpHprInterval(self.orbitNodes["orbit0"], 4, Point3(0, 0, 270), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit1"], 4, Point3(0, 270, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit2"], 4, Point3(0, 0, -270), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit3"], 4, Point3(0, -270, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit4"], 4, Point3(-270, 0, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit5"], 4, Point3(270, 0, 0), blendType = "easeInOut"),
name = "rotateTargets2"),
Parallel(
LerpHprInterval(self.orbitNodes["orbit0"], 4, Point3(0, 0, 360), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit1"], 4, Point3(0, 360, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit2"], 4, Point3(0, 0, -360), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit3"], 4, Point3(0, -360, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit4"], 4, Point3(-360, 0, 0), blendType = "easeInOut"),
LerpHprInterval(self.orbitNodes["orbit5"], 4, Point3(360, 0, 0), blendType = "easeInOut"),
name = "rotateTargets3")
)
self.rotateTargets.loop()``````

You could perhaps use a python tag to store in each NodePath the rotation that you intend to add, and use string concatenation to select the appropriate NodePath, something like this:

``````ROTATION_PYTHON_TAG = "rotation"
NUM_NODES = 6

self.orbitNodes["orbit0"].setPythonTag(ROTATION_PYTHON_TAG, Vec3(0, 0, 90))
# Repeat for each node...

def rotateTargets(self):
self.rotateTargets = Sequence()

for i in xrange(4):
p = Parallel()

for j in xrange(NUM_NODES):
np = self.orbitNodes["orbit"+str(j)]
p.append(LerpHprInterval(np, 4, i*np.getPythonTag(ROTATION_PYTHON_TAG), blendType = "easeInOut")

self.rotateTargets.append(p)``````