Rhino Python Lecture 2016 | DAY3
Contents
- RhinoScriptSyntax (2) – Review
- Draw Model
- Edit Model
- If statement
- Comparison operator
- Logical operator
- Exercise
- Practice 1
- Pattern of diagonal area
- Practice 2
- The golden spiral
1. RhinoScriptSyntax (2) – Review
1.1. Draw Models
Ex1)AddRectangle()
Ex2)AddArc()
import rhinoscriptsyntax as rs r = 5.0 origin = [0.0, 0.0, 0.0] rec = rs.AddRectangle(origin, r, r) arc = rs.AddArc(origin, r, 90.0)
1.2. Edit Models
Ex3)RotateObject()
import rhinoscriptsyntax as rs r = 5.0 origin = [0.0, 0.0, 0.0] rec = rs.AddRectangle(origin, r, r) for i in range(16): rs.RotateObject(rec, origin, 30.0*i, [0,0,1], True)
2. If statement
Conditional Branch – To branch processes in programming, use “if… elif… else…” syntax. The space before lines next to the “if”, “elif”, “else” lines are necessary to define paragraph in program.
There are several relational operators—“Comparison operator”, “Logical operator”
2.1. Comparison operator
- > – larger(greater) than
- < – smaller(less) than
- == – equal to
- != – not equal to
- >= – larger(greater) than or equal to
- <= – smaller(less) than or equal to
################################################## #Comparison operator ################################################## x = 0 if x>5 : a = "x is higher than 5" elif x<5 : a = "x is lower than 5" else : a = "x is 5"
2.2.Logical operator
- and – (a and b) is true
- or – (a or b) is true
- not – Not(a and b) is false.
################################################### #Logical operator - Two conditional expressions ################################################### a = 0 b = 1 #If both the operands are true then condition becomes true. if a == 0 and b == 1: print "(a and b) is true" #If any of the two operands are true then condition becomes true. if a == 0 or b == 1: print "(a or b) is true" #Used to reverse the logical state of its operand. if not(a == 0 and b == 1): print "Not(a and b) is true." ################################################## #Logical operator - Three conditional expressions ################################################## a = "a" b = "a" c = "a" if a == "a" and b == "b" and c =="c": print "(a and b and c) is true" if a == "a" or b == "b" or c =="c": print "(a or b or c) is true" if not(a == "a" and b == "b" and c =="c"): print "Not(a and b and c) is true."
2.3.Exercise
—from RhinoPython¹º¹ Primer p.18
3. Practice 1
Please send your program data to Shuta by the end of the day
→ Submission is closed.
3.1. Pattern of diagonal area
Please draw Pattern of diagonal area as folowing figure by python scripting
https://en.wikipedia.org/wiki/Inequality_(mathematics)
*
4. Practice 2
Please send your program data to Shuta by the end of the day
→ Submission is closed.
4.1. The golden spiral
Please draw the pattern of “The golden spiral” as folowing figure by python scripting
A Fibonacci spiral approximates the golden spiral using quarter-circle arcs inscribed in squares of integer Fibonacci-number side, shown for square sizes 1, 1, 2, 3, 5, 8, 13, 21, and 34.
https://en.wikipedia.org/wiki/Golden_spiral
https://en.wikipedia.org/wiki/Fibonacci_number
*