Hi everyone! I am new to python and I'm having a few difficulties. 
I'm attempting to implement a program in Python (using Maya script editor), 
that can generate an animation sequence 
capable of visualising moving n disks from Peg 1(sourcePeg) to Peg 
2(destinationPeg).

*Here is what I've done so far:*

import maya.cmds as cmds

cmds.select(all=True)
cmds.delete()

def Pegs( Height, Radius ):
    pegList=[]
    sourcePeg=cmds.polyCylinder( name='A', r=Radius, sx=15, sy=5, sz=2, 
h=Height )
    cmds.xform( piv=[0,-Height/2,0] ) 
    cmds.move( 0, Height/2, 4)

    destinationPeg=cmds.polyCylinder( name='B', r=Radius, sx=15, sy=5, 
sz=2, h=Height )
    cmds.xform( piv=[0,-Height/2,0] ) 
    cmds.move( 0, Height/2, 0)
    
    auxiliaryPeg=cmds.polyCylinder( name='C', r=Radius, sx=15, sy=5, sz=2, 
h=Height )
    cmds.xform( piv=[0,-Height/2,0] ) 
    cmds.move( 0, Height/2, -4 )
    
    pegList.append(sourcePeg)
    pegList.append(destinationPeg)
    pegList.append(auxiliaryPeg)
    
Pegs( 4, 0.05 )

def Discs( n, Height, Radius ):

    global discList
    global pegList
    discList=[]
    cmds.polyPipe( name='disc_0', r=Radius*6, t=1, h=Height*0.15 )
    cmds.xform( piv=[0,-Height*0.075/2,0] ) 
    cmds.move( 0, Height*0.0375, 4, 'disc_0' )

    for i in range(1, n):
        cmds.duplicate( 'disc_0', 'disc_'+str(i) )
        cmds.move( 0, 0.3, 0,'disc_0', relative=True )
        cmds.scale( 0.8, 1, 0.8,'disc_0', relative=True )
        discList.append('disc_*')
    print discList
        
Discs( 5, 4, 0.2 )    

def TowersOfHanoi( m, sourcePeg, destinationPeg, auxiliaryPeg):
    global pegList
    global discList   
    
    if m == 0:
    
        print "There are no Discs! "     
    
    elif m == 1:

        print " \t\t| Move Disc ", m, " from ", sourcePeg, " Peg ", "to 
---> ", destinationPeg, " Peg |" 
        cmds.move( 0, 0, 0, 'disc_0')
      
    else:        

        TowersOfHanoi(m - 1, sourcePeg, auxiliaryPeg, destinationPeg)
        print " \t\t| Move Disc ", m, " from ", sourcePeg, " Peg ", "to 
---> ", destinationPeg, " Peg |"
        
        if sourcePeg:
            destinationPeg.append(sourcePeg.pop())
            
        cmds.move( 0, 0, -4, 'disc_*', r=True)
        
        TowersOfHanoi(m - 1, auxiliaryPeg, destinationPeg, sourcePeg)

sourcePeg = [discList]
destinationPeg = []
auxiliaryPeg = []
TowersOfHanoi(len(sourcePeg), "A", "B", "C")

print auxiliaryPeg, destinationPeg, sourcePeg          
      
.
.
.
I can't manage to get it to work... =S
Any help would be greatly appreciated!

Kind regards!



-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/c1d00aa5-96a1-4eb6-9828-ad0ae5c4dd4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to