class assignment shenting wang

Capture
import rhinoscriptsyntax as rs
import math as mt
import random as rd
def exer01():
    """create a list and use it for itertaion
    """
    mylist = range(10) # [0,1,2,...,9] start at 0, ending is 10 - 1
    print mylist
    mylist = range(1,10)
    print mylist
    mylist = range(1,5) # 5 is the ending number excluding itself
    print mylist
    mylist = range(1,20, 2) # starts at 1, ending at 20-1, increase with a step 2
    print mylist
    mylist = range(40, -1, -2)
    print mylist
    mylist = rs.frange(0, 10, 0.5)
    print mylist
    mylist = range(100)
def makeTriangles(item):
    p0 = item,          item,       0
    p1 = item + 1,      item,       0
    p2 = item + 0.5,    item + 1,   0
    points = p0,p1,p2,p0
    rs.AddPolyline(points)
def makeTriangles2(item, id):
    p0 = 0,      0,       0
    p1 = 1,      0,       0
    p2 = 0.5,    1,       0
    origin = 0,0,0
    scale = item+1, item+1, item+1
    id = rs.ScaleObject(id, origin, scale, True)

    center = origin
    rad = mt.radians(45) #calculate radians for 45 degree
    angle = item * mt.sin(rad)
    id = rs.RotateObject(id, center, angle)

    translation = item, item, 0
    id = rs.MoveObject(id, translation)
    return id
def makeTriangles3(item):
    p0 = 0,      0,       0
    p1 = 1,      0,       0
    p2 = 0.5,    1,       0    

    origin = 0,0,0
    scale = item+1, item+1, 1
    id = rs.ScaleObject(id, origin, scale)

    center = origin
    rad = mt.radians(45)* -1 #calculate radians for 45 degree
    angle = item * mt.sin(rad)
    id = rs.RotateObject(id, center, angle)

    translation = item, item, 0
    id = rs.MoveObject(id, translation)
def makeInitialShape(item,id):
    origin = 0,0,0
    scale = item/10+1, item/10+1, 1
    id = rs.ScaleObject(id, origin, scale,True)

    center = origin
    rad = mt.radians(1) #calculate radians for 45 degree
    angle = item * mt.sin(rad)*50
    id = rs.RotateObject(id, center, angle)

    translation = item, item, 0
    id = rs.MoveObject(id, translation)
    return id

def exer02():
    """ make a for loop using a list
    """
    id = rs.GetObject()
    mylist = range(10)
    for item in mylist:
        id = makeInitialShape(item, id)
        mirror1 = rs.MirrorObject(id,[0,0,0],[0,1,0],True)
        mirror2 = rs.MirrorObjects (mirror1,[0,0,0],[1,0,0],True)
        mirror3 = rs.MirrorObjects (id,[0,0,0],[1,0,0],True)
        print id

def exer03():# make a field of points vertically
    xlist = range(10) # 0,1,2,3,...9
    ylist = range(10)
    for x in xlist:
        for y in ylist:
            point = x,y,0
            rs.AddPoint(point)
            rs.Sleep(500)

def addPointsinYList(x):
    ylist = range(10)
    for y in ylist:
        point = x,y,0
        #print point
        rs.AddPoint(point)
        rs.Sleep(500)
def exer03B():# make a field of points vertically
    xlist = range(10) # 0,1,2,3,...9
    for x in xlist:
        addPointsinYlist(x)

def exer04():# make a field of points horizontally
    xlist = range(10) # 0,1,2,3,...9
    ylist = range(10)
    for y in ylist:
        for x in xlist:
            point = x,y,0
            #print point
            rs.AddPoint(point)
            rs.Sleep(500)
def exer05():# make a filed of cube (3D)
    xlist = range(10) # 0,1,2,3,...9
    ylist = range(10)
    zlist = range(10)
    for x in xlist:
        for y in ylist:
            for z in zlist:
                point = x,y,z
                #print point
                rs.AddPoint(point)
                rs.Sleep(10)

def addCircles(x,y, distance):
    center = x,y,0
    rad = distance/10
    rs.AddCircle(center, rad)
def exer06():
    attractor = rs.GetPoint()
    print attractor
    xlist = range(30)
    ylist = range(30)
    for x in xlist:
        for y in ylist:
            #calculate distance
            pt1 = attractor
            pt2 = x,y,0
            distance = rs.Distance(pt1, pt2)
            #make a cylinder
            base = x,y,0
            height = distance/50
            rad = distance/30
            id = rs.AddCylinder(base, height, rad, True)

def main():
    #exer01()
    exer02()
    #exer03()
    #exer04()
    #exer05()
    #exer06()
main()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s