Thursday, May 28, 2009

Monday, May 25, 2009

O2A_DengLei




I creat some curves but they all in the same position , i mean they are all overlap, i divide by hand


03 - Diana Pérez - Curves

I tried this script to create curves out of the points created with the Math Function script I wrote before, but somehow it's not drawing the curves. Could you tell me what's wrong?

Thanks


#function to create curves on the fly
def curves(amplitude):
#define initial variables
numPoints = 600
amplitude = 10

#create an empty list to store the points
points = []

#loop and gather point information
for i in range (0, numPoints, 1):
#funtion for the curve
x = sin(i)*i
y = (cos(i)*sin(i))*i
z = i*amplitude/10
myPoint = (x, y, z)
#store the point in the list
points.append (myPoint)

#create the curves
myCurve = cmds.curve(d=3, p=points) #degree 3
return myCurve

02B - Diana Pérez - Math Function


#define initial variables
numPoints = 600
amplitude = 10

#loop and gather point information
for i in range (0, numPoints, 1):
#funtion for the curve
x = sin(i)*i
y = (cos(i)*sin(i))*i
z = i*amplitude/10
myPoint = (x, y, z)
cmds.spaceLocator (p = myPoint)(your code here)


02A - Diana Pérez - 3D Grid

This is the assignment about making a 3D grid of points, which I couldn't make work the last time.

# GRID 3D
numColumns = 30
numRows = 30
numLevels = 30

for i in range (0, numColumns, 1):
x = i
for j in range (0, numRows, 1):
y = j
for k in range (0, numLevels, 1):
z = k
myPoint = [x, y, z]
cmds.spaceLocator (p = myPoint)


02A_COSMOS_CURVES


import maya.cmds as cmds

#craeting curves through points

from math import*

numRows = 20
numColumns = 20
num3rdDimension = 1
Points=[]
for i in range(0,numRows,1):
x = (i)
for j in range(0,numColumns,1):
y = j
for k in range(-1,num3rdDimension,1):
z = sin(k*i*j)# this will craete an undulating grid
myPoint=(x,y,z)
points.append(myPoint)
cmds.curve(d=3, p=points)


Sunday, May 24, 2009

01B_COSMOS_POINTS


import maya.cmds as cmds

#creating a 3d points grid using mathematical function

from math import*

numRows = 20
numColumns = 20
num3rdDimension = 1
for i in range(0,numRows,1):
x = (i)
for j in range(0,numColumns,1):
y = j
for k in range(-1,num3rdDimension,1):
z = sin(k*i*j)# this will craete an undulating grid
myPoint=(x,y,z)
cmds.spaceLocator(p=myPoint)

02A_Natasha_from points to curves

import maya.cmds as cmds
from math import *
from random import *
numRows = 5
numColumns = 7
numLevels = 5
amplitude = 4
points = []

#define curves first 
for i in range(0, numRows, 1):
x = tan(3*i)*amplitude
for j in range(0, numColumns, 1):
y = sin(2*j)*amplitude
for k in range(0, numLevels, 1):
z = k+amplitude
myPoint = [x,y,z]
print "point ", x, y, z
points.append(myPoint)
#create curves from points
cmds.curve(d=1, p=points)

02A - Deborah Kaiser - from point to curves

Daniel, i took the function from the previous exercise but i can not get it to turn the points into a curve. What am i doing wrong?

Thnx!


def curves (amplitude):
numPoints = 200
amplitude = 1
points = []


for i in range (0,numPoints,1) : # (start, end, increment)ve
x = i + 3*i
y = cos (i)*amplitude*10
z = i*x*.001 + y*0.0001 +1
myPoint = [x,y,z]
points.append (myPoint)


myCurve = cmds.curve (d =3, p= points)
return myCurve

01A - Deborah Kaiser - making rice

Sorry it is so overdo, i was not getting the e mails...

function cook rice:

function fillCup:
get cup
get rice bag
place cup right to rice bag
with rice bag:
move 20cm up
turn -90°
if cup = „full“
with rice bag:
turn 90°
move 20cm down

with cup:
get pan
turn 90°
let all content fall into pan


function fillCup:
get cup
get water jar
place cup right to water jar
with water jar:
move 20cm up
turn -90°
if cup = „full“
with water jar:
turn 90°
move 20cm down

with cup:
get pan
turn 90°
let all content fall into pan



execute function makeRice

function makeRice:
desiredSalt = 2
desiredTime = 10 min

get pan
with pan:
place on burner
turn burner on

start counting time
if time = 10min:
turn burner off

finish

01B - Deborah Kaiser - function, succesful attempt

01B - Deborah Kaiser - function, succesful attempt

from math import *

numPoints = 200
amplitude = 1


for i in range (0,numPoints,1) : # (start, end, increment)
x = i + 3*i
y = cos (i)*amplitude*10
z = i*x*.001 + y*0.0001 +1
myPoint = [x,y,z]
cmds.spaceLocator (p=myPoint)

01B - Deborah Kaiser - 3d grid, succesful attempt




# 3d grid

numColumns = 30
numRows = 30
numHeights = 30

for k in range (0, numHeights,1):
z = k
for i in range (0, numColumns,1):
x=i
for j in range(0,numRows, 1):
y = j
myPoint = [x,y,z]
cmds.spaceLocator (p=myPoint)

02A_Clau_from points to curves

In the first part of this exercise I took the code of the previous assingment, but instead of plotting points I generated curves (see image). Then I tried to convert the code into a function and return the value but didn't get a result. I have a Syntax Error. I don't know where is the mistake.


import maya.cmds as cmds
from math import*
from random import*
######################################################
#from points to curves
#defining initial variables
numRows= 40
numColumns=4
numLevels=12
amplitude = 12

#create an empty list to store the points
points= []

#defining the loop and gather information
for i in range (-1,numRows,1):
x= sin(6*i)*amplitude
for j in range (-1,numColumns,2):
y= cos(i)*8
for k in range (0,numLevels,1.5):
z= k+1
myPoint=(x,y,z)
#store the point in the list
points.append(myPoint)

#create the curve
cmds.curve (d= 3, p= points) #curve degree 3

######################################################
######################################################
#2ND PART
#####################################################
#defining initial variables
numRows= 40
numColumns=4
numLevels=12
amplitude = 12

#defining the curve
def Curves (numPoints, amplitude)

#create an empty list to store the points
points= []

#loop and gather point information
for i in range (-1,numRows,1):
x= sin(6*i)*amplitude
for j in range (-1,numColumns,2):
y= cos(i)*8
for k in range (0,numLevels,1.5):
z= k+1
myPoint=(x,y,z)
#store the point in the list
points.append(myPoint)

#creating the curve
myCurve= cmds.curve (d=3, p=points) #curve degree 3

#returning the name of the curve created
return myCurve


import maya.cmds as cmds
from math import *
from random import *

radius = 50
numCirc = 10
amplitude = 2

def curves(amplitude):
numPoints = 10
points = []
#loop and gather point information
for i in range (1, numPoints, 1):
#function for the spiral curve
x = sin(i)*amplitude
y = cos(i)*amplitude
z = i*(i+1)
myPoint = (x,y,z)
#store the point in the list
points.append(myPoint)

#create the curve
myCurve = cmds.curve (d = 3, p=points) #degree 3
return myCurve

numCol = 10
numRows = 10

def array(numCol):
#create empty list of curvs
numCurvs = []
for j in range (0, 360/numCirc, 1):
#create curve and then rotate
crv = curves (j)
cmds.rotate( 0, 10*j, 0, crv )
#store the point in the list
numCurvs.append (crv)
cmds.select (numCurvs)# select the number of created curvs
cmds.group (numCurvs, r=True)

#loop which made copies of created curvs in 2 directions
for m in range (0, numRows, 1):
for n in range (0, numCol, 1):
ar = array (1)
s = randint(0,3)
cmds.move (n*200, 0, m*200)
#change the size of group of curvs
cmds.scale (s,s,s)

squareINsquare (3)

Saturday, May 23, 2009

Wednesday, May 20, 2009

For next class

As I told you last class, you should have an external script editor installed in your computer. Here is a list of nice editors, just choose one:

If you don't like any of those, feel free to chose any other you desire. Just be sure it has Python syntax highlighting.

It would be great if you could setup your computer to make it able work with external scripts. Here is a step-by-step tutorial on how to do that.

Tuesday, May 19, 2009

Assignment 02A

For this assignment you should do two things:

  1. Take the code you developed for the assignment 01A and use it not to plot points, but to generate a curve
  2. Convert this code into a function with arguments and return value, and use it in a loop to generate several different instances of your curve

Like usual, you should post the script along with screenshots. Don’t forget to comment all your code!

Delivery limit: 24.05 by noon.

w03 code: from points to curves

First we saw how to store the points coordinates generated in a loop into an empty list , and then use this list to generate a curve:

import maya.cmds as cmds

#generating a straight line with even spacing between points
#define initial variables
numPoints = 20.0 #we use floats instead of integers so that the division below works properly
lineLength = 30.0
spacing = lineLength/numPoints #spacing between points


#create an empty list to store my points
#it is empty and will be "populated" in the following loop
points = []

#loop and get point coordinates
for i in range(0, numPoints, 1): #(start, end, increment)
#define x y and z variables
x = spacing*i #this will vary in each loop
y = 0
z = 0
#put all these variables in a list
myPoint = (x,y,z)

print "point ", i, myPoint #shows in the output window the point coordinates which were generated above (just for your feedback)

#append the point to the list (add it to the end of the list)
points.append(myPoint)


print "points list = ", points #for your feedback

#after the loop, I have all points in my "points" list
#now I can use the curve command to create my curve
#by using the points in "points"
cmds.curve(d=1, p=points) #creates a curve of degree 1 > linear curve
cmds.curve(d=3, p=points) #creates a curve of degree 3 > "curved" curve


Then we looked at some functions to make operations on list objects:



#some list functions
#first we create a new list
myList = ["Dessau", "Germany", "europe"]
print myList

#add element to list
myList.append("world")
print myList

#remove element from list
myList.remove("world")
print myList

#insert element in a specified place (specified by the index value)
myList.insert(1, "DIA")
print myList

#remove the last element
myList.pop()
print myList

#sort the elements of the list alphabetically
myList.sort()
print myList


Then we looked quickly at another function to gather point coordinated and generate a curve, which in this case resembles a helix:



#import all functions of the math module
#we will use the function sin() and cos()
from math import *

#define initial variables
numPoints = 60
amplitude = 2

# create an empty list to store the points
points = [ ]

#loop and gather point information
for i in range( 1, numPoints, 1) :
#function for the spiral curve
x = sin( i ) * amplitude
y = cos( i ) * amplitude
z = i / 10
myPoint = (x,y,z)
#store the point in the list
points.append(myPoint)

#create the curve
cmds.curve( d = 3, p = points ) #degree 3


The we started to look at functions. We saw some simple examples of functions with and without arguments, and how to define and call them:



#FUNCTIONS - INTRO

#first we need to define the function
def myFunction( ):
print "Hello world!"

#the code above doesn't do anything apparently
#but it stores the function definition on memory and
#you can use it by calling the function:
myFunction()

#you'll see the command indented under the function
#be executed and printing the text we wrote

#functions get more interesting when we start
#to add arguments to it:

def printMessage( msg ):
print msg

#the definition above means that this function
#takes as an argument the variable "msg"
#and inside the function we use this argument and print it

#to call this function you have to pass the argument in the function call:
printMessage( "this is my message" )

#you can also pass a pre-defined variable as the argument
#and python will do all the replacing and printing the same way:
a = "Another message"
printMessage( a )


Finally, we took the helix code and converted it into a function:



#converting the helix code into a function
#first import the math module if you still did not do so
from math import *

#then start the function definition
def curves( numPoints, amplitude ):
#it takes as an argument the value of the amplitude of the curve
#and the number of points we want in the curve

#then we just repeat the code of the helix
# create an empty list to store the points
points = [ ]

#loop and gather point information
for i in range( 1, numPoints, 1) :
#function for the spiral curve
x = sin( i ) * amplitude
y = cos( i ) * amplitude
z = i / 10
myPoint = (x,y,z)
#store the point in the list
points.append(myPoint)

#now as we saw, every command in Maya returns me a value
#you can see which values each function returns,
#take a look at Help > Python Command Reference
#and we can store this value in a variable to use it later:
myCurve = cmds.curve( d = 3, p = points ) #degree 3

#also in our own functions we can return values
#in this case, we will return the name of the curve created above
return myCurve


In the end, we saw how to use our new function to generate several curves on the fly. By using the arguments, we can vary each curve, and by using the return value, we can make modifications on the curve after its creation:



#function call in a loop
#first we define how many curves we want
numCurves = 10

#then run the loop
for i in range(0, numCurves, 1):
#then inside the loop we call the function
#and store its return value in the variable crv
crv = curves(60, i ) #arguments (numPoints, amplitude)

#as we stored the return value (in our case, name of the curve)
#in the variable crv, we can later use it to
#do anything we want with the curve
#in this case, we'll move it along the x-axis:
cmds.move(i*10, 0, 0, crv)

Week 03 - recap

Yesterday in our third class we saw how to move from point generation to curves. We reused the code from last class and captured the point coordinates and instead of plotting points, we learned how to use them to generate curves.

Also, we learned about functions and their importance in scripting. We converted previous code into a function to see how it allows us to have more flexibility in our scripts.

Monday, May 18, 2009

Deborah & Diana Intent 2 - Doubt

#We couldn't make this work either

from math import *

numPoints = 200
amplitude = 10
for i in range (0,numPoints,1) : # (start, end, increment)
x = (i*i + 3i + 5)
y = cos (i)*amplitude
z = i*x + y*y +1
myPoint = [x,y,z]
print myPoint
cmds.spaceLocator (p=myPoint)

Deborah & Diana Intent - Doubt

# Daniel, it's not working. Can you tell us why?

numRows=20
numColumns=50
numLevels=70

for i in range (0,numRows,1):
x=i
print "x", i
for j in range (0,numColumns,1):
y=j
print "y", j
for k in range (0,numLevels,1):
z=k
print "z", k
myPoint = (x,y,z)
cmds.spaceLocator (p=myPoint)

Deng_Point




Zhulei_ points in grids


import maya.cmds as cmds
from math import *

numColumns=10

for k in range(0,numColumns,1):
z=2 * k
for i in range(0, numColumns,1):
x=4*tan(i)
for j in range(0,numColumns,1):
y=3 * sin(j)

myPoint= [x,3*sin(30*z),z]
cmds.spaceLocator(p=myPoint)

clau_tower of points



#creating a tower of points
numRows= 90
numColumns=42
numLevels=12
amplitude = 5
for i in range (-1,numRows,1):
x= sin(6*i)*amplitude
print "row", i
for j in range (-1,numColumns,2):
y= cos(i)*3
print "column", j
for k in range (0,numLevels,1.5):
z= k+1
myPoint=(x,y,z)
cmds.spaceLocator(p=myPoint)

clau_grids of points


#grid of points using nested loops
#rotating grids of points in "z" axis
numRows=12
numColumns=10
for i in range (0,numRows,2):
x=i
print "row", i
for j in range (0,numColumns,1):
y=j+1
print "column", j
z=1
myPoint = (x,y,z)
cmds.spaceLocator (p=myPoint

numRows=12
numColumns=10
for i in range (0,numRows,2):
x=i/2
print "row", i
for j in range (0,numColumns,1):
y=j+1
print "column", j
z=-1
myPoint = (x,y,z)
cmds.spaceLocator (p=myPoint)

numRows=12
numColumns=10
for i in range (0,numRows,2):
x=-i/2
print "row", i
for j in range (0,numColumns,1):
y=-j
print "column", j
z=2
myPoint = (x,y,z)
cmds.spaceLocator (p=myPoint)

numRows=12
numColumns=10
for i in range (0,numRows,2):
x=-i
print "row", i
for j in range (0,numColumns,1):
y=j
print "column", j
z=3
myPoint = (x,y,z)
cmds.spaceLocator (p=myPoint)

numRows=12
numColumns=10
for i in range (4,numRows,2):
x=i
print "row", i
for j in range (0,numColumns,1):
y=j+2
print "column", j
z=5
myPoint = (x,y,z)
cmds.spaceLocator (p=myPoint)

clau_plot points



#random points loop using negative numbers
numPoints = 60
for i in range (-5,numPoints,1):
x= randint(0,5) #this generate a random integer between 0 and 5
y= randint (0,5)
z= 0
myPoint= (x,y,z)
cmds.spaceLocator (p=myPoint)

numPoints = 100
for i in range (-5,numPoints,1):
x= randint(0,5) #this generate a random integer between 0 and 5
y= randint (0,5)
z= 5
myPoint= (x,y,z)
cmds.spaceLocator (p=myPoint)

numPoints = 60
for i in range (-5,numPoints,1):
x= randint(-5,0) #this generate a random integer between 0 and 5
y= randint (-5,0)
z= 10
myPoint= (x,y,z)
cmds.spaceLocator (p=myPoint)

numPoints = 100
for i in range (-5,numPoints,1):
x= randint(-3,0) #this generate a random integer between -3 and 0
y= randint (0,5)
z= 10
myPoint= (x,y,z)
cmds.spaceLocator (p=myPoint)

numPoints = 180
for i in range (-5,numPoints,1):
x= randint(-3,0) #this generate a random integer between -3 and 0
y= randint (-5,5)
z= -5
myPoint= (x,y,z)
cmds.spaceLocator (p=myPoint)

numPoints = 240
for i in range (-5,numPoints,1):
x= randint(-5,10) #this generate a random integer between -5 and 10
y= randint (-5,0)
z= -3
myPoint= (x,y,z)
cmds.spaceLocator (p=myPoint)

Sunday, May 17, 2009

Friday, May 15, 2009

# create cylinder with nonuniform density of points

import maya.cmds as cmds
from math import *

from random import *

radius = 10
numCirc = 10

for n in range (0, numCirc, 1):
y = n #Number Of Elements By Y Axis
for i in range (0, 36, 1):
cmds.rotate( 0, 10*i, 0, pivot=(1, 0, 0) )
x = radius #create circle
z = randint (0,2)
myPoint = [x, y, z]
cmds.spaceLocator (p
= myPoint)

Assignment 01B

You should try to plot points in different ways. Here are some guidelines:

Most important: use your imagination. And if you get stuck, try to delineate the logic behind your idea (remember the pseudo-code exercise) to try and make it clearer.

Also important: don’t forget to comment each line in your code (by using #, as we saw last class).

Post your results along with screenshots on the blog.

Thursday, May 14, 2009

numColumns = 10
numRows = 10
numHeights = 10

for k in range (0, numHeights,1):
z = k
for i in range (0, numColumns,1):
x=i
print i
for j in range(0,numRows, 1):
y = j

myPoint = [x,y,z]
cmds.spaceLocator (p=myPoint)

w02 – Plotting point in space

We can’t forget to always write in the beginning of our script:

import maya.cmds as cmds

We then saw how to create a variable to define the coordinates x,y,z of a point, and then use it to create a locator on that position.

# points x,y,z
myPoint = (0,0,0)
cmds.spaceLocator() #this will create a locator in the default position (0,0,0)
cmds.spaceLocator(p=myPoint) #this will create a locator on the position define in myPoint
# change the point values
myPoint = (10,2,0) # keep z=0 to work in 2D only
cmds.spaceLocator(p=myPoint)

Next step was to create several points at once by using loops.

#how to create lots of points
#LOOPS

numPoints = 10 #define the number of desired points

for i in range(0, numPoints, 1):
cmds.spaceLocator()

#the loop above created 10 locator, but all of them on the default position
# I can place the locators in a variable position
# if I use the i variable as one of the position values
for i in range(0, numPoints, 1):
myPoint = (i,0,0)
cmds.spaceLocator(p=myPoint)

#other examples:
for i in range(0, numPoints, 1):
myPoint = (i,i,0)
cmds.spaceLocator(p=myPoint)

for i in range(0, numPoints, 1):
myPoint = (i*10,i+5,0)
cmds.spaceLocator(p=myPoint)

Then we used random functions to generate x,y values. For that, we first need to import the random module as we did for the maya.cmds module.

# import all the functions from the random module
from random import *

numPoints = 20
for i in range(0,numPoints,1):
x = randint(0,10) #this generates a random integer between 0 and 10
y = randint(0,10)
z = 0
myPoint = (x,y,z)
cmds.spaceLocator(p=myPoint)

Then we saw an example of how to plot points in a straight lines with evenly spaced distances:

# how to plot points in a line of a certain length
numPoints = 20
lineLength = 30
#divide to get the space between the points
spaces = lineLength/numPoints
for i in range(0, numPoints, 1):
x = spaces*i
y = 0
z = 0
myPoint = (x,y,z)
cmds.spaceLocator(p=myPoint)

We then saw how to create grids of points with rows and columns, by using nested loops.

## how to create grids of points > rows and columns
## NESTED LOOPS!

numRows = 10
numColumns = 10
for i in range(0, numRows, 1):
x = i
print "row ", i
for j in range(0, numColumns, 1):
print "column ", j
y = j
z = 0
myPoint = (x,y,z)
cmds.spaceLocator(p=myPoint)

Finally, we started to use mathematical functions to plot points, such as the sine and cosine functions. Again, we need to import the math module in order to be able to use mathematical functions in Python. 
#how to use mathematical function to plot the points!
#sine function
from math import *

numPoints = 30
for i in range(0, numPoints, 1):
x = sin(i)
y = i
z = 0
myPoint = (x,y,z)
cmds.spaceLocator(p=myPoint)

#add amplitude

numPoints = 60
amplitude = 2
for i in range(0, numPoints, 1):
x = sin(i)*amplitude
y = i
z = 0
myPoint = (x,y,z)
cmds.spaceLocator(p=myPoint)

### spiral
numPoints = 60
amplitude = 2
for i in range(0, numPoints, 1):
x = sin(i)/i*amplitude
y = cos(i)/i*amplitude
z = 0
cmds.spaceLocator()
cmds.scale(.1,.1,.1)
cmds.move(x,y,z)

Week 02 - recap

Last Monday we took a quick look at the Maya interface and learned how to start scripting with Python. We learned the difference between Python/MEL, and how to use the script editor window to input Python code in Maya.

We also saw different ways to get help on a particular command (quick help and command reference), and how to convert a MEL command from the output window into Python.

In the end, we saw how to use variables, loops, Math functions and Random functions to plot points (locators) on stage.

Monday, May 4, 2009

clau.pseudo-code again

I realized what the problem was with my code flow and here I fix it. I hope it is ok. Again I have problems with identation, I don´t know how to controll it in order to have desired order of functions

Buy a train ticket to Berlin in a ticket-vending machine.

For humans
Go to the ticket machine
Press the button Ticket- Reservation
Select the departure and destination cities
Select the date and time
Select the number of travelers
Select the means of transport
Press search button
Select the journey that fit best with your request
Press purchase button and proceed to buy the ticket


For computers
function informationRequest:
with ticketMachine
press ticketMachine.monitor
select ticketReservation.button
press departure.button
with the keyboard on the monitor
write Dessau
press DessauHbf.button
press destination.Key
with the keyboard on the monitor
write Berlin
press BerlinHbf.button
desiredDay = Today
desiredTime = 23:00
desiredTravelers = Adult
desiredTravelers.number = 1
desiredTravel.class= secondClass
desiredMeansTransport = localTransport
press search.button
execute function selectionJourney

function selectionJourney:
on standardFare.column and
along dep 23.17 arr 01:06.row
press purchase.button
execute function buyTicket

function buyTicket:
get credit.Card
with credit.Card
move 20 cm right
move 5 cm up
insert credit.Card inside ticketMachine.slot

when hear “beep” sound
remove creditCard
put creditCard in initial position
with keyboard near ticketMachine.slot
write creditCard.pinCode
press B button
wait monitor change image
move 60 cm down
open window
remove ticket
execute function remove ticket
else:
finish