Class Practice Two – Smart Windrose

 

 

 

 

This is the second in-class practice doing a control structure program that generates a smart wind rose in Rhinoceros.

Here is the Python Code:


#this links python to rhino
import rhinoscriptsyntax as rs
import math as m
import random 

#use \ to break the line/command
#use comma between values, before the command ends, don't close it with parenthesis

#def means to define
#keyword, the name of the function, parameters: the definition

rs.DeleteObjects (rs.AllObjects())

def windrose (intCardinalPoints,dblCardinalLength, translation):

    dblL = 2.0
    angCardinal = m.radians ((360 / intCardinalPoints) / 2)
    #angCardinal is an angle in radians
    ptX = dblL * m.cos(angCardinal)
    ptY = dblL * m.sin(angCardinal)

    #print (ptx)
    #cos(angCardinal)

    #drafts a cardinal point
    #there are 2 kuohao
    objCardinalPoint = rs.AddPolyline\
    (([0,0,0],[ptX,ptY,0],[dblCardinalLength,0,0],[ptX,-ptY,0],[0,0,0]))

    #print (objCardinalPoint)  

    #selests all
    #rs.SelectObjects(rs.AllObjects())

    #copies around the center
    rs.SelectObject (objCardinalPoint)
    
    for i in range (1,intCardinalPoints+1):
        angle = 360 / intCardinalPoints
        new = rs.RotateObject (objCardinalPoint, [0,0,0], angle*i, None, True)
        #python random website: 9.6. random-generate pseudo number (between 0 and 1)
        f = random.random ();
        rs.ScaleObject (new, [0,0,0],[f,f,f])

    #rs.Command ("arrayPolar 0,0 " + str(intCardinalPoints) + " 360 Enter")
    
    #rs.MoveObject (rs.LastCreatedObjects (), translation)
    #rs.MoveObject (objCardinalPoint, translation)

    rs.UnselectAllObjects()

intCardinalPoints = rs.GetInteger ("Please insert number of cardinal points", 27)
dblCardinalLength = rs.GetInteger ("Enter Length of cardinal point", 27)

#now its not working, we need to invoke the function:

#windrose (intCardinalPoints,dblCardinalLength)
#windrose (20,10)   even if you enter 100, 200 etc, it will still be 20,10

#with all commands below, it will run one by one and stop at the last one:
while (dblCardinalLength < 2): 
    print ("That number is too short")
    dblCardinalLength = rs.GetInteger ("Enter Length of cardinal point", 10.0)
else: 
    windrose (intCardinalPoints ,dblCardinalLength, [0,0,0])

Exercise One – Python Batch Program

 

 

 

 

This is Exercise One: Python Batch Program. For this exercise, we were asked to write a working batch program that generates a very simple drawing, such as a pattern of tiles, a type of window, a section of a pillar, a bathroom, etc, making use of the functions we have learned during the first three classes.

 

Here is the Python Code:


import rhinoscriptsyntax as rs
import math as m

#four points: 0,0 3,-y 6,0 3,y
#angle: 30degrees  rad=deg*pai/180
#y=3*tan30=1.73205

rs.DeleteObjects (rs.AllObjects())

#Assign coordinates to an object
obj = rs.AddPolyline (([0,0,0],[3,-1.73205,0],[6,0,0],[3,1.73205,0],[0,0,0]))

#Give coordinates of center point, and rotate
point = [0,0,0]
rs.RotateObject (obj, point, -60, None, copy=True)

point = [6,0,0]
rs.RotateObject (obj, point, 60, None, copy=True)

rs.SelectObjects(rs.AllObjects())

#Array
intx = rs.GetInteger ("Please insert number of diamonds", 18)
rs.Command ("arrayLinear " + str(intx) + " 0,0 6,0")


rs.SelectObjects(rs.AllObjects())

#angle: 30degrees
#Long=6, x=Long*sin30=3, y=Long*cos30=5.19615

intx = rs.GetInteger ("Please insert number of diamonds", 27)
rs.Command ("arrayLinear " + str(intx) + " 0,0 3,-5.19615")

Aobj = rs.AllObjects()

#rs.Command ("arrayPolar 0,0 6 360 Enter")

for i in range (1,6):
    angle = 360/6
    rs.RotateObjects (Aobj, [0,0,0], angle*i, None, True)

Class Practice One – Wind Rose

This is the first in-class practice doing a simple declarative program that generates a wind rose in Rhinoceros.

Here is the Python Code:

 


#this links python to rhino
import rhinoscriptsyntax as rs

rs.DeleteObjects (rs.AllObjects ())

#use \ to break the line/command
#use comma between values, before the command ends, don't close it with parenthesis
dblTextHeight = rs.GetReal \
    ("Please insert text Height", \
    1.0)
dblCardinalLength = rs.GetReal \
    ("Please insert cardinal length", \
    15)

intCardinalPoints = rs.GetInteger ("Please insert number of points", 4)


#drafts a cardinal point
#there are 2 kuohao
rs.AddPolyline (([0,0,0],[2,1,0],[dblCardinalLength,0,0],[2,-1,0],[0,0,0]))

#drafts a subcardinal point
rs.AddPolyline (([0,0,0],[2,1,0],[4,4,0],[1,2,0],[0,0,0]))

#selests all
rs.SelectObjects(rs.AllObjects())

#copies around the center
print ("arrayPolar 0,0 " + str(intCardinalPoints) + "360 Enter")
rs.Command ("arrayPolar 0,0 " + str(intCardinalPoints) + "360 Enter")

#add the North
rs.AddText ("N", [-.5,dblCardinalLength +1.0,0], dblTextHeight)

rs.UnselectAllObjects()