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])