List access, condition statements

## 1. item access

Place GhPython components like this.

For the time being, we keep using Item Access

The codes on "from" and "to" ends are:

You will get

## 2. item access

Let's switch to List Access.

Now, the "To" end component turned to Red. This is because circle is a list type object and not a tuple.

Let's modify the code a little bit.

You will get the same result as the previous one.

## 3. Gaussian hill

Surface version of the Gaussian function.

import rhinoscriptsyntax as rs import math F=lambda x,y:( A*math.exp(-((x-x0)**2+(y-y0)**2)/ (2*(C**2)))) a=list() for i in rs.frange(-1.0,1.0,0.05): for j in rs.frange(-1.0,1.0,0.05): a.append(rs.AddPoint(i,j,F(i,j)))

## 4. Splitting Gaussian Hill

## 5. Gaussian hill with List Access

Let's change the access type of "hill" to List Access.

Let's rename the "hill" "hills".

Our new code for To end is

import rhinoscriptsyntax as rs import math _F=lambda x,y,A,C,x0,y0:( A*math.exp(-((x-x0)**2 +(y-y0)**2)/(2*(C**2)))) def F(x,y): z=0 for hill in hills: (A,C,x0,y0)=hill #Unpacking z+=_F(x,y,A,C,x0,y0) return z a=list() for i in rs.frange(-1.0,1.0,0.05): for j in rs.frange(-1.0,1.0,0.05): a.append(rs.AddPoint(i,j,F(i,j)))

Note that

F=lambda x:x**2

is equivalent to

def F(x): return x**2

If you duplicate From end like this

You may get somthing like this

## 6. Condition statements

a=1 print a==1 print a==2 print a<1 print a<=1 print a!=1

a=1 b=2 print a==1 and b==2 print a==1 or b==2 print a==1 and b==3 print a==1 or b==3

page revision: 33, last edited: 12 Nov 2013 11:08