Self Critique:
I enjoyed this project to some extent, as I used it as an opportunity to learn more about coding. I consider this aspect of the project a success, because I did learn a great deal about Python.
The project itself, however, did not turn out the way I had originally intended. I think I bit off a little more than I could chew, and wasn't able to incorporate many of the elements I wanted the project to have for the presentation.
For example: The more I worked on the project, the more I realized that what I was trying to accomplish was a little beyond the scope of what I could learn in such a short time. I wanted to incorporate many more evolutionary elements, such as diminishing populations over time, and less of a "winner-takes-all" method of gameplay, but as was mentioned in class, the direction the project took was more geared towards an 'A-Life' mentality.
I also wanted to do a little more aesthetically. The plain, lambert textures on the spheres were boring and hard to distinguish from the background, which had a lot of grey in it as well. I underestimated the time it would take to code in color change, as it was a little more difficult than I had thought it was going to be. I wanted the objects to change color based on their "type", i.e. "predator", or "prey". This did not get accomplished.
I also wanted to make the background a little more elaborate as well, but the time it took to make the program overwhelmed the time I was planning to use to create the environment.
All in all, I would say this was a worthwhile project, as I learned a great deal. I am toying with the idea of coming back to this concept for my final project in this class.
Friday, February 24, 2012
Project 2: Presentation 2/22
Below is my final code I created using Python, environment created in Photoshop and Maya:
import maya.cmds as cmds
import random as rand
import math
def populationDefine(): #user input sets parameters for creation of population
global p1, p2, p3
print "Before proceeding, define the following parameters regarding your population: "
#determine population size
p1 = raw_input('Is the population large, medium, or small? ')
print p1, "\n"
if p1 == 'large': #assigns value to global variable based on user input
p1 = 0
elif p1 == 'medium':
p1 = 1
elif p1 == 'small':
p1 = 2
else:
print "Incorrect input, please try again."
main()
#determine population type
p2 = raw_input('Is the population of type predator or prey? ')
print p2, "\n"
if p2 == 'predator':
p2 = 0
elif p2 == 'prey':
p2 = 1
else:
print "Incorrect input, please try again."
main()
#determine population speed
p3 = raw_input('Is the population fast or slow? ')
print p3, "\n"
if p3 == 'fast':
p3 = 0
elif p3 == 'slow':
p3 = 1
else:
print "Incorrect input, please try again."
main()
def objectSize(curObj): #determines poly size based on population size
if p1 == 0:
cmds.scale(1.5, 1.5, 1.5, curObj)
elif p1 == 1:
cmds.scale(1, 1, 1, curObj)
elif p1 == 2:
cmds.scale(.5, .5, .5, curObj)
def objectColor(curObj): #could not get this to work, supposed to assign color
if p2 == 0:
cmds.connectAttr(curObj+'.objectColor', 'matRed')
elif p2 == 1:
cmds.connectAttr(curObj+'.objectColor', 'matBlue')
def populationPos(): #places population randomly in environment
x = rand.randrange(1, 19, 1)
z = rand.randrange(1, 19, 1)
curObj = cmds.polySphere(name='population1', radius=.5, subdivisionsX=10, subdivisionsY=10, axis=(0, 1, 0), createUVs=2, constructionHistory=True)
curObj = curObj[0]
objectSize(curObj)
#objectColor(curObj)
print "Name = ", curObj, "\n"
cmds.addAttr(ln = 'size', at = 'enum', en = "large:medium:small")
cmds.setAttr(curObj+'.size', p1)
cmds.addAttr(ln = 'type', at = 'enum', en = "predator:prey")
cmds.setAttr(curObj+'.type', p2)
cmds.addAttr(ln = 'speed', at = 'enum', en = "fast:slow")
cmds.setAttr(curObj+'.speed', p3)
color = cmds.getAttr( "lambert1.color" )
cmds.setAttr( "lambert1.color", color[0][0], color[0][1], color[0][2], type="double3" )
cmds.setAttr(curObj+".translate", x, 0, z)
return curObj
def userInput(curObj): #user input moves object in direction of choice
q = raw_input('In which direction should the population move? N, S, E, or W? To create a new population, type "new". If you are done, type "exit". ')
print q, "\n"
cmds.select(curObj)
if q == 'n' or q == 'N':
if p3 == 0:
cmds.move(2, 0, 0, relative=True)
elif p3 == 1:
cmds.move(1, 0, 0, relative=True)
elif q == 's' or q == 'S':
if p3 == 0:
cmds.move(-2, 0, 0, relative=True)
elif p3 == 1:
cmds.move(-1, 0, 0, relative=True)
elif q == 'e' or q == 'E':
if p3 == 0:
cmds.move(0, 0, 2, relative=True)
elif p3 == 1:
cmds.move(0, 0, 1, relative=True)
elif q == 'w' or q =='W':
if p3 == 0:
cmds.move(0, 0, -2, relative=True)
elif p3 == 1:
cmds.move(0, 0, -1, relative=True)
elif q == 'new':
main()
elif q == 'exit':
print 'OK \n'
return q
def populationDistance(i, j): #checks the distance between 2 populations
global dist
ix = cmds.getAttr(i+'.translateX')
jx = cmds.getAttr(j+'.translateX')
iz = cmds.getAttr(i+'.translateZ')
jz = cmds.getAttr(j+'.translateZ')
dist = math.sqrt( pow(ix-jx,2) + pow(iz-jz,2) )
def populationReact(i, j): #if populations are close together, they will interact
if cmds.getAttr(i+'.type') == 0 and cmds.getAttr(j+'.type') == 1:
if cmds.getAttr(i+'.size') == 0 and cmds.getAttr(j+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(i+'.size') == 1 and cmds.getAttr(j+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(i+'.size') == 2 and cmds.getAttr(j+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(i+'.size') == 2 and cmds.getAttr(j+'.size') == 1:
print "These two populations can coexist!"
else:
cmds.delete(j)
print "These two populations could not coexist!\n\n"
main()
if cmds.getAttr(j+'.type') == 0 and cmds.getAttr(i+'.type') == 1:
if cmds.getAttr(j+'.size') == 0 and cmds.getAttr(i+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(j+'.size') == 1 and cmds.getAttr(i+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(j+'.size') == 2 and cmds.getAttr(i+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(j+'.size') == 2 and cmds.getAttr(i+'.size') == 1:
print "These two populations can coexist!"
else:
cmds.delete(i)
print "These two populations could not coexist!\n\n"
main()
def populationDetect(): #detects populations near current controlled object
cmds.select('population*')
cmds.select('pop*Shape', d=True)
allObj = cmds.ls(sl = True)
cmds.select(d=True)
for i in range(len(allObj)):
temp = allObj[i+1:]
for j in range(len(temp)):
populationDistance(allObj[i], allObj[i+1+j]) #populationDistance called
if dist <= 2:
populationReact(allObj[i], allObj[i+1+j]) #populationReact called
def main(): #Main function
populationDefine()
curObj = populationPos()
popX = cmds.getAttr(curObj+'.translateX')
popZ = cmds.getAttr(curObj+'.translateZ')
q = ''
while popX < 20 and popX > 0 and popZ < 20 and popZ > 0 and q != 'exit' and cmds.objExists(curObj): #user is prompted until one of these things happens
q = userInput(curObj)
populationDetect()
popX = cmds.getAttr(curObj+'.translateX')
popZ = cmds.getAttr(curObj+'.translateZ')
import maya.cmds as cmds
import random as rand
import math
def populationDefine(): #user input sets parameters for creation of population
global p1, p2, p3
print "Before proceeding, define the following parameters regarding your population: "
#determine population size
p1 = raw_input('Is the population large, medium, or small? ')
print p1, "\n"
if p1 == 'large': #assigns value to global variable based on user input
p1 = 0
elif p1 == 'medium':
p1 = 1
elif p1 == 'small':
p1 = 2
else:
print "Incorrect input, please try again."
main()
#determine population type
p2 = raw_input('Is the population of type predator or prey? ')
print p2, "\n"
if p2 == 'predator':
p2 = 0
elif p2 == 'prey':
p2 = 1
else:
print "Incorrect input, please try again."
main()
#determine population speed
p3 = raw_input('Is the population fast or slow? ')
print p3, "\n"
if p3 == 'fast':
p3 = 0
elif p3 == 'slow':
p3 = 1
else:
print "Incorrect input, please try again."
main()
def objectSize(curObj): #determines poly size based on population size
if p1 == 0:
cmds.scale(1.5, 1.5, 1.5, curObj)
elif p1 == 1:
cmds.scale(1, 1, 1, curObj)
elif p1 == 2:
cmds.scale(.5, .5, .5, curObj)
def objectColor(curObj): #could not get this to work, supposed to assign color
if p2 == 0:
cmds.connectAttr(curObj+'.objectColor', 'matRed')
elif p2 == 1:
cmds.connectAttr(curObj+'.objectColor', 'matBlue')
def populationPos(): #places population randomly in environment
x = rand.randrange(1, 19, 1)
z = rand.randrange(1, 19, 1)
curObj = cmds.polySphere(name='population1', radius=.5, subdivisionsX=10, subdivisionsY=10, axis=(0, 1, 0), createUVs=2, constructionHistory=True)
curObj = curObj[0]
objectSize(curObj)
#objectColor(curObj)
print "Name = ", curObj, "\n"
cmds.addAttr(ln = 'size', at = 'enum', en = "large:medium:small")
cmds.setAttr(curObj+'.size', p1)
cmds.addAttr(ln = 'type', at = 'enum', en = "predator:prey")
cmds.setAttr(curObj+'.type', p2)
cmds.addAttr(ln = 'speed', at = 'enum', en = "fast:slow")
cmds.setAttr(curObj+'.speed', p3)
color = cmds.getAttr( "lambert1.color" )
cmds.setAttr( "lambert1.color", color[0][0], color[0][1], color[0][2], type="double3" )
cmds.setAttr(curObj+".translate", x, 0, z)
return curObj
def userInput(curObj): #user input moves object in direction of choice
q = raw_input('In which direction should the population move? N, S, E, or W? To create a new population, type "new". If you are done, type "exit". ')
print q, "\n"
cmds.select(curObj)
if q == 'n' or q == 'N':
if p3 == 0:
cmds.move(2, 0, 0, relative=True)
elif p3 == 1:
cmds.move(1, 0, 0, relative=True)
elif q == 's' or q == 'S':
if p3 == 0:
cmds.move(-2, 0, 0, relative=True)
elif p3 == 1:
cmds.move(-1, 0, 0, relative=True)
elif q == 'e' or q == 'E':
if p3 == 0:
cmds.move(0, 0, 2, relative=True)
elif p3 == 1:
cmds.move(0, 0, 1, relative=True)
elif q == 'w' or q =='W':
if p3 == 0:
cmds.move(0, 0, -2, relative=True)
elif p3 == 1:
cmds.move(0, 0, -1, relative=True)
elif q == 'new':
main()
elif q == 'exit':
print 'OK \n'
return q
def populationDistance(i, j): #checks the distance between 2 populations
global dist
ix = cmds.getAttr(i+'.translateX')
jx = cmds.getAttr(j+'.translateX')
iz = cmds.getAttr(i+'.translateZ')
jz = cmds.getAttr(j+'.translateZ')
dist = math.sqrt( pow(ix-jx,2) + pow(iz-jz,2) )
def populationReact(i, j): #if populations are close together, they will interact
if cmds.getAttr(i+'.type') == 0 and cmds.getAttr(j+'.type') == 1:
if cmds.getAttr(i+'.size') == 0 and cmds.getAttr(j+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(i+'.size') == 1 and cmds.getAttr(j+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(i+'.size') == 2 and cmds.getAttr(j+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(i+'.size') == 2 and cmds.getAttr(j+'.size') == 1:
print "These two populations can coexist!"
else:
cmds.delete(j)
print "These two populations could not coexist!\n\n"
main()
if cmds.getAttr(j+'.type') == 0 and cmds.getAttr(i+'.type') == 1:
if cmds.getAttr(j+'.size') == 0 and cmds.getAttr(i+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(j+'.size') == 1 and cmds.getAttr(i+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(j+'.size') == 2 and cmds.getAttr(i+'.size') == 0:
print "These two populations can coexist!"
if cmds.getAttr(j+'.size') == 2 and cmds.getAttr(i+'.size') == 1:
print "These two populations can coexist!"
else:
cmds.delete(i)
print "These two populations could not coexist!\n\n"
main()
def populationDetect(): #detects populations near current controlled object
cmds.select('population*')
cmds.select('pop*Shape', d=True)
allObj = cmds.ls(sl = True)
cmds.select(d=True)
for i in range(len(allObj)):
temp = allObj[i+1:]
for j in range(len(temp)):
populationDistance(allObj[i], allObj[i+1+j]) #populationDistance called
if dist <= 2:
populationReact(allObj[i], allObj[i+1+j]) #populationReact called
def main(): #Main function
populationDefine()
curObj = populationPos()
popX = cmds.getAttr(curObj+'.translateX')
popZ = cmds.getAttr(curObj+'.translateZ')
q = ''
while popX < 20 and popX > 0 and popZ < 20 and popZ > 0 and q != 'exit' and cmds.objExists(curObj): #user is prompted until one of these things happens
q = userInput(curObj)
populationDetect()
popX = cmds.getAttr(curObj+'.translateX')
popZ = cmds.getAttr(curObj+'.translateZ')
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()
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()
Sunday, February 12, 2012
Project 2 idea
For this next project I want to try my hand at a little more coding-intensive project. I have two options that I am thinking about:
1) Several "sculpture-creatures" will be created in Maya, as well as an environment that has different kinds of terrain (mountains, swamps, plains, snow etc.). The population of the environment itself will be done thru evolutionary methods. Based on manual scoring of genotypes such as "high altitude/low altitude", "wet/dry areas", "hot/cold areas", the phenotype will be determined. The phenotype in this case is what section of the environment the sculpture-creature would most favor, and then based upon this information, the program would then populate the environment with the sculpture-creatures. Other genotypes could include "size", "predator/prey", and "endangered species" to determine how large the populations should be.
2) If this proves to be too ambitious for a non-proficient programmer like myself, an evolutionary method will be used to create primitive sculpture-creatures based on the manual scoring of genotypes I choose. The sculpture-creatures with the highest "score" will then be placed in an environment that I create in Maya. This will also be coded.
3) If even this proves to be too difficult, I will create a program that only creates sculpture-creatures based on genotype scoring, without the population of environments.
SO. To reiterate:
Step 1: Create environment and sculpture-creatures.
Step 2: Programming.
1) Several "sculpture-creatures" will be created in Maya, as well as an environment that has different kinds of terrain (mountains, swamps, plains, snow etc.). The population of the environment itself will be done thru evolutionary methods. Based on manual scoring of genotypes such as "high altitude/low altitude", "wet/dry areas", "hot/cold areas", the phenotype will be determined. The phenotype in this case is what section of the environment the sculpture-creature would most favor, and then based upon this information, the program would then populate the environment with the sculpture-creatures. Other genotypes could include "size", "predator/prey", and "endangered species" to determine how large the populations should be.
2) If this proves to be too ambitious for a non-proficient programmer like myself, an evolutionary method will be used to create primitive sculpture-creatures based on the manual scoring of genotypes I choose. The sculpture-creatures with the highest "score" will then be placed in an environment that I create in Maya. This will also be coded.
3) If even this proves to be too difficult, I will create a program that only creates sculpture-creatures based on genotype scoring, without the population of environments.
SO. To reiterate:
Step 1: Create environment and sculpture-creatures.
Step 2: Programming.
Step 3: Populate environment with sculpture-creatures.
Monday, February 6, 2012
Project 1: Creature Design by Chance
Above is a video detailing the method used to create my final creature designs. I consider the method as much of a part of the project as the final results.
Subscribe to:
Comments (Atom)










