Sunday, February 19, 2012

Project 2 update: 2/20

Below is my code that I have working thus far. The code asks for a user to define the parameters of its population. So far the parameters are population size, predator/prey, and population speed. The code then randomly creates a population (represented by a sphere) in the environment. The user then is prompted to choose a direction for the population to move, N, S, E, or W. The population moves in increments of 1 unit. The user is prompted until the population reaches the edges of the map or the user types "finished".

import maya.cmds as cmds
import random as rand


def populationDef():
  
   global p1, p2, p3

   print "Before proceeding, define the following parameters regarding your population: "
   p1 = raw_input('Is the population large, medium, or small? ')
   print p1, "\n"
   p2 = raw_input('Is the population made up of predators or prey? ')
   print p2, "\n"
   p3 = raw_input('Is the population fast or slow? ')
   print p3, "\n"

def populationPos():
   x = rand.randrange(0, 19, 1)
   z = rand.randrange(0, 19, 1)
   curObj = cmds.polySphere(name='population1', radius=.5, subdivisionsX=10, subdivisionsY=10, axis=(0, 1, 0), createUVs=2, constructionHistory=True)
   curObj = curObj[0]
   print "Name = ", curObj, "\n"
   cmds.setAttr(curObj+".translate", x, 0, z)
   return curObj


def userInput():
   q = raw_input('In which direction should the population move? N, S, E, or W? If you are done, type "finished". ')
   print q, "\n"
   #cmds.select('population1')
   if q == 'N':
      cmds.move(1, 0, 0, relative=True)
   elif q == 'S':
      cmds.move(-1, 0, 0, relative=True)
   elif q == 'E':
      cmds.move(0, 0, 1, relative=True)
   elif q == 'W':
      cmds.move(0, 0, -1, relative=True)
   elif q == 'finished':
      print 'OK \n'
   return q


def main():
   populationDef()
   curObj = populationPos()

   popX = cmds.getAttr(curObj+'.translateX')
   popZ = cmds.getAttr(curObj+'.translateZ')
   q = ''
  
   while popX < 20 and popZ < 20 and q != 'finished':
      q = userInput()

   #populationType()

No comments:

Post a Comment